Skip to content

Commit

Permalink
🐛 Allow override of self-created-files (#42)
Browse files Browse the repository at this point in the history
Before the code did not allow a file that was created in a backup to be written to twice
  • Loading branch information
pajowu authored Mar 21, 2021
1 parent 56686e5 commit faf19ff
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/output_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct SignalOutputRaw {
count_sticker: usize,
count_avatar: usize,
written_frames: usize,
created_files: std::boxed::Box<std::collections::HashSet<std::path::PathBuf>>
}

impl SignalOutputRaw {
Expand Down Expand Up @@ -82,6 +83,7 @@ impl SignalOutputRaw {
count_avatar: 0,
// we set read frames to 1 due to the header frame we will never write
written_frames: 1,
created_files: std::boxed::Box::new(std::collections::HashSet::new())
})
}

Expand Down Expand Up @@ -212,7 +214,7 @@ impl crate::output::SignalOutput for SignalOutputRaw {

// open connection to file
let path = path.join(pref.get_file());
if path.exists() && !self.force_write {
if path.exists() && !self.force_write && !self.created_files.contains(&path) {
return Err(anyhow!(
"Config file does already exist: {}. Try -f",
path.to_string_lossy()
Expand All @@ -230,6 +232,7 @@ impl crate::output::SignalOutput for SignalOutputRaw {
)
})?;

self.created_files.insert(path);
self.written_frames += 1;

Ok(())
Expand Down

0 comments on commit faf19ff

Please sign in to comment.