- 
                Notifications
    
You must be signed in to change notification settings  - Fork 216
 
Open
Description
I'm attempting to map/include the a subdirectory of one repo to the root of another, as shown here. This fails with the following error (formatted):
failed to copy 'infra-mk3-actual' include from /cluster/gitops/. to /:
  link error: cannot rename /tmp/flux-include-735574679/unpack/cluster/gitops to /tmp/gitrepository-flux-system-infra-mk3-328487949:
    rename /tmp/flux-include-735574679/unpack/cluster/gitops /tmp/gitrepository-flux-system-infra-mk3-328487949:
      file exists
Linking fails, but copying should succeed without issue. The problem is that the renameFallback function errors if linking failed, except in the case where the link is cross-device:
// renameFallback attempts to determine the appropriate fallback to failed rename
// operation depending on the resulting error.
func renameFallback(err error, src, dst string) error {
	// Rename may fail if src and dst are on different devices; fall back to
	// copy if we detect that case. syscall.EXDEV is the common name for the
	// cross device link error which has varying output text across different
	// operating systems.
	terr, ok := err.(*os.LinkError)
	if !ok {
		return err
	} else if terr.Err != syscall.EXDEV {  // This is where the problem occurs
		return fmt.Errorf("link error: cannot rename %s to %s: %w", src, dst, terr)
	}
	return renameByCopy(src, dst)
}This can be fixed by simply checking if the error is an EEXIST error, and running renameByCopy if so:
// renameFallback attempts to determine the appropriate fallback to failed rename
// operation depending on the resulting error.
func renameFallback(err error, src, dst string) error {
	// Rename may fail if src and dst are on different devices; fall back to
	// copy if we detect that case. syscall.EXDEV is the common name for the
	// cross device link error which has varying output text across different
	// operating systems.
	terr, ok := err.(*os.LinkError)
	if !ok {
		return err
	} else if terr.Err != syscall.EXDEV && terr.Err != syscall.EEXIST {
		return fmt.Errorf("link error: cannot rename %s to %s: %w", src, dst, terr)
	}
	return renameByCopy(src, dst)
}Metadata
Metadata
Assignees
Labels
No labels