xorpaul / g10k

my r10k fork in Go
Apache License 2.0
125 stars 50 forks source link

sync symlink creation/update fails if the symlink points to a nonexistant file #150

Closed juliantaylor closed 4 years ago

juliantaylor commented 4 years ago

the sync fails if you have an an environment that has symlink pointing to a not existing file it fails with:

unTar(): error while creating symlink ...mods-enabled/dbd.load pointing to ../mods-available/dbd.load Error: symlink .../mods-enabled/dbd.load: file exists

g10k 0.8.3

juliantaylor commented 4 years ago

this should do it:

--- a/helper.go
+++ b/helper.go
@@ -84,7 +84,7 @@ func Fatalf(s string) {
 // fileExists checks if the given file exists and returns a bool
 func fileExists(file string) bool {
        //Debugf("checking for file existence " + file)
-       if _, err := os.Stat(file); os.IsNotExist(err) {
+       if _, err := os.Lstat(file); os.IsNotExist(err) {
                return false
        }
        return true
xorpaul commented 4 years ago

The great war of the g10k 0.8.x rewrite and symlinks continues...

Thanks for catching that.

juliantaylor commented 4 years ago

though depending on your other code it may be safer to add a new function that explicitly only tests existance and rename the fileExists to fileReadable?

xorpaul commented 4 years ago

Check out https://github.com/xorpaul/g10k/releases/tag/v0.8.4

juliantaylor commented 4 years ago

thanks it works now