mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
8a410b993b
commit
b59a46eef0
+20
-2
@@ -8,6 +8,7 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user