From 49838542a306b703e8f0c9eab8e6553916b5552f 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 1f70496c6..693b4e535 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); } }