Skip to content

Commit

Permalink
loader: work around Windows symlink limitation
Browse files Browse the repository at this point in the history
Currently there will be a problem if the TinyGo installation directory
is not the same filesystem as the cache directory (usually the C drive)
and Developer Mode is disabled. Therefore, let's add another fallback
for when both conditions are true, falling back to copying the file
instead of symlinking/hardlinking it.
  • Loading branch information
aykevl authored and deadprogram committed Aug 19, 2020
1 parent 8a410b9 commit b59a46e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions loader/goroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
Expand Down Expand Up @@ -228,10 +229,27 @@ func symlink(oldname, newname string) error {
return symlinkErr
}
} else {
// Make a hard link.
// Try making a hard link.
err := os.Link(oldname, newname)
if err != nil {
return symlinkErr
// Making a hardlink failed. Try copying the file as a last
// fallback.
inf, err := os.Open(oldname)
if err != nil {
return err
}
defer inf.Close()
outf, err := os.Create(newname)
if err != nil {
return err
}
defer outf.Close()
_, err = io.Copy(outf, inf)
if err != nil {
os.Remove(newname)
return err
}
// File was copied.
}
}
return nil // success
Expand Down

0 comments on commit b59a46e

Please sign in to comment.