Skip to content

Commit 2ca991a

Browse files
preview: detect changes from atomic writes performed by AI (#1542)
1 parent f732ce3 commit 2ca991a

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Add: Live preview on Linux now detects files saved via atomic write (write-to-temp then rename), so changes from AI agents are picked up reliably

znai-server/src/main/java/org/testingisdocumenting/znai/server/preview/FileWatcher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ private void register(Path path) {
179179
return;
180180
}
181181

182-
final WatchKey key = path.register(watchService, new WatchEvent.Kind[]{StandardWatchEventKinds.ENTRY_MODIFY},
182+
// ENTRY_CREATE is required to handle swap in atomic writes
183+
final WatchKey key = path.register(watchService,
184+
new WatchEvent.Kind[]{StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY},
183185
SensitivityWatchEventModifier.HIGH);
184186
pathByKey.put(key, path);
185187

znai-server/src/main/java/org/testingisdocumenting/znai/server/preview/PreviewPushFileChangeHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ private void onMarkupChange(Path path) {
137137

138138
private void onDependentChange(Path path) {
139139
execute(() -> {
140+
String pathAsString = path.toString();
141+
if (pathAsString.contains(".md.tmp.") || pathAsString.endsWith(".md.tmp")) {
142+
return;
143+
}
144+
140145
Collection<TocItem> dependentTocItems = previewWebSite.dependentTocItems(path);
141146
if (dependentTocItems.isEmpty()) {
142147
ConsoleOutputs.out("no markup files depends on ", BLUE, path);

0 commit comments

Comments
 (0)