Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot include a repo at the root of another repo (one line fix in description) #1657

Open
solidDoWant opened this issue Oct 31, 2024 · 0 comments · May be fixed by #1659
Open

Cannot include a repo at the root of another repo (one line fix in description) #1657

solidDoWant opened this issue Oct 31, 2024 · 0 comments · May be fixed by #1659

Comments

@solidDoWant
Copy link

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant