adding validation for files to make sure the underlying filesystem

hasn't deleted or moved files in the database
This commit is contained in:
Chris Cochrun 2023-02-17 13:12:23 -06:00
parent 0d3e057734
commit 3b35424a0c
2 changed files with 52 additions and 8 deletions

View file

@ -1,6 +1,7 @@
#[cxx_qt::bridge]
mod file_helper {
use cxx_qt_lib::QVariantValue;
use std::path::Path;
unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h");
@ -47,5 +48,23 @@ mod file_helper {
println!("{}", file);
return vec!["hi".to_string()];
}
#[qinvokable]
pub fn validate(self: Pin<&mut Self>, file: QUrl) -> bool {
let file_string = file.to_string();
let _file_string = file_string.strip_prefix("file://");
match _file_string {
None => {
let _exists = Path::new(&file.to_string()).exists();
println!("{} does not exist", file.to_string());
_exists
}
Some(file) => {
let _exists = Path::new(&file).exists();
println!("{} exists? {_exists}", file);
_exists
}
}
}
}
}