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: Avoid copying built-in Pandoc to workspaces https://github.com/siyuan-note/siyuan/issues/18437
Daniel632042202d38
diff --git a/kernel/util/pandoc.go b/kernel/util/pandoc.goindex fe2d1ebac5..bf29b2ed6c 100644--- a/kernel/util/pandoc.go+++ b/kernel/util/pandoc.go@@ -158,9 +158,7 @@ func InitPandoc(customPandocBinPath string) {if pandocVer := getPandocVer(customPandocBinPath); "" != pandocVer {runtimeState.BinPath = customPandocBinPathlogging.LogInfof("custom pandoc [ver=%s, bin=%s]", pandocVer, runtimeState.BinPath)- if "" != installedPandocVer {- removeLegacyPandocDir(tempPandocDir)- }+ removeLegacyPandocDir(tempPandocDir)return}}@@ -172,56 +170,8 @@ func InitPandoc(customPandocBinPath string) {return}- runtimeState.BinPath = pandocBinPath(tempPandocDir)- pandocVer := getPandocVer(runtimeState.BinPath)- if "" != pandocVer {- logging.LogInfof("built-in pandoc [ver=%s, bin=%s]", pandocVer, runtimeState.BinPath)- return- }-- pandocZip := filepath.Join(WorkingDir, "pandoc.zip")- if !gulu.File.IsExist(pandocZip) {- if gulu.OS.IsWindows() {- if "amd64" == runtime.GOARCH {- pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-windows-amd64.zip")- }- } else if gulu.OS.IsDarwin() {- if "amd64" == runtime.GOARCH {- pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-darwin-amd64.zip")- } else if "arm64" == runtime.GOARCH {- pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-darwin-arm64.zip")- }- } else if gulu.OS.IsLinux() {- if "amd64" == runtime.GOARCH {- pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-linux-amd64.zip")- } else if "arm64" == runtime.GOARCH {- pandocZip = filepath.Join(WorkingDir, "pandoc", "pandoc-linux-arm64.zip")- }- }- }-- if !gulu.File.IsExist(pandocZip) {- runtimeState.BinPath = ""- logging.LogErrorf("pandoc zip [%s] not found", pandocZip)- return- }-- if err := gulu.Zip.Unzip(pandocZip, tempPandocDir); err != nil {- runtimeState.BinPath = ""- logging.LogErrorf("unzip pandoc failed: %s", err)- return- }-- if gulu.OS.IsDarwin() || gulu.OS.IsLinux() {- exec.Command("chmod", "+x", runtimeState.BinPath).CombinedOutput()- }- pandocVer = getPandocVer(runtimeState.BinPath)- if "" == pandocVer {- runtimeState.BinPath = ""- logging.LogErrorf("initialized built-in pandoc is invalid")- return- }- logging.LogInfof("initialized built-in pandoc [ver=%s, bin=%s]", pandocVer, runtimeState.BinPath)+ removeLegacyPandocDir(tempPandocDir)+ logging.LogErrorf("built-in pandoc executable [%s] is unavailable", installedPandocBinPath)}func pandocBinPath(pandocDir string) string {diff --git a/kernel/util/pandoc_test.go b/kernel/util/pandoc_test.gonew file mode 100644index 0000000000..fcfec3ce6c--- /dev/null+++ b/kernel/util/pandoc_test.go@@ -0,0 +1,59 @@+// SiYuan - Refactor your thinking+// Copyright (c) 2020-present, b3log.org+//+// This program is free software: you can redistribute it and/or modify+// it under the terms of the GNU Affero General Public License as published by+// the Free Software Foundation, either version 3 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU Affero General Public License for more details.+//+// You should have received a copy of the GNU Affero General Public License+// along with this program. If not, see <https://www.gnu.org/licenses/>.++package util++import (+ "os"+ "path/filepath"+ "testing"+)++func TestInitPandocDoesNotUseWorkspaceTemp(t *testing.T) {+ originalContainer, originalTempDir, originalWorkingDir := Container, TempDir, WorkingDir+ originalRuntime := GetPandocRuntime()+ t.Cleanup(func() {+ Container, TempDir, WorkingDir = originalContainer, originalTempDir, originalWorkingDir+ pandocInitMutex.Lock()+ activePandocRuntime = originalRuntime+ pandocInitMutex.Unlock()+ })++ root := t.TempDir()+ Container = ContainerStd+ TempDir = filepath.Join(root, "temp")+ WorkingDir = filepath.Join(root, "resources")+ legacyPandocDir := filepath.Join(TempDir, "pandoc")+ legacyPandocBin := pandocBinPath(legacyPandocDir)+ if "" == legacyPandocBin {+ t.Skip("Pandoc is not supported on this platform")+ }+ if err := os.MkdirAll(filepath.Dir(legacyPandocBin), 0755); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(legacyPandocBin, []byte("legacy"), 0755); err != nil {+ t.Fatal(err)+ }++ InitPandoc("")++ if runtimeState := GetPandocRuntime(); "" != runtimeState.BinPath {+ t.Fatalf("workspace temporary Pandoc was selected: %q", runtimeState.BinPath)+ }+ if _, err := os.Stat(legacyPandocDir); !os.IsNotExist(err) {+ t.Fatalf("legacy Pandoc temporary directory was not removed: %v", err)+ }+}