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: Complete appearance migration cleanup https://github.com/siyuan-note/siyuan/issues/19634
Daniel179aaba41ee0
diff --git a/docs/APPEARANCE-SYNC.md b/docs/APPEARANCE-SYNC.mdindex 4b3cf04678..1a2f00acef 100644--- a/docs/APPEARANCE-SYNC.md+++ b/docs/APPEARANCE-SYNC.md@@ -24,7 +24,7 @@ The ordinary `.siyuan/syncignore` rules apply to individual files and directorieStartup moves third-party packages from the previous appearance directory into `data/themes/` and `data/icons/`. An existing destination takes precedence. Successfully migrated source directories are removed, so deleting a package or restoring an older snapshot cannot recreate it from the original directory. Built-in resources remain in the application appearance directory.-The upgrade removes complete generated `siyuan-appearance-isolation:v1` blocks from `.siyuan/syncignore` once they are encountered. User-written rules outside those blocks retain their contents and order. No isolation block is created or maintained afterward.+The upgrade removes complete generated `siyuan-appearance-isolation:v1` blocks from `.siyuan/syncignore`. Loading changed ignore rules also removes blocks brought back by synchronization or snapshot restoration. User-written rules outside those blocks retain their contents and order. No isolation block is created or maintained afterward.The released implementation does not create per-package digest or deletion records, immutable package archives, recovery tags, or an appearance-specific transaction protocol. Installation metadata uses the shared `storage/bazaar.json` mechanism. Alpha leftovers in `data/storage/appearance-v1/`, `data/storage/bazaar/themes/`, `data/storage/bazaar/icons/`, and `conf/appearance-migration.json`, and existing `.siyuan-appearance-v1` tags are not automatically cleaned up or used to restore packages. Existing tags follow ordinary tag behavior.diff --git a/docs/APPEARANCE-SYNC.zh-CN.md b/docs/APPEARANCE-SYNC.zh-CN.mdindex fb9f66aca2..e8268dc0a5 100644--- a/docs/APPEARANCE-SYNC.zh-CN.md+++ b/docs/APPEARANCE-SYNC.zh-CN.md@@ -24,7 +24,7 @@启动时将旧外观目录中的第三方包移入 `data/themes/` 和 `data/icons/`,已有目标目录优先。迁移成功后移除源目录,避免删除包或恢复旧快照后又从原目录复活。内置资源仍保留在程序外观目录中。-升级时一次性移除 `.siyuan/syncignore` 中完整的 `siyuan-appearance-isolation:v1` 系统规则块,保留块外用户规则的内容和顺序。此后不再生成或维护隔离块。+升级时移除 `.siyuan/syncignore` 中完整的 `siyuan-appearance-isolation:v1` 系统规则块;重新加载忽略规则时,也会清除同步或快照恢复带回的隔离块,保留块外用户规则的内容和顺序。此后不再生成或维护隔离块。正式实现不再生成逐包摘要及删除记录、不可变包归档、恢复标签,也不再使用外观专用事务协议。安装信息复用共享的 `storage/bazaar.json` 机制。Alpha 版本遗留的 `data/storage/appearance-v1/`、`data/storage/bazaar/themes/`、`data/storage/bazaar/icons/`、`conf/appearance-migration.json` 及已有的 `.siyuan-appearance-v1` 标签不做自动清理,也不用于恢复外观包。已有标签按普通标签处理。diff --git a/kernel/model/appearance_paths_migration.go b/kernel/model/appearance_paths_migration.goindex 3259d8a5a8..107f484bc6 100644--- a/kernel/model/appearance_paths_migration.go+++ b/kernel/model/appearance_paths_migration.go@@ -50,7 +50,7 @@ func MigrateAppearancePackages() error {}func moveAppearancePackage(source, target string) error {- if _, err := os.Lstat(target); err == nil {+ if targetEntry, err := os.Lstat(target); err == nil {sourceInfo, sourceErr := os.Stat(source)targetInfo, targetErr := os.Stat(target)if sourceErr != nil {@@ -60,9 +60,36 @@ func moveAppearancePackage(source, target string) error {return targetErr}if os.SameFile(sourceInfo, targetInfo) {- return nil+ sourceEntry, err := os.Lstat(source)+ if err != nil {+ return err+ }+ sourceParent, err := os.Stat(filepath.Dir(source))+ if err != nil {+ return err+ }+ targetParent, err := os.Stat(filepath.Dir(target))+ if err != nil {+ return err+ }+ if sourceEntry.Name() == targetEntry.Name() && os.SameFile(sourceParent, targetParent) {+ // 父目录的不同路径指向同一个目录项时,没有需要清理的副本。+ return nil+ }+ if !sourceEntry.IsDir() {+ if _, err = os.Readlink(source); err != nil {+ return err+ }+ // 两个入口已指向同一份开发文件,只移除源链接。+ return os.Remove(source)+ }+ // 目标链接依赖源目录时,先移除链接,再将实际目录迁入目标位置。+ if err = os.Remove(target); err != nil {+ return err+ }+ } else {+ return os.RemoveAll(source)}- return os.RemoveAll(source)} else if !os.IsNotExist(err) {return err}diff --git a/kernel/model/appearance_paths_migration_test.go b/kernel/model/appearance_paths_migration_test.goindex c5a6b64fbf..c9e0b1354f 100644--- a/kernel/model/appearance_paths_migration_test.go+++ b/kernel/model/appearance_paths_migration_test.go@@ -2,7 +2,9 @@ package modelimport ("os"+ "os/exec""path/filepath"+ "runtime""testing""github.com/siyuan-note/siyuan/kernel/util"@@ -80,3 +82,83 @@ func TestAppearanceMigrationPreservesDevelopmentLink(t *testing.T) {t.Fatalf("original link remains: %v", err)}}++func createAppearanceMigrationDirectoryLink(t *testing.T, link, target string) {+ t.Helper()+ if err := os.Symlink(target, link); err != nil {+ if runtime.GOOS != "windows" {+ t.Skipf("symlinks unavailable: %v", err)+ }+ if output, err := exec.Command("cmd", "/d", "/c", "mklink", "/J", link, target).CombinedOutput(); err != nil {+ t.Skipf("directory links unavailable: %v %s", err, output)+ }+ }+}++func TestAppearanceMigrationRemovesExistingAliases(t *testing.T) {+ for _, layout := range []string{"shared-development-directory", "destination-points-to-source", "source-points-to-destination"} {+ t.Run(layout, func(t *testing.T) {+ setupAppearancePackagesTest(t)+ external := t.TempDir()+ writeAppearanceTestFile(t, filepath.Join(external, "asset.txt"), "development asset")+ source := filepath.Join(util.AppearancePath, "themes", "linked")+ target := filepath.Join(util.ThemesPath, "linked")+ switch layout {+ case "shared-development-directory":+ createAppearanceMigrationDirectoryLink(t, source, external)+ createAppearanceMigrationDirectoryLink(t, target, external)+ case "destination-points-to-source":+ writeAppearanceTestFile(t, filepath.Join(source, "theme.css"), "development theme")+ createAppearanceMigrationDirectoryLink(t, filepath.Join(source, "assets"), external)+ createAppearanceMigrationDirectoryLink(t, target, source)+ case "source-points-to-destination":+ writeAppearanceTestFile(t, filepath.Join(target, "theme.css"), "development theme")+ createAppearanceMigrationDirectoryLink(t, source, target)+ }+ if err := moveAppearancePackage(source, target); err != nil {+ t.Fatal(err)+ }+ if _, err := os.Lstat(source); !os.IsNotExist(err) {+ t.Fatalf("source alias remains: %v", err)+ }+ file, want := "theme.css", "development theme"+ if layout == "shared-development-directory" {+ file, want = "asset.txt", "development asset"+ }+ if data, err := os.ReadFile(filepath.Join(target, file)); err != nil || string(data) != want {+ t.Fatalf("migrated package is unreadable: %q, %v", data, err)+ }+ if layout == "destination-points-to-source" {+ if data, err := os.ReadFile(filepath.Join(target, "assets", "asset.txt")); err != nil || string(data) != "development asset" {+ t.Fatalf("nested development link changed: %q, %v", data, err)+ }+ }+ if err := os.RemoveAll(target); err != nil {+ t.Fatal(err)+ }+ if err := MigrateAppearancePackages(); err != nil {+ t.Fatal(err)+ }+ if _, err := os.Lstat(target); !os.IsNotExist(err) {+ t.Fatalf("uninstalled package reappeared: %v", err)+ }+ if data, err := os.ReadFile(filepath.Join(external, "asset.txt")); err != nil || string(data) != "development asset" {+ t.Fatalf("external development files changed: %q, %v", data, err)+ }+ })+ }+}++func TestAppearanceMigrationPreservesAliasedParent(t *testing.T) {+ root := t.TempDir()+ writeAppearanceTestFile(t, filepath.Join(root, "themes", "shared", "theme.css"), "shared")+ alias := filepath.Join(t.TempDir(), "themes")+ createAppearanceMigrationDirectoryLink(t, alias, filepath.Join(root, "themes"))+ target := filepath.Join(root, "themes", "shared")+ if err := moveAppearancePackage(filepath.Join(alias, "shared"), target); err != nil {+ t.Fatal(err)+ }+ if data, err := os.ReadFile(filepath.Join(target, "theme.css")); err != nil || string(data) != "shared" {+ t.Fatalf("shared directory was removed: %q, %v", data, err)+ }+}diff --git a/kernel/model/sync.go b/kernel/model/sync.goindex d249022e06..322cc3370f 100644--- a/kernel/model/sync.go+++ b/kernel/model/sync.go@@ -998,6 +998,10 @@ func loadSyncIgnoreLines() (ret []string, err error) {defer func() {ret = append(ret, "/.siyuan/conf.json")}()+ // 同步或快照可能重新带回隔离块,加载规则前完成清理。+ if err = util.MigrateAppearanceSyncIgnore(); err != nil {+ return+ }ignore := filepath.Join(util.DataDir, ".siyuan", "syncignore")err = os.MkdirAll(filepath.Dir(ignore), 0755)if err != nil {diff --git a/kernel/model/sync_ignore_test.go b/kernel/model/sync_ignore_test.goindex 7aee529e83..e11f84cec4 100644--- a/kernel/model/sync_ignore_test.go+++ b/kernel/model/sync_ignore_test.go@@ -5,7 +5,9 @@ import ("path/filepath""reflect""sort"+ "strings""testing"+ "time"ignore "github.com/sabhiram/go-gitignore""github.com/siyuan-note/dejavu"@@ -27,6 +29,95 @@ func mustSyncIgnoreLines(t testing.TB) []string {return lines}+func TestSyncIgnoreRemovesRestoredAppearanceIsolation(t *testing.T) {+ setupAppearancePackagesTest(t)+ oldWorking := util.WorkingDir+ util.WorkingDir = t.TempDir()+ t.Cleanup(func() { util.WorkingDir = oldWorking })+ block := "# siyuan-appearance-isolation:v1:begin\n/themes/\n/icons/\n/storage/bazaar/themes/\n/storage/bazaar/icons/\n# siyuan-appearance-isolation:v1:end\n"+ userRules := "# local packages\n/themes/local/\n/icons/local/\n"+ rule := filepath.Join(util.DataDir, syncIgnoreRulePath)+ writeAppearanceTestFile(t, rule, userRules+block)+ oldTime := time.Unix(1700000000, 0)+ if err := os.Chtimes(rule, oldTime, oldTime); err != nil {+ t.Fatal(err)+ }+ base := t.TempDir()+ options := dejavu.Options{+ DataPath: util.DataDir, RepoPath: filepath.Join(base, "repo"), HistoryPath: filepath.Join(base, "history"), TempPath: filepath.Join(base, "temp"),+ DeviceID: "device", DeviceName: "device", DeviceOS: "windows", AESKey: []byte("0123456789abcdef0123456789abcdef"),+ IgnoreLines: strings.Split(userRules+block, "\n"), IgnoreRulePath: syncIgnoreRulePath, HiddenDirectoryNames: []string{".siyuan"},+ PathFilter: func(info os.FileInfo, path string) (bool, error) {+ return syncPathFilter(util.DataDir, info, path)+ },+ }+ repo, err := dejavu.NewRepoWithOptions(options)+ if err != nil {+ t.Fatal(err)+ }+ before, err := repo.Index("before migration", true, nil)+ if err != nil {+ t.Fatal(err)+ }+ if err = MigrateAppearancePackages(); err != nil {+ t.Fatal(err)+ }+ options.IgnoreLines = mustSyncIgnoreLines(t)+ repo, err = dejavu.NewRepoWithOptions(options)+ if err != nil {+ t.Fatal(err)+ }+ if _, err = repo.Index("after migration", true, nil); err != nil {+ t.Fatal(err)+ }+ if err = checkoutRepoSnapshot(repo, before.ID, func(error) {}); err != nil {+ t.Fatal(err)+ }+ if data, err := os.ReadFile(rule); err != nil || string(data) != userRules+block {+ t.Fatalf("snapshot did not restore the isolation block: %q, %v", data, err)+ }+ _, matcher := mustSyncIgnoreRules(t)+ for _, path := range []string{"/themes/custom/theme.css", "/icons/custom/icon.js"} {+ if matcher.MatchesPath(path) {+ t.Fatalf("restored isolation block excludes package: %s", path)+ }+ }+ for _, path := range []string{"/themes/local/theme.css", "/icons/local/icon.js"} {+ if !matcher.MatchesPath(path) {+ t.Fatalf("user rule was removed: %s", path)+ }+ }+ if data, err := os.ReadFile(rule); err != nil || string(data) != userRules {+ t.Fatalf("restored isolation block not removed cleanly: %q, %v", data, err)+ }+ _, cached := mustSyncIgnoreRules(t)+ _, reused := mustSyncIgnoreRules(t)+ if cached != reused {+ t.Fatal("cleaned rules were not cached")+ }+}++func TestSyncIgnoreRejectsModifiedAppearanceIsolation(t *testing.T) {+ oldData, oldWorking := util.DataDir, util.WorkingDir+ util.DataDir, util.WorkingDir = t.TempDir(), t.TempDir()+ t.Cleanup(func() { util.DataDir, util.WorkingDir = oldData, oldWorking })+ mustSyncIgnoreRules(t)+ rule := filepath.Join(util.DataDir, syncIgnoreRulePath)+ original := "# siyuan-appearance-isolation:v1:begin\n/custom/\n"+ writeAppearanceTestFile(t, rule, original)+ if _, matcher, err := getSyncIgnoreRules(); err == nil || matcher != nil {+ t.Fatal("modified isolation block produced usable rules")+ }+ if data, err := os.ReadFile(rule); err != nil || string(data) != original {+ t.Fatalf("modified rules were not preserved: %q, %v", data, err)+ }+ writeAppearanceTestFile(t, rule, "/custom/\n")+ _, matcher := mustSyncIgnoreRules(t)+ if !matcher.MatchesPath("/custom/file") {+ t.Fatal("rule loading did not recover after correction")+ }+}+func TestSyncIgnoreGuideReadFailureRecovers(t *testing.T) {oldData, oldWorking := util.DataDir, util.WorkingDirutil.DataDir, util.WorkingDir = t.TempDir(), t.TempDir()