An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Correct sync scheduling for notebook metadata https://github.com/siyuan-note/siyuan/issues/19397
Danieldc1b305ec619
diff --git a/kernel/model/repository.go b/kernel/model/repository.goindex e1f5ff1512..b7dac588bc 100644--- a/kernel/model/repository.go+++ b/kernel/model/repository.go@@ -2983,7 +2983,6 @@ func newRepositoryWithAssetSourceLocked() (ret *dejavu.Repo, err error) {}ignoreLines := getSyncIgnoreLines()- ignoreLines = append(ignoreLines, "/.siyuan/conf.json") // 忽略旧版同步配置ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, util.HistoryDir, util.TempDir, Conf.System.ID, Conf.System.Name, Conf.System.OS, Conf.Repo.Key, ignoreLines, cloudRepo)if err != nil {logging.LogErrorf("init data repo failed: %s", err)diff --git a/kernel/model/sync.go b/kernel/model/sync.goindex b84154dbf3..8413c59636 100644--- a/kernel/model/sync.go+++ b/kernel/model/sync.go@@ -945,6 +945,10 @@ func bootSyncRepoWithDNSRetry() (err error) {}func getSyncIgnoreLines() (ret []string) {+ // 忽略旧版同步配置,读取用户规则失败时仍需保留此规则。+ defer func() {+ ret = append(ret, "/.siyuan/conf.json")+ }()ignore := filepath.Join(util.DataDir, ".siyuan", "syncignore")err := os.MkdirAll(filepath.Dir(ignore), 0755)if err != nil {diff --git a/kernel/model/sync_path.go b/kernel/model/sync_path.goindex 264135fbe5..9e965961b0 100644--- a/kernel/model/sync_path.go+++ b/kernel/model/sync_path.go@@ -61,13 +61,12 @@ func IncSyncIfNeeded(absPaths ...string) {}func pathAffectsSync(dataDir, absPath string, matcher *ignore.GitIgnore) bool {- absPath = util.ResolveLongestExistingParent(absPath)relPath, ok := dataRelativePath(dataDir, absPath)if !ok {return false}- // 修改同步忽略规则会改变仓库内容,规则文件本身虽然不参与同步也需要重新计划同步。+ // 修改同步忽略规则会改变仓库内容,即使规则排除了规则文件本身也需要重新计划同步。if "/.siyuan/syncignore" == relPath {return true}@@ -150,7 +149,7 @@ func syncPathHasSkippedDir(relPath string, includeLast bool) bool {parts = parts[:len(parts)-1]}for _, part := range parts {- if strings.HasPrefix(part, ".") || "filesys_status_check" == part {+ if (strings.HasPrefix(part, ".") && ".siyuan" != part) || "filesys_status_check" == part {return true}}diff --git a/kernel/model/sync_path_test.go b/kernel/model/sync_path_test.goindex 962a500685..fc9a2fc0c8 100644--- a/kernel/model/sync_path_test.go+++ b/kernel/model/sync_path_test.go@@ -21,6 +21,7 @@ import ("path/filepath""testing"+ ignore "github.com/sabhiram/go-gitignore""github.com/siyuan-note/siyuan/kernel/util")@@ -99,6 +100,72 @@ func TestPathsAffectSync(t *testing.T) {}}+func TestPathsAffectSyncMetadata(t *testing.T) {+ oldDataDir := util.DataDir+ util.DataDir = t.TempDir()+ t.Cleanup(func() {+ util.DataDir = oldDataDir+ })++ for _, tc := range []struct {+ path string+ want bool+ }{+ {".siyuan/searchignore", true},+ {".siyuan/embeddingignore", true},+ {".siyuan/indexignore", true},+ {".siyuan/refsearchignore", true},+ {".siyuan/data-crypto-backup.json", true},+ {".siyuan/conf.json", false},+ {".siyuan/.hidden/file.json", false},+ {".hidden/.siyuan/file.json", false},+ {"notebook/.siyuan/conf.json", true},+ {".siyuan/recovery.tmp", false},+ {"storage/view-state-corrupted-20260913000000.json", false},+ } {+ t.Run(tc.path, func(t *testing.T) {+ path := filepath.Join(util.DataDir, filepath.FromSlash(tc.path))+ writeSyncPathTestFile(t, path)+ if got := PathsAffectSync(path); got != tc.want {+ t.Fatalf("existing path: got %v, want %v", got, tc.want)+ }+ if err := os.Remove(path); nil != err {+ t.Fatal(err)+ }+ if got := PathsAffectSync(path); got != tc.want {+ t.Fatalf("removed path: got %v, want %v", got, tc.want)+ }+ })+ }++ metadataDir := filepath.Join(util.DataDir, ".siyuan")+ writeSyncPathTestFile(t, filepath.Join(metadataDir, "data-crypto-backup.json"))+ matcher := ignore.CompileIgnoreLines(getSyncIgnoreLines()...)+ if err := os.Remove(filepath.Join(metadataDir, "syncignore")); nil != err {+ t.Fatal(err)+ }+ if !pathAffectsSync(util.DataDir, metadataDir, matcher) {+ t.Fatal("metadata directory without syncignore should affect sync")+ }+ matcher = ignore.CompileIgnoreLines("/.siyuan/data-crypto-backup.json")+ if pathAffectsSync(util.DataDir, metadataDir, matcher) {+ t.Fatal("ignored metadata should not affect sync")+ }+}++func TestSyncIgnoreLegacyConfReadFailure(t *testing.T) {+ oldDataDir := util.DataDir+ util.DataDir = t.TempDir()+ t.Cleanup(func() {+ util.DataDir = oldDataDir+ })+ writeSyncPathTestFile(t, filepath.Join(util.DataDir, ".siyuan"))+ matcher := ignore.CompileIgnoreLines(getSyncIgnoreLines()...)+ if !matcher.MatchesPath("/.siyuan/conf.json") {+ t.Fatal("legacy sync configuration must remain ignored when rules cannot be read")+ }+}+func TestPathsAffectSyncResolvesSymlinks(t *testing.T) {oldDataDir := util.DataDirutil.DataDir = t.TempDir()