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: Allow marketplace installs beneath linked workspace roots https://github.com/siyuan-note/siyuan/issues/20651
Danielf115b6009781
diff --git a/kernel/bazaar/install_paths.go b/kernel/bazaar/install_paths.goindex 49edd9ee7d..d95d9b8ec4 100644--- a/kernel/bazaar/install_paths.go+++ b/kernel/bazaar/install_paths.go@@ -23,7 +23,7 @@ func installPrivateRoot() string {return filepath.Join(confDir, "plugin-development")}-// makePrivateInstallDir 拒绝链接目录及非绝对根;已有目录同样逐层检查。+// makePrivateInstallDir 拒绝工作空间内部的链接目录及非绝对根;已有目录同样逐层检查。func makePrivateInstallDir(root string) error {if !filepath.IsAbs(root) {return errors.New("private package operation root is unavailable")@@ -42,7 +42,24 @@ func rejectInstallPathLinks(target string) error {if err != nil {return err}+ workspace := ""+ if util.WorkspaceDir != "" && filepath.IsAbs(util.WorkspaceDir) {+ workspace = filepath.Clean(util.WorkspaceDir)+ }for current := target; ; current = filepath.Dir(current) {+ if workspace != "" {+ if relative, relErr := filepath.Rel(workspace, current); relErr == nil && relative == "." {+ // 用户选择的工作空间及其祖先可使用链接,空间内部的操作路径仍须逐层拒绝链接。+ info, statErr := os.Stat(current)+ if statErr != nil {+ return statErr+ }+ if !info.IsDir() {+ return errors.New("package operation workspace must be a directory")+ }+ return nil+ }+ }info, err := os.Lstat(current)if err != nil && !os.IsNotExist(err) {return errdiff --git a/kernel/bazaar/install_paths_windows_test.go b/kernel/bazaar/install_paths_windows_test.gonew file mode 100644index 0000000000..469bebeba8--- /dev/null+++ b/kernel/bazaar/install_paths_windows_test.go@@ -0,0 +1,82 @@+package bazaar++import (+ "os"+ "os/exec"+ "path/filepath"+ "testing"++ "github.com/siyuan-note/siyuan/kernel/util"+)++func makeInstallJunction(t *testing.T, link, target string) {+ t.Helper()+ if output, err := exec.Command("cmd", "/c", "mklink", "/J", link, target).CombinedOutput(); err != nil {+ t.Fatalf("create junction: %v: %s", err, output)+ }+}++func TestInstallPathsAllowWorkspaceJunctions(t *testing.T) {+ for _, workspaceIsJunction := range []bool{false, true} {+ t.Run(map[bool]string{false: "ancestor", true: "workspace"}[workspaceIsJunction], func(t *testing.T) {+ oldWorkspace, oldConf, oldData := util.WorkspaceDir, util.ConfDir, util.DataDir+ t.Cleanup(func() { util.WorkspaceDir, util.ConfDir, util.DataDir = oldWorkspace, oldConf, oldData })+ root := t.TempDir()+ realRoot, alias := filepath.Join(root, "real"), filepath.Join(root, "alias")+ if err := os.Mkdir(realRoot, 0755); err != nil {+ t.Fatal(err)+ }+ makeInstallJunction(t, alias, realRoot)+ util.WorkspaceDir = alias+ if !workspaceIsJunction {+ util.WorkspaceDir = filepath.Join(alias, "workspace")+ }+ if err := os.MkdirAll(util.WorkspaceDir, 0755); err != nil {+ t.Fatal(err)+ }+ util.ConfDir = filepath.Join(util.WorkspaceDir, "conf")+ util.DataDir = filepath.Join(util.WorkspaceDir, "data")+ if err := makePrivateInstallDir(installPrivateRoot()); err != nil {+ t.Fatalf("private operation under workspace junction: %v", err)+ }+ source := filepath.Join(realRoot, "source")+ if err := os.Mkdir(source, 0755); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(filepath.Join(source, "index.js"), []byte("new"), 0644); err != nil {+ t.Fatal(err)+ }+ for _, kind := range []string{"plugins", "themes", "icons", "templates", "widgets"} {+ target := filepath.Join(util.DataDir, kind, "sample")+ if err := replacePackageDirectory(source, target, false); err != nil {+ t.Fatalf("install %s: %v", kind, err)+ }+ if revision, err := InstalledPackageRevision(target); err != nil || !validInstallHash(revision) {+ t.Fatalf("read %s revision: %s, %v", kind, revision, err)+ }+ if err := replacePackageDirectory(source, target, true); err != nil {+ t.Fatalf("update %s: %v", kind, err)+ }+ }+ })+ }+}++func TestInstallPathsRejectJunctionsInsideWorkspace(t *testing.T) {+ oldWorkspace := util.WorkspaceDir+ t.Cleanup(func() { util.WorkspaceDir = oldWorkspace })+ util.WorkspaceDir = t.TempDir()+ outside := t.TempDir()+ for _, relative := range []string{"data/plugins", "conf/plugin-development", "data/themes/sample"} {+ link := filepath.Join(util.WorkspaceDir, filepath.FromSlash(relative))+ if err := os.MkdirAll(filepath.Dir(link), 0755); err != nil {+ t.Fatal(err)+ }+ makeInstallJunction(t, link, outside)+ for _, target := range []string{link, filepath.Join(link, "missing")} {+ if err := rejectInstallPathLinks(target); err == nil {+ t.Fatalf("accepted internal junction: %s", target)+ }+ }+ }+}