Skip to content

Commit 439438d

Browse files
committed
#431: Fix timestamp change for read-only files
1 parent 93ff5db commit 439438d

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
when multiple manifest entries have the same normalized title.
4141
* Some default paths are now formatted more consistently.
4242
* GUI: There was an error when the backup/restore paths were relative to the working directory.
43+
* When backing up a read-only file using the simple format,
44+
Ludusavi would fail to set the backed up file's modified time.
4345

4446
## v0.27.0 (2024-11-19)
4547

src/path.rs

+33-27
Original file line numberDiff line numberDiff line change
@@ -717,50 +717,56 @@ impl StrictPath {
717717

718718
if let Err(e) = target_file.create_parent_dir() {
719719
log::error!(
720-
"[{context}] unable to create parent directories: {} -> {} | {e}",
721-
self.raw(),
722-
target_file.raw()
720+
"[{context}] unable to create parent directories: {:?} -> {:?} | {e}",
721+
&self,
722+
&target_file
723723
);
724724
return Err(e);
725725
}
726726

727+
if let Err(e) = self.unset_readonly(context) {
728+
log::warn!("[{context}] failed to unset read-only on source: {:?} | {e}", &self);
729+
return Err(std::io::Error::new(
730+
std::io::ErrorKind::Other,
731+
"Failed to unset read-only",
732+
));
733+
}
727734
if let Err(e) = target_file.unset_readonly(context) {
728735
log::warn!(
729-
"[{context}] failed to unset read-only on target: {} | {e}",
730-
target_file.raw()
736+
"[{context}] failed to unset read-only on target: {:?} | {e}",
737+
&target_file
731738
);
732739
return Err(std::io::Error::new(
733740
std::io::ErrorKind::Other,
734741
"Failed to unset read-only",
735742
));
736-
} else if let Err(e) = self.copy_to(target_file) {
737-
log::error!(
738-
"[{context}] unable to copy: {} -> {} | {e}",
739-
self.raw(),
740-
target_file.raw()
741-
);
743+
}
744+
745+
if let Err(e) = self.copy_to(target_file) {
746+
log::error!("[{context}] unable to copy: {:?} -> {:?} | {e}", &self, &target_file);
742747
return Err(e);
743-
} else {
744-
let mtime = match self.get_mtime() {
745-
Ok(x) => x,
746-
Err(e) => {
747-
log::error!(
748-
"[{context}] unable to get modification time: {} -> {} | {e}",
749-
self.raw(),
750-
target_file.raw(),
751-
);
752-
return Err(e);
753-
}
754-
};
755-
if let Err(e) = target_file.set_mtime(mtime) {
748+
}
749+
750+
let mtime = match self.get_mtime() {
751+
Ok(x) => x,
752+
Err(e) => {
756753
log::error!(
757-
"[{context}] unable to set modification time: {} -> {} to {mtime:#?} | {e}",
758-
self.raw(),
759-
target_file.raw(),
754+
"[{context}] unable to get modification time: {:?} -> {:?} | {e}",
755+
&self,
756+
&target_file,
760757
);
761758
return Err(e);
762759
}
760+
};
761+
if let Err(e) = target_file.set_mtime(mtime) {
762+
log::error!(
763+
"[{context}] unable to set modification time: {:?} -> {:?} to {mtime:#?} | {e}",
764+
&self,
765+
&target_file,
766+
);
767+
return Err(e);
763768
}
769+
764770
Ok(())
765771
}
766772

0 commit comments

Comments
 (0)