Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4952b1b

Browse files
committed
fix: Use FileInformation to check same file.
1 parent e644e15 commit 4952b1b

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
@@ -272,10 +272,9 @@ impl ComparableValue {
272272
}
273273

274274
// Used on file output arguments.
275-
// Based on path inode or file_index check if the file already has been specified.
276275
// If yes, use the same file pointer.
277276
struct FileMemoizer {
278-
mem: HashMap<u64, Arc<File>>,
277+
mem: HashMap<FileInformation, Arc<File>>,
279278
}
280279
impl FileMemoizer {
281280
fn new() -> Self {
@@ -284,30 +283,22 @@ impl FileMemoizer {
284283
}
285284
}
286285
fn get_or_create_file(&mut self, path: &str) -> Result<Arc<File>, Box<dyn Error>> {
287-
let path = Path::new(path);
288-
let file_id = self.get_file_id(path);
289-
if file_id.is_err() {
290-
let file = Arc::new(File::create(path)?);
291-
self.mem.insert(self.get_file_id(path)?, file.clone());
292-
return Ok(file);
286+
let mut file_info = FileInformation::from_path(path, true);
287+
match file_info {
288+
Ok(info) => {
289+
let file = self
290+
.mem
291+
.entry(info)
292+
.or_insert(Arc::new(File::create(path)?));
293+
Ok(file.clone())
294+
}
295+
Err(_) => {
296+
let file = Arc::new(File::create(path)?);
297+
file_info = FileInformation::from_path(path, true);
298+
self.mem.insert(file_info?, file.clone());
299+
Ok(file)
300+
}
293301
}
294-
295-
let file = self
296-
.mem
297-
.entry(file_id.unwrap())
298-
.or_insert(Arc::new(File::create(path)?));
299-
Ok(file.clone())
300-
}
301-
302-
fn get_file_id(&self, path: &Path) -> Result<u64, Box<dyn Error>> {
303-
let file_info = FileInformation::from_path(path, true)?;
304-
#[cfg(windows)]
305-
let file_inode = file_info.file_index();
306-
307-
#[cfg(unix)]
308-
let file_inode = file_info.inode();
309-
310-
Ok(file_inode)
311302
}
312303
}
313304

0 commit comments

Comments
 (0)