From 9774d761e393537efcaf4349866a8ff4967c5d61 Mon Sep 17 00:00:00 2001 From: Luke Hsiao Date: Mon, 24 Jun 2024 14:05:50 -0600 Subject: [PATCH] fix: treat any data change as a modification (#2542) For unknown reasons, it seems some environments emit a `DataChange::Any` event, rather than specifying content or size, when a file is edited. As an example: [src/fs_utils.rs:72:9] &event = DebouncedEvent { event: Event { kind: Modify( Data( Any, ), ), paths: [ "/home/redacted/content/blog/2024-06-23_example.md", ], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None, }, time: Instant { tv_sec: 78544, tv_nsec: 936740729, }, } Consequently, because this isn't treated by Zola as a modification, the site is not rebuilt, which regresses on previous behavior. This patch fixes this particular case by treating any data modification events as a modification. Closes: https://github.com/getzola/zola/issues/2536 --- src/fs_utils.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/fs_utils.rs b/src/fs_utils.rs index 1f70496c..693b4e53 100644 --- a/src/fs_utils.rs +++ b/src/fs_utils.rs @@ -38,8 +38,7 @@ fn get_relevant_event_kind(event_kind: &EventKind) -> Option { Some(SimpleFileSystemEventKind::Create) } - EventKind::Modify(ModifyKind::Data(DataChange::Size)) - | EventKind::Modify(ModifyKind::Data(DataChange::Content)) + EventKind::Modify(ModifyKind::Data(_)) // Intellij modifies file metadata on edit. // https://github.com/passcod/notify/issues/150#issuecomment-494912080 | EventKind::Modify(ModifyKind::Metadata(MetadataKind::WriteTime)) @@ -181,6 +180,14 @@ mod tests { EventKind::Modify(ModifyKind::Data(DataChange::Content)), Some(SimpleFileSystemEventKind::Modify), ), + ( + EventKind::Modify(ModifyKind::Data(DataChange::Any)), + Some(SimpleFileSystemEventKind::Modify), + ), + ( + EventKind::Modify(ModifyKind::Data(DataChange::Other)), + Some(SimpleFileSystemEventKind::Modify), + ), ( EventKind::Modify(ModifyKind::Metadata(MetadataKind::WriteTime)), Some(SimpleFileSystemEventKind::Modify), @@ -202,7 +209,7 @@ mod tests { ]; for (case, expected) in cases.iter() { let ek = get_relevant_event_kind(&case); - assert_eq!(ek, *expected); + assert_eq!(ek, *expected, "case: {:?}", case); } }