Skip to content

Commit b59a46e

Browse files
aykevldeadprogram
authored andcommitted
loader: work around Windows symlink limitation
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.
1 parent 8a410b9 commit b59a46e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

loader/goroot.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/hex"
99
"errors"
1010
"fmt"
11+
"io"
1112
"io/ioutil"
1213
"math/rand"
1314
"os"
@@ -228,10 +229,27 @@ func symlink(oldname, newname string) error {
228229
return symlinkErr
229230
}
230231
} else {
231-
// Make a hard link.
232+
// Try making a hard link.
232233
err := os.Link(oldname, newname)
233234
if err != nil {
234-
return symlinkErr
235+
// Making a hardlink failed. Try copying the file as a last
236+
// fallback.
237+
inf, err := os.Open(oldname)
238+
if err != nil {
239+
return err
240+
}
241+
defer inf.Close()
242+
outf, err := os.Create(newname)
243+
if err != nil {
244+
return err
245+
}
246+
defer outf.Close()
247+
_, err = io.Copy(outf, inf)
248+
if err != nil {
249+
os.Remove(newname)
250+
return err
251+
}
252+
// File was copied.
235253
}
236254
}
237255
return nil // success

0 commit comments

Comments
 (0)