golang/go

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

Open

#41 487 ouverte le 18 sept. 2020

Voir sur GitHub
 (6 commentaires) (0 réactions) (0 assignés)Go (19 008 forks)batch import
NeedsInvestigationOS-Linuxhelp wanted

Métriques du dépôt

Stars
 (133 883 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

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.

Guide contributeur