Skip to content

Commit

Permalink
Fix moving files
Browse files Browse the repository at this point in the history
using os.Rename to move files fails when copying files between different
partitions. On Debian 10 it failes with an "invalid cross-device link"
error. The solution is to copy the source file to the destination and
then remove the source.
  • Loading branch information
kyakdan authored and dvyukov committed May 6, 2019
1 parent 8416b0d commit 24b3a97
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions go-fuzz-build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ func main() {

if *flagLibFuzzer {
archive := c.buildInstrumentedBinary(&blocks, nil)
err := os.Rename(archive, *flagOut)
if err != nil {
c.failf("failed to rename file: %v", err)
}
c.moveFile(archive, *flagOut)
return
}

Expand Down Expand Up @@ -663,10 +660,7 @@ func (c *Context) instrumentPackages(blocks *[]CoverBlock, sonar *[]CoverBlock)
if runtime.GOOS == "windows" {
os.Remove(outpath)
}
err := os.Rename(tmp, outpath)
if err != nil {
c.failf("failed to rename file: %v", err)
}
c.moveFile(tmp, outpath)
}
}

Expand Down Expand Up @@ -710,6 +704,14 @@ func (c *Context) copyFile(src, dst string) {
}
}

func (c *Context) moveFile(src, dst string) {
c.copyFile(src, dst)
err := os.Remove(src)
if err != nil {
c.failf("moveFile: removing %q failed: %v", src, err)
}
}

func (c *Context) failf(str string, args ...interface{}) {
c.cleanup()
fmt.Fprintf(os.Stderr, str+"\n", args...)
Expand Down

0 comments on commit 24b3a97

Please sign in to comment.