Skip to content

Commit

Permalink
fix: treat any data change as a modification (getzola#2542)
Browse files Browse the repository at this point in the history
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: getzola#2536
  • Loading branch information
lukehsiao authored and berdandy committed Sep 17, 2024
1 parent f5a5b82 commit 5bcf1ee
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/fs_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ fn get_relevant_event_kind(event_kind: &EventKind) -> Option<SimpleFileSystemEve
EventKind::Create(CreateKind::File) | EventKind::Create(CreateKind::Folder) => {
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))
Expand Down Expand Up @@ -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),
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 5bcf1ee

Please sign in to comment.