aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/osutil
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/osutil
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/osutil')
-rw-r--r--pkg/osutil/fileutil.go10
1 files changed, 10 insertions, 0 deletions
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.