]> git.mikk.net Git - mtbl-rs/commitdiff
Fix Fileset bugs
authorChris Mikkelson <cmikkelson@domaintools.com>
Tue, 17 Sep 2024 22:14:38 +0000 (22:14 +0000)
committerChris Mikkelson <cmikkelson@domaintools.com>
Tue, 17 Sep 2024 22:14:38 +0000 (22:14 +0000)
Handle relative paths in fileset file, start last_reload at 0/epoch

src/fileset.rs

index 3d02f8db615392e6089bd20fe52248401e7aa95a..5a5bf9e683633f20b1bd3fd9f232b23c4cdac1d1 100644 (file)
@@ -17,10 +17,17 @@ pub struct Fileset {
     readers: Mutex<HashMap<PathBuf, (FileReader, SystemTime)>>,
 }
 
-fn load_fs_file(f: impl AsRef<Path>) -> Result<Vec<PathBuf>> {
+fn load_fs_file(f: &PathBuf) -> Result<Vec<PathBuf>> {
     use std::fs::read_to_string;
+    let mut dir = f.clone();
+    dir.pop();
+
     read_to_string(f)
-        .and_then(|s| Ok(s.lines().map(|l| PathBuf::from(l)).collect::<Vec<_>>()))
+        .and_then(|s| {
+            Ok(s.lines()
+                .map(|l| dir.clone().join(PathBuf::from(l)))
+                .collect::<Vec<_>>())
+        })
         .map_err(|e| e.into())
 }
 
@@ -28,7 +35,7 @@ impl Fileset {
     pub fn new(fname: impl AsRef<Path>) -> Self {
         Self {
             fs_path: PathBuf::new().with_file_name(fname.as_ref()),
-            last_reload: SystemTime::now() - Duration::new(2, 0),
+            last_reload: SystemTime::UNIX_EPOCH,
             reload_interval: Duration::new(1, 0),
             readers: Mutex::new(HashMap::new()),
         }