Added a basic check to make sure we don't try to transcode a partially written file

This commit is contained in:
Gregory Ballantine
2022-09-01 22:15:46 -04:00
parent b5d96c21a9
commit 44ef95b440
6 changed files with 30 additions and 4 deletions

16
src/util/io.rs Normal file
View File

@@ -0,0 +1,16 @@
use std::process;
// checks whether a file is currently open in another program (e.g. still being written)
pub fn is_file_locked(filepath: &str) -> bool {
let cmd = process::Command::new("/usr/bin/lsof")
.arg(filepath)
.output()
.expect("Failed to execute command");
let results = &String::from_utf8_lossy(&cmd.stdout);
if results.contains(filepath) {
return true;
}
return false;
}

1
src/util/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod io;