yazi_scheduler/file/
op.rs

1use yazi_fs::Cha;
2use yazi_shared::url::Url;
3
4#[derive(Debug)]
5pub enum FileOp {
6	Paste(FileOpPaste),
7	Link(FileOpLink),
8	Hardlink(FileOpHardlink),
9	Delete(FileOpDelete),
10	Trash(FileOpTrash),
11}
12
13impl FileOp {
14	pub fn id(&self) -> usize {
15		match self {
16			Self::Paste(op) => op.id,
17			Self::Link(op) => op.id,
18			Self::Hardlink(op) => op.id,
19			Self::Delete(op) => op.id,
20			Self::Trash(op) => op.id,
21		}
22	}
23}
24
25// --- Paste
26#[derive(Clone, Debug)]
27pub struct FileOpPaste {
28	pub id:     usize,
29	pub from:   Url,
30	pub to:     Url,
31	pub cha:    Option<Cha>,
32	pub cut:    bool,
33	pub follow: bool,
34	pub retry:  u8,
35}
36
37impl FileOpPaste {
38	pub(super) fn spawn(&self, from: Url, to: Url, cha: Cha) -> Self {
39		Self {
40			id: self.id,
41			from,
42			to,
43			cha: Some(cha),
44			cut: self.cut,
45			follow: self.follow,
46			retry: self.retry,
47		}
48	}
49}
50
51// --- Link
52#[derive(Clone, Debug)]
53pub struct FileOpLink {
54	pub id:       usize,
55	pub from:     Url,
56	pub to:       Url,
57	pub cha:      Option<Cha>,
58	pub resolve:  bool,
59	pub relative: bool,
60	pub delete:   bool,
61}
62
63impl From<FileOpPaste> for FileOpLink {
64	fn from(value: FileOpPaste) -> Self {
65		Self {
66			id:       value.id,
67			from:     value.from,
68			to:       value.to,
69			cha:      value.cha,
70			resolve:  true,
71			relative: false,
72			delete:   value.cut,
73		}
74	}
75}
76
77// --- Hardlink
78#[derive(Clone, Debug)]
79pub struct FileOpHardlink {
80	pub id:     usize,
81	pub from:   Url,
82	pub to:     Url,
83	pub cha:    Option<Cha>,
84	pub follow: bool,
85}
86
87impl FileOpHardlink {
88	pub(super) fn spawn(&self, from: Url, to: Url, cha: Cha) -> Self {
89		Self { id: self.id, from, to, cha: Some(cha), follow: self.follow }
90	}
91}
92
93// --- Delete
94#[derive(Clone, Debug)]
95pub struct FileOpDelete {
96	pub id:     usize,
97	pub target: Url,
98	pub length: u64,
99}
100
101// --- Trash
102#[derive(Clone, Debug)]
103pub struct FileOpTrash {
104	pub id:     usize,
105	pub target: Url,
106	pub length: u64,
107}