Skip to content

Commit

Permalink
added force option
Browse files Browse the repository at this point in the history
  • Loading branch information
chanderlud committed Dec 26, 2023
1 parent c301df5 commit 9f790e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
10 changes: 9 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ pub(crate) struct Options {
#[clap(short, long)]
pub(crate) overwrite: bool,

/// Include subdirectories recursively
/// Include subdirectories and files recursively
#[clap(short = 'R', long)]
pub(crate) recursive: bool,

/// Force the transfer even if the there is not enough space
#[clap(short, long)]
pub(crate) force: bool,

/// Optionally encrypt the data stream
#[clap(short = 'S', long)]
pub(crate) stream_crypto: Option<Crypto>,
Expand Down Expand Up @@ -128,6 +132,10 @@ impl Options {
arguments.push(String::from("-R"))
}

if self.force {
arguments.push(String::from("-f"))
}

arguments.push(format!("\"{}\"", self.source));
arguments.push(format!("\"{}\"", self.destination));

Expand Down
32 changes: 17 additions & 15 deletions src/receiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,23 @@ pub(crate) async fn main(
completed.len()
);

let free_space = free_space(&options.destination.file_path)?;
debug!("free space: {}", free_space);

if free_space < stats.total_data.load(Relaxed) as u64 {
error!(
"not enough free space {} / {}",
free_space,
stats.total_data.load(Relaxed)
);

str_stream
.write_message(&Message::failure(0, 1, None))
.await?;

return Err(Error::failure(1));
if !options.force {
let free_space = free_space(&options.destination.file_path)?;
debug!("free space: {}", free_space);

if free_space < stats.total_data.load(Relaxed) as u64 {
error!(
"not enough free space {} / {}",
free_space,
stats.total_data.load(Relaxed)
);

str_stream
.write_message(&Message::failure(0, 1, None))
.await?;

return Err(Error::failure(1));
}
}

debug!("sending completed: {:?}", completed);
Expand Down

0 comments on commit 9f790e8

Please sign in to comment.