This commit is contained in:
sxyazi 2023-09-17 19:04:12 +08:00
parent e7a683ef9d
commit db7f72e14a
No known key found for this signature in database
4 changed files with 17 additions and 43 deletions

View file

@ -108,21 +108,17 @@ impl Executor {
cx.tasks.file_copy(src, dest, force, exec.named.contains_key("follow"))
}
}
"symlink" => {
"link" => {
let dest = cx.manager.cwd().to_owned();
let (cut, src) = cx.manager.yanked();
// Cut doesn't conform to the convention for creating symlinks
if *cut {
return false;
}
cx.tasks.file_symlink(
src,
dest,
exec.named.contains_key("force"),
exec.named.contains_key("relative"),
)
!cut
&& cx.tasks.file_link(
src,
dest,
exec.named.contains_key("relative"),
exec.named.contains_key("force"),
)
}
"remove" => {
let targets = cx.manager.selected().into_iter().map(|f| f.url_owned()).collect();

View file

@ -49,12 +49,10 @@ keymap = [
{ on = [ "<C-Enter>" ], exec = "open --interactive", desc = "Open the selected files interactively" }, # It's cool if you're using a terminal that supports CSI u
{ on = [ "y" ], exec = "yank", desc = "Copy the selected files" },
{ on = [ "x" ], exec = "yank --cut", desc = "Cut the selected files" },
{ on = [ "p" , "p" ], exec = "paste", desc = "Paste the files" },
{ on = [ "p" ], exec = "paste", desc = "Paste the files" },
{ on = [ "P" ], exec = "paste --force", desc = "Paste the files (overwrite if the destination exists)" },
{ on = [ "k" ], exec = "paste --follow", desc = "Paste the files (follow the symlinks)" },
{ on = [ "K" ], exec = "paste --follow --force", desc = "Paste the files (overwrite + follow)" },
{ on = [ "p", "l" ], exec = "symlink", desc = "Symlink the absolute path of files" },
{ on = [ "p", "L" ], exec = "symlink --relative", desc = "Symlink the relative path of files" },
{ on = [ "k" ], exec = "link", desc = "Symlink the absolute path of files" },
{ on = [ "K" ], exec = "link --relative", desc = "Symlink the relative path of files" },
{ on = [ "d" ], exec = "remove", desc = "Move the files to the trash" },
{ on = [ "D" ], exec = "remove --permanently", desc = "Permanently delete the files" },
{ on = [ "a" ], exec = "create", desc = "Create a file or directory (ends with / for directories)" },

View file

@ -8,7 +8,7 @@ use shared::{unique_path, Throttle, Url};
use tokio::{fs, select, sync::{mpsc::{self, UnboundedReceiver}, oneshot}, time::sleep};
use tracing::{info, trace};
use super::{workers::{File, FileOpDelete, FileOpPaste, FileOpSymlink, FileOpTrash, Precache, PrecacheOpMime, PrecacheOpSize, Process, ProcessOpOpen}, Running, TaskOp, TaskStage};
use super::{workers::{File, FileOpDelete, FileOpLink, FileOpPaste, FileOpTrash, Precache, PrecacheOpMime, PrecacheOpSize, Process, ProcessOpOpen}, Running, TaskOp, TaskStage};
use crate::emit;
pub struct Scheduler {
@ -234,8 +234,8 @@ impl Scheduler {
});
}
pub(super) fn file_symlink(&self, from: Url, mut to: Url, force: bool) {
let name = format!("Symlink {from:?} to {to:?}");
pub(super) fn file_link(&self, from: Url, mut to: Url, force: bool) {
let name = format!("Link {from:?} to {to:?}");
let id = self.running.write().add(name);
let _ = self.todo.send_blocking({
@ -244,7 +244,7 @@ impl Scheduler {
if !force {
to = unique_path(to).await;
}
file.symlink(FileOpSymlink { id, from, to }).await.ok();
file.link(FileOpLink { id, from, to }).await.ok();
}
.boxed()
});

View file

@ -20,7 +20,6 @@ pub(crate) struct File {
pub(crate) enum FileOp {
Paste(FileOpPaste),
Link(FileOpLink),
Symlink(FileOpSymlink),
Delete(FileOpDelete),
Trash(FileOpTrash),
}
@ -44,13 +43,6 @@ pub(crate) struct FileOpLink {
pub length: u64,
}
#[derive(Clone, Debug)]
pub(crate) struct FileOpSymlink {
pub id: usize,
pub from: Url,
pub to: Url,
}
#[derive(Clone, Debug)]
pub(crate) struct FileOpDelete {
pub id: usize,
@ -76,7 +68,6 @@ impl File {
Ok(match self.rx.recv().await? {
FileOp::Paste(t) => (t.id, FileOp::Paste(t)),
FileOp::Link(t) => (t.id, FileOp::Link(t)),
FileOp::Symlink(t) => (t.id, FileOp::Symlink(t)),
FileOp::Delete(t) => (t.id, FileOp::Delete(t)),
FileOp::Trash(t) => (t.id, FileOp::Trash(t)),
})
@ -122,17 +113,6 @@ impl File {
}
self.sch.send(TaskOp::Adv(task.id, 1, 0))?;
}
FileOp::Symlink(task) => {
#[cfg(unix)]
{
fs::symlink(&task.from, &task.to).await?;
self.sch.send(TaskOp::Adv(task.id, 1, 0))?;
}
#[cfg(target_os = "windows")]
{
todo!()
}
}
FileOp::Link(task) => {
let src = match fs::read_link(&task.from).await {
Ok(src) => src,
@ -264,10 +244,10 @@ impl File {
self.done(task.id)
}
pub(crate) async fn symlink(&self, task: FileOpSymlink) -> Result<()> {
pub(crate) async fn link(&self, task: FileOpLink) -> Result<()> {
let id = task.id;
self.sch.send(TaskOp::New(id, 0))?;
self.tx.send(FileOp::Symlink(task)).await?;
self.tx.send(FileOp::Link(task)).await?;
self.done(id)
}