fix(fs): compare modified time in whole seconds in write confirmation (#17290)

Signed-off-by: lingyicute <xlyxinglinyi@gmail.com>
This commit is contained in:
Yi Ling authored and GitHub committed 2026-11-27 23:50:30 +08:00
1 parent 5c680b4d86
commit 104ef2a865
1 file changed
+21 -1
+21 -1
View File
@@ -1667,7 +1667,8 @@ pub fn is_write_need_confirmation(
// We decide to give the decision whether to override the existing file to users,
// which obey the behavior of the file manager in our system.
let mut is_identical = false;
if remote_mt == local_mt && digest.file_size == metadata.len() {
// The peer's digest only carries whole seconds (see `get_current_digest()`).
if remote_mt.as_secs() == local_mt.as_secs() && digest.file_size == metadata.len() {
is_identical = true;
}
Ok(DigestCheckResult::NeedConfirm(FileTransferDigest {
@@ -1918,6 +1919,25 @@ mod tests {
assert!(dst.exists());
}
#[test]
fn write_confirmation_compares_modified_time_in_seconds() {
let tmp_root = TestTempDir::new("rustdesk_digest_secs");
std::fs::create_dir_all(&tmp_root.path).expect("create temp dir");
let file = tmp_root.join("same.txt");
std::fs::write(&file, b"content").expect("create file");
let mtime = filetime::FileTime::from_unix_time(1_700_000_000, 500_000_000);
filetime::set_file_mtime(&file, mtime).expect("set mtime");
let digest = FileTransferDigest {
last_modified: 1_700_000_000,
file_size: 7,
..Default::default()
};
assert!(matches!(
is_write_need_confirmation(false, &file.to_string_lossy(), &digest).unwrap(),
DigestCheckResult::NeedConfirm(d) if d.is_identical
));
}
#[test]
fn compressed_file_extensions_ignore_case() {
// Cameras and phones name their photos IMG_0001.JPG.