Preserve code samples and watcher state during file updates

This commit is contained in:
eezd committed 2026-10-20 18:59:41 +08:00
1 parent 3a8248e560
commit 2df1ab87df
4 files changed
+218 -6

No files matched your search

+7 -1
View File
@@ -4,6 +4,9 @@ package watch
import (
"context"
"errors"
"fmt"
"io/fs"
"log/slog"
"os"
"path/filepath"
@@ -139,9 +142,12 @@ func (w *Watcher) scan() (map[string]fileState, error) {
st.rev = old.rev
} else {
data, err := os.ReadFile(abs)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
continue // 扫描期间被删除,下一轮会处理
}
if err != nil {
return nil, fmt.Errorf("读取笔记 %s 失败: %w", e.Path, err)
}
st.rev = vault.Rev(data)
}
}