One self-hosted app for your shows, movies and music.
//go:build linux
package importer
import (
"errors"
"os"
"golang.org/x/sys/unix"
)
// renameNoReplace renames src to dst and never replaces an existing dst.
func renameNoReplace(src, dst string) error {
err := unix.Renameat2(unix.AT_FDCWD, src, unix.AT_FDCWD, dst, unix.RENAME_NOREPLACE)
if errors.Is(err, unix.EINVAL) || errors.Is(err, unix.ENOSYS) || errors.Is(err, unix.EOPNOTSUPP) {
return renameChecked(src, dst)
}
if err != nil {
return &os.LinkError{Op: "rename", Old: src, New: dst, Err: err}
}
return nil
}