From a9cc88c19f0c8907d7696b47a2b3b251a2ca06df Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 17 Dec 2018 16:56:39 +0100 Subject: 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. --- pkg/osutil/fileutil.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'pkg/osutil') 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. -- cgit mrf-deployment