Skip to content

Commit

Permalink
potential patch to broken symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgomez committed Aug 27, 2024
1 parent c3aff2a commit 3a431df
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/nimblepkg/packageinstaller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,25 @@ proc setupBinSymlink*(symlinkDest, symlinkFilename: string,
symlinkDestRel = relativePath(symlinkDest, symlinkFilename.parentDir())
currentPerms = getFilePermissions(symlinkDest)
setFilePermissions(symlinkDest, currentPerms + {fpUserExec})
when defined(unix):
display("Creating", "symlink: $1 -> $2" %
[symlinkDest, symlinkFilename], priority = MediumPriority)
if fileExists(symlinkFilename):
when defined(unix):
proc removeWithWarning() =
let msg = "Symlink already exists in $1. Replacing." % symlinkFilename
display("Warning:", msg, Warning, HighPriority)
removeFile(symlinkFilename)
removeFile(symlinkFilename)

createSymlink(symlinkDestRel, symlinkFilename)
display("Creating", "symlink: $1 -> $2" %
[symlinkDest, symlinkFilename], priority = MediumPriority)
if fileExists(symlinkFilename):
removeWithWarning()
try:
createSymlink(symlinkDestRel, symlinkFilename)
except OSError as ex:
#fileExists may return false for broken symlink
if "File exists" in ex.msg:
removeWithWarning()
createSymlink(symlinkDestRel, symlinkFilename)
else:
raise ex
result.add symlinkFilename.extractFilename
elif defined(windows):
# There is a bug on XP, described here:
Expand Down

0 comments on commit 3a431df

Please sign in to comment.