Set file path for FileLock

Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
This commit is contained in:
Jiahao XU 2025-02-22 22:56:04 +11:00 committed by GitHub
parent 1f4defe042
commit d224e820be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -62,7 +62,8 @@ impl CratesToml<'_> {
}
pub fn load_from_path(path: impl AsRef<Path>) -> Result<Self, CratesTomlParseError> {
let file = FileLock::new_shared(File::open(path)?)?;
let path = path.as_ref();
let file = FileLock::new_shared(File::open(path)?)?.set_file_path(path);
Self::load_from_reader(file)
}
@ -100,7 +101,8 @@ impl CratesToml<'_> {
}
pub fn write_to_path(&self, path: impl AsRef<Path>) -> Result<(), CratesTomlParseError> {
let mut file = FileLock::new_exclusive(File::create(path)?)?;
let path = path.as_ref();
let mut file = FileLock::new_exclusive(File::create(path)?)?.set_file_path(path);
self.write_to_file(&mut file)
}
@ -142,7 +144,7 @@ impl CratesToml<'_> {
where
Iter: IntoIterator<Item = &'a CrateInfo>,
{
let mut file = FileLock::new_exclusive(create_if_not_exist(path.as_ref())?)?;
let mut file = create_if_not_exist(path.as_ref())?;
Self::append_to_file(&mut file, iter)
}