Skip to content

Commit

Permalink
#431: Fix timestamp change for read-only files
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jan 7, 2025
1 parent 93ff5db commit 439438d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
when multiple manifest entries have the same normalized title.
* Some default paths are now formatted more consistently.
* GUI: There was an error when the backup/restore paths were relative to the working directory.
* When backing up a read-only file using the simple format,
Ludusavi would fail to set the backed up file's modified time.

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

Expand Down
60 changes: 33 additions & 27 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,50 +717,56 @@ impl StrictPath {

if let Err(e) = target_file.create_parent_dir() {
log::error!(
"[{context}] unable to create parent directories: {} -> {} | {e}",
self.raw(),
target_file.raw()
"[{context}] unable to create parent directories: {:?} -> {:?} | {e}",
&self,
&target_file
);
return Err(e);
}

if let Err(e) = self.unset_readonly(context) {
log::warn!("[{context}] failed to unset read-only on source: {:?} | {e}", &self);
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to unset read-only",
));
}
if let Err(e) = target_file.unset_readonly(context) {
log::warn!(
"[{context}] failed to unset read-only on target: {} | {e}",
target_file.raw()
"[{context}] failed to unset read-only on target: {:?} | {e}",
&target_file
);
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to unset read-only",
));
} else if let Err(e) = self.copy_to(target_file) {
log::error!(
"[{context}] unable to copy: {} -> {} | {e}",
self.raw(),
target_file.raw()
);
}

if let Err(e) = self.copy_to(target_file) {
log::error!("[{context}] unable to copy: {:?} -> {:?} | {e}", &self, &target_file);
return Err(e);
} else {
let mtime = match self.get_mtime() {
Ok(x) => x,
Err(e) => {
log::error!(
"[{context}] unable to get modification time: {} -> {} | {e}",
self.raw(),
target_file.raw(),
);
return Err(e);
}
};
if let Err(e) = target_file.set_mtime(mtime) {
}

let mtime = match self.get_mtime() {
Ok(x) => x,
Err(e) => {
log::error!(
"[{context}] unable to set modification time: {} -> {} to {mtime:#?} | {e}",
self.raw(),
target_file.raw(),
"[{context}] unable to get modification time: {:?} -> {:?} | {e}",
&self,
&target_file,
);
return Err(e);
}
};
if let Err(e) = target_file.set_mtime(mtime) {
log::error!(
"[{context}] unable to set modification time: {:?} -> {:?} to {mtime:#?} | {e}",
&self,
&target_file,
);
return Err(e);
}

Ok(())
}

Expand Down

0 comments on commit 439438d

Please sign in to comment.