From bab56dab69b4aa32300c30d3a2d8cfbea110e6bf Mon Sep 17 00:00:00 2001 From: Wojciech Sobolewski <8691776+wsobolewski@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:14:49 +0100 Subject: [PATCH 1/2] Support whitespace and non-ASCI characters in path. --- src/nvm.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nvm.go b/src/nvm.go index 9bcf5966..ec5bac94 100644 --- a/src/nvm.go +++ b/src/nvm.go @@ -51,10 +51,11 @@ type Environment struct { var home = filepath.Clean(os.Getenv("NVM_HOME") + "\\settings.txt") var symlink = filepath.Clean(os.Getenv("NVM_SYMLINK")) +var root = filepath.Clean(os.Getenv("NVM_HOME")) var env = &Environment{ settings: home, - root: "", + root: root, symlink: symlink, arch: os.Getenv("PROCESSOR_ARCHITECTURE"), node_mirror: "", @@ -1421,6 +1422,7 @@ func saveSettings() { content := "root: " + strings.Trim(encode(env.root), " \n\r") + "\r\narch: " + strings.Trim(encode(env.arch), " \n\r") + "\r\nproxy: " + strings.Trim(encode(env.proxy), " \n\r") + "\r\noriginalpath: " + strings.Trim(encode(env.originalpath), " \n\r") + "\r\noriginalversion: " + strings.Trim(encode(env.originalversion), " \n\r") content = content + "\r\nnode_mirror: " + strings.Trim(encode(env.node_mirror), " \n\r") + "\r\nnpm_mirror: " + strings.Trim(encode(env.npm_mirror), " \n\r") ioutil.WriteFile(env.settings, []byte(content), 0644) + os.Setenv("NVM_HOME", strings.Trim(encode(env.root), " \n\r")) } func getProcessPermissions() (admin bool, elevated bool, err error) { @@ -1479,8 +1481,8 @@ func setup() { m[res[0]] = strings.TrimSpace(strings.Join(res[1:], ":")) } - if val, ok := m["root"]; ok { - env.root = filepath.Clean(val) + if _, ok := m["root"]; ok { + env.root = filepath.Clean(os.Getenv("NVM_HOME")) } if val, ok := m["originalpath"]; ok { env.originalpath = filepath.Clean(val) From dc699f5960af8e9e7bbb849e4eaebe899fedd37a Mon Sep 17 00:00:00 2001 From: Wojciech Sobolewski <8691776+wsobolewski@users.noreply.github.com> Date: Tue, 2 Apr 2024 19:52:28 +0200 Subject: [PATCH 2/2] Code cleanup. --- src/nvm.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/nvm.go b/src/nvm.go index ec5bac94..b3290a48 100644 --- a/src/nvm.go +++ b/src/nvm.go @@ -1481,9 +1481,6 @@ func setup() { m[res[0]] = strings.TrimSpace(strings.Join(res[1:], ":")) } - if _, ok := m["root"]; ok { - env.root = filepath.Clean(os.Getenv("NVM_HOME")) - } if val, ok := m["originalpath"]; ok { env.originalpath = filepath.Clean(val) }