aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-12-17 16:56:39 +0100
committerDmitry Vyukov <dvyukov@google.com>2018-12-17 19:09:10 +0100
commita9cc88c19f0c8907d7696b47a2b3b251a2ca06df (patch)
treeadedad6e0ff2a340c5b39bef617407f809a7e69e /pkg
parentb38da77e00c6c2fb3424224657e9f665e519ea2d (diff)
pkg/osutil: provide better Rename
os.Rename fails for cross-device renaming (e.g. to/from tmpfs). This is quite unpleasant. Provide own version that falls back to copying.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/build/akaros.go2
-rw-r--r--pkg/build/linux.go2
-rw-r--r--pkg/db/db.go2
-rw-r--r--pkg/osutil/fileutil.go10
-rw-r--r--pkg/vcs/fuchsia.go2
5 files changed, 14 insertions, 4 deletions
diff --git a/pkg/build/akaros.go b/pkg/build/akaros.go
index 6ee3d774b..60750028f 100644
--- a/pkg/build/akaros.go
+++ b/pkg/build/akaros.go
@@ -52,7 +52,7 @@ func (ctx akaros) build(targetArch, vmType, kernelDir, outputDir, compiler, user
return err
}
targetKey := filepath.Join(kernelDir, "kern", "kfs", ".ssh", "authorized_keys")
- if err := os.Rename(sshkeyPub, targetKey); err != nil {
+ if err := osutil.Rename(sshkeyPub, targetKey); err != nil {
return err
}
const init = `#!/bin/bash
diff --git a/pkg/build/linux.go b/pkg/build/linux.go
index f2bc4e0fe..dbe9cfbb7 100644
--- a/pkg/build/linux.go
+++ b/pkg/build/linux.go
@@ -71,7 +71,7 @@ func (linux) buildKernel(kernelDir, outputDir, compiler string, config []byte) e
}
vmlinux := filepath.Join(kernelDir, "vmlinux")
outputVmlinux := filepath.Join(outputDir, "obj", "vmlinux")
- if err := os.Rename(vmlinux, outputVmlinux); err != nil {
+ if err := osutil.Rename(vmlinux, outputVmlinux); err != nil {
return fmt.Errorf("failed to rename vmlinux: %v", err)
}
return nil
diff --git a/pkg/db/db.go b/pkg/db/db.go
index fde371d90..e3492031b 100644
--- a/pkg/db/db.go
+++ b/pkg/db/db.go
@@ -118,7 +118,7 @@ func (db *DB) compact() error {
return err
}
f.Close()
- if err := os.Rename(f.Name(), db.filename); err != nil {
+ if err := osutil.Rename(f.Name(), db.filename); err != nil {
return err
}
db.uncompacted = len(db.Records)
diff --git a/pkg/osutil/fileutil.go b/pkg/osutil/fileutil.go
index 3e107828f..0b09ff0b4 100644
--- a/pkg/osutil/fileutil.go
+++ b/pkg/osutil/fileutil.go
@@ -40,6 +40,16 @@ func CopyFile(oldFile, newFile string) error {
return os.Rename(tmpFile, newFile)
}
+// Rename is similar to os.Rename but handles cross-device renaming (by copying).
+func Rename(oldFile, newFile string) error {
+ err := os.Rename(oldFile, newFile)
+ if err != nil {
+ // Can't use syscall.EXDEV because this is used in appengine app.
+ return CopyFile(oldFile, newFile)
+ }
+ return err
+}
+
// WriteTempFile writes data to a temp file and returns its name.
func WriteTempFile(data []byte) (string, error) {
// Note: pkg/report knows about "syzkaller" prefix as it appears in crashes as process name.
diff --git a/pkg/vcs/fuchsia.go b/pkg/vcs/fuchsia.go
index 354be6c8d..f9a027f67 100644
--- a/pkg/vcs/fuchsia.go
+++ b/pkg/vcs/fuchsia.go
@@ -56,7 +56,7 @@ func (ctx *fuchsia) initRepo() error {
if _, err := runSandboxed(tmpDir, "bash", "-c", cmd); err != nil {
return err
}
- return os.Rename(filepath.Join(tmpDir, "fuchsia"), ctx.dir)
+ return osutil.Rename(filepath.Join(tmpDir, "fuchsia"), ctx.dir)
}
func (ctx *fuchsia) CheckoutBranch(repo, branch string) (*Commit, error) {