golang/go

os: if rename system call fails, try ioctl(FICLONE)

Open

#41.487 geöffnet am 18. Sept. 2020

Auf GitHub ansehen
 (6 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Go (19.008 Forks)batch import
NeedsInvestigationOS-Linuxhelp wanted

Repository-Metriken

Stars
 (133.883 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

What version of Go are you using (go version)?

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

What did you do?

I am cross-compiling on Mac for Linux

Linux execution env: Linux nas 4.4.190.x86_64.1 #1 SMP Mon Oct 28 01:55:46 UTC 2019 x86_64 GNU/Linux

Build command: GOOS=linux GOARCH=amd64 go build -v

func move(src, dst string) error {
	err := os.Rename(src, dst)
	// cross device move
	if err != nil && strings.Contains(err.Error(), "cross-device") {
		if err := copy(src, dst); err != nil {
			return err
		}
		if err := os.Remove(src); err != nil {
			return err
		}
	}
	return nil
}

What did you expect to see?

os.Rename() to succeed because the source and target are on the same filesystem.

What did you see instead?

os.Rename() returns "invalid cross-device link" and the above code falls back to copy-and-delete. If I do an mv on the command line, it completes immediately - even for multi-gigabyte files.

Contributor Guide