Try to solve corpus issue related to #2981 (#2982)

* Try to solve corpus issue related to #2981

* clippy
This commit is contained in:
Dominik Maier 2025-02-14 02:07:14 +01:00 committed by GitHub
parent c53e51584b
commit f9715392af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -362,7 +362,7 @@ impl<I> InMemoryOnDiskCorpus<I> {
testcase.input().as_ref().unwrap().generate_name(id) testcase.input().as_ref().unwrap().generate_name(id)
}); });
let mut ctr = String::new(); let mut ctr = 1;
if self.locking { if self.locking {
let lockfile_name = format!(".{file_name}"); let lockfile_name = format!(".{file_name}");
let lockfile_path = self.dir_path.join(lockfile_name); let lockfile_path = self.dir_path.join(lockfile_name);
@ -375,15 +375,14 @@ impl<I> InMemoryOnDiskCorpus<I> {
); );
lockfile.lock_exclusive()?; lockfile.lock_exclusive()?;
lockfile.read_to_string(&mut ctr)?; let mut old_ctr = String::new();
ctr = if ctr.is_empty() { lockfile.read_to_string(&mut old_ctr)?;
String::from("1") if !old_ctr.is_empty() {
} else { ctr = old_ctr.trim().parse::<u32>()? + 1;
(ctr.trim().parse::<u32>()? + 1).to_string() }
};
lockfile.seek(SeekFrom::Start(0))?; lockfile.seek(SeekFrom::Start(0))?;
lockfile.write_all(ctr.as_bytes())?; lockfile.write_all(ctr.to_string().as_bytes())?;
} }
if testcase.file_path().is_none() { if testcase.file_path().is_none() {
@ -432,11 +431,18 @@ impl<I> InMemoryOnDiskCorpus<I> {
*testcase.metadata_path_mut() = Some(metafile_path); *testcase.metadata_path_mut() = Some(metafile_path);
} }
// Only try to write the data if the counter is 1.
// Otherwise we already have a file with this name, and
// we can assume the data has already been written.
if ctr == 1 {
if let Err(err) = self.store_input_from(testcase) { if let Err(err) = self.store_input_from(testcase) {
if self.locking { if self.locking {
return Err(err); return Err(err);
} }
log::error!("An error occurred when trying to write a testcase without locking: {err}"); log::error!(
"An error occurred when trying to write a testcase without locking: {err}"
);
}
} }
Ok(()) Ok(())
} }