From 83c15cc9278351dccff4ff1dbeb4a852415d69d3 Mon Sep 17 00:00:00 2001 From: codito Date: Tue, 22 Feb 2022 19:03:30 +0530 Subject: [PATCH] Fix Windows build (#171) --- .gitignore | 3 +++ internal/core/notebook_store.go | 3 ++- internal/util/exec/exec_windows.go | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9d1c75f..dfc646e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,8 @@ # Dependency directories (remove the comment below to include it) # vendor/ +# IDEs/Editors +.vscode/ + notebook.db zk diff --git a/internal/core/notebook_store.go b/internal/core/notebook_store.go index 8002772..5cd4186 100644 --- a/internal/core/notebook_store.go +++ b/internal/core/notebook_store.go @@ -152,7 +152,8 @@ func (ns *NotebookStore) locateNotebook(path string) (string, error) { var locate func(string) (string, error) locate = func(currentPath string) (string, error) { - if currentPath == "/" || currentPath == "." { + // For Windows, the root dir may end with volume name, e.g. E:\\ + if currentPath == "/" || currentPath == filepath.VolumeName(currentPath)+"\\" || currentPath == "." { return "", ErrNotebookNotFound(path) } exists, err := ns.fs.DirExists(filepath.Join(currentPath, ".zk")) diff --git a/internal/util/exec/exec_windows.go b/internal/util/exec/exec_windows.go index 6895ae3..0b22153 100644 --- a/internal/util/exec/exec_windows.go +++ b/internal/util/exec/exec_windows.go @@ -3,15 +3,16 @@ package exec import ( "fmt" "os/exec" + "strings" "syscall" ) // CommandFromString returns a Cmd running the given command. -func CommandFromString(command string) *exec.Cmd { +func CommandFromString(command string, args ...string) *exec.Cmd { cmd := exec.Command("cmd") cmd.SysProcAttr = &syscall.SysProcAttr{ HideWindow: false, - CmdLine: fmt.Sprintf(` /v:on/s/c "%s"`, command), + CmdLine: fmt.Sprintf(` /v:on/s/c "%s %s"`, command, strings.Join(args[:], " ")), CreationFlags: 0, } return cmd