mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 15:33:40 +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"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
@@ -228,10 +229,27 @@ func symlink(oldname, newname string) error {
|
|||||||
return symlinkErr
|
return symlinkErr
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Make a hard link.
|
// Try making a hard link.
|
||||||
err := os.Link(oldname, newname)
|
err := os.Link(oldname, newname)
|
||||||
if err != nil {
|
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
|
return nil // success
|
||||||
|
|||||||
Reference in New Issue
Block a user