Skip to content

Commit

Permalink
fix: treat closed files accessed in write mode as modifications
Browse files Browse the repository at this point in the history
For unknown reasons, it seems some environments emit a `Close` event,
rather than a `Modify`, when a file is edited. As an example:

    [src/fs_utils.rs:71:9] &event = DebouncedEvent {
        event: Event {
            kind: Access(
                Close(
                    Write,
                ),
            ),
            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: 78269,
            tv_nsec: 133499794,
        },
    }

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 `Close` events, where
the file was accessed `Write` mode, as a modification.

Closes: getzola#2536
  • Loading branch information
lukehsiao committed Jun 23, 2024
1 parent aeed18a commit 5a9b22f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/fs_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ fn get_relevant_event_kind(event_kind: &EventKind) -> Option<SimpleFileSystemEve
| EventKind::Modify(ModifyKind::Metadata(MetadataKind::WriteTime))
| EventKind::Modify(ModifyKind::Metadata(MetadataKind::Permissions))
| EventKind::Modify(ModifyKind::Metadata(MetadataKind::Ownership))
| EventKind::Modify(ModifyKind::Name(RenameMode::To)) => Some(SimpleFileSystemEventKind::Modify),
| EventKind::Modify(ModifyKind::Name(RenameMode::To))
| EventKind::Access(AccessKind::Close(AccessMode::Write)) => Some(SimpleFileSystemEventKind::Modify),
EventKind::Remove(RemoveKind::File) | EventKind::Remove(RemoveKind::Folder) => {
Some(SimpleFileSystemEventKind::Remove)
}
Expand Down Expand Up @@ -197,6 +198,10 @@ mod tests {
EventKind::Modify(ModifyKind::Name(RenameMode::To)),
Some(SimpleFileSystemEventKind::Modify),
),
(
EventKind::Access(AccessKind::Close(AccessMode::Write)),
Some(SimpleFileSystemEventKind::Modify),
),
(EventKind::Remove(RemoveKind::File), Some(SimpleFileSystemEventKind::Remove)),
(EventKind::Remove(RemoveKind::Folder), Some(SimpleFileSystemEventKind::Remove)),
];
Expand Down

0 comments on commit 5a9b22f

Please sign in to comment.