diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-02-09 12:39:31 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-02-09 13:07:31 -0500 |
commit | becbb90b2f22d58c98693d653f55ba604bb03f75 (patch) | |
tree | 085b9ac9b197a9ad3f0dd20df36848c5619adefe /src/io | |
parent | 656582a6c867c25667661be9b327b4cc73859d7d (diff) |
rework input thread and file operations
- no longer depend on fs_extra for copy/paste files
- in house solution preserves permissions
- ioworkers are now queued, no more parallel io tasks
- input thread now listens for ioworker threads as well
- cargo fmt
Diffstat (limited to 'src/io')
-rw-r--r-- | src/io/io_worker.rs | 34 | ||||
-rw-r--r-- | src/io/mod.rs | 3 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/io/io_worker.rs b/src/io/io_worker.rs new file mode 100644 index 0000000..f497526 --- /dev/null +++ b/src/io/io_worker.rs @@ -0,0 +1,34 @@ +use crate::util::event::Event; +use std::sync::mpsc; +use std::thread; + +#[derive(Clone, Debug)] +pub struct Options { + pub overwrite: bool, + pub skip_exist: bool, +} + +impl std::default::Default for Options { + fn default() -> Self { + Self { + overwrite: false, + skip_exist: false, + } + } +} + +pub struct IOWorkerThread { + pub handle: thread::JoinHandle<std::io::Result<u64>>, + pub tx_start: mpsc::Sender<()>, + pub rx: mpsc::Receiver<Event>, +} + +impl IOWorkerThread { + pub fn start(&self) { + self.tx_start.send(()); + } + + pub fn recv(&self) -> Result<Event, mpsc::RecvError> { + self.rx.recv() + } +} diff --git a/src/io/mod.rs b/src/io/mod.rs new file mode 100644 index 0000000..350bdba --- /dev/null +++ b/src/io/mod.rs @@ -0,0 +1,3 @@ +mod io_worker; + +pub use self::io_worker::{IOWorkerThread, Options}; |