Skip to content

Commit 35a9759

Browse files
committed
fix: Use FileInformation to check same file.
1 parent 3fea131 commit 35a9759

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

src/find/matchers/mod.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,9 @@ impl ComparableValue {
285285
}
286286

287287
// Used on file output arguments.
288-
// Based on path inode or file_index check if the file already has been specified.
289288
// If yes, use the same file pointer.
290289
struct FileMemoizer {
291-
mem: HashMap<u64, Arc<File>>,
290+
mem: HashMap<FileInformation, Arc<File>>,
292291
}
293292
impl FileMemoizer {
294293
fn new() -> Self {
@@ -297,30 +296,22 @@ impl FileMemoizer {
297296
}
298297
}
299298
fn get_or_create_file(&mut self, path: &str) -> Result<Arc<File>, Box<dyn Error>> {
300-
let path = Path::new(path);
301-
let file_id = self.get_file_id(path);
302-
if file_id.is_err() {
303-
let file = Arc::new(File::create(path)?);
304-
self.mem.insert(self.get_file_id(path)?, file.clone());
305-
return Ok(file);
299+
let mut file_info = FileInformation::from_path(path, true);
300+
match file_info {
301+
Ok(info) => {
302+
let file = self
303+
.mem
304+
.entry(info)
305+
.or_insert(Arc::new(File::create(path)?));
306+
Ok(file.clone())
307+
}
308+
Err(_) => {
309+
let file = Arc::new(File::create(path)?);
310+
file_info = FileInformation::from_path(path, true);
311+
self.mem.insert(file_info?, file.clone());
312+
Ok(file)
313+
}
306314
}
307-
308-
let file = self
309-
.mem
310-
.entry(file_id.unwrap())
311-
.or_insert(Arc::new(File::create(path)?));
312-
Ok(file.clone())
313-
}
314-
315-
fn get_file_id(&self, path: &Path) -> Result<u64, Box<dyn Error>> {
316-
let file_info = FileInformation::from_path(path, true)?;
317-
#[cfg(windows)]
318-
let file_inode = file_info.file_index();
319-
320-
#[cfg(unix)]
321-
let file_inode = file_info.inode();
322-
323-
Ok(file_inode)
324315
}
325316
}
326317

0 commit comments

Comments
 (0)