Skip to content

Commit

Permalink
Use junctions when mklink, avoid elevated permission
Browse files Browse the repository at this point in the history
  • Loading branch information
h404bi committed Aug 14, 2018
1 parent 635b05b commit 5988853
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
5 changes: 0 additions & 5 deletions bin/elevate.cmd

This file was deleted.

13 changes: 0 additions & 13 deletions bin/elevate.vbs

This file was deleted.

12 changes: 4 additions & 8 deletions src/nvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ func uninstall(version string) {
fmt.Printf("Uninstalling node v"+version+"...")
v, _ := node.GetCurrentVersion()
if v == version {
runElevated(fmt.Sprintf(`"%s" cmd /C rmdir "%s"`,
filepath.Join(env.root, "elevate.cmd"),
runElevated(fmt.Sprintf(`cmd /C rmdir "%s"`,
filepath.Clean(env.symlink)))
}
e := os.RemoveAll(filepath.Join(env.root, "v"+version))
Expand Down Expand Up @@ -397,16 +396,14 @@ func use(version string, cpuarch string) {
// Remove symlink if it already exists
sym, _ := os.Stat(env.symlink)
if sym != nil {
if !runElevated(fmt.Sprintf(`"%s" cmd /C rmdir "%s"`,
filepath.Join(env.root, "elevate.cmd"),
if !runElevated(fmt.Sprintf(`cmd /C rmdir "%s"`,
filepath.Clean(env.symlink))) {
return
}
}

// Create new symlink
if !runElevated(fmt.Sprintf(`"%s" cmd /C mklink /D "%s" "%s"`,
filepath.Join(env.root, "elevate.cmd"),
if !runElevated(fmt.Sprintf(`cmd /C mklink /J "%s" "%s"`,
filepath.Clean(env.symlink),
filepath.Join(env.root, "v"+version))) {
return
Expand Down Expand Up @@ -560,8 +557,7 @@ func enable() {
}

func disable() {
if !runElevated(fmt.Sprintf(`"%s" cmd /C rmdir "%s"`,
filepath.Join(env.root, "elevate.cmd"),
if !runElevated(fmt.Sprintf(`cmd /C rmdir "%s"`,
filepath.Clean(env.symlink))) {
return
}
Expand Down

0 comments on commit 5988853

Please sign in to comment.