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

convert errors if tempdir is on different filesystem #96

Open
lordkekz opened this issue Oct 24, 2024 · 2 comments
Open

convert errors if tempdir is on different filesystem #96

lordkekz opened this issue Oct 24, 2024 · 2 comments

Comments

@lordkekz
Copy link
Contributor

lordkekz commented Oct 24, 2024

Your project looks really exciting!

I was just trying it out, but there are some issues on my system. Here's one, which I may be able to send a PR for, but I want to report it first to get feedback on how you want to solve it.

My environment

I have my /tmp on a tmpfs and I use impermanence with btrfs to mount persistent directories (like git repos).

What happened

When I tried to run git prole convert (after #95), it failed with the following error:

$ git prole convert
• Converting ~/git to a worktree repository at ~/git/nixos-riscv.
  I'll move the following worktrees to new locations:
  • ~/git/nixos-riscv -> ~/git/nixos-riscv/master
  Additionally, I'll convert the repository to a bare repository.

Error:   × failed to rename file from /home/username/git/nixos-riscv/.git to /tmp/.tmp7ju3mQ/.git
  ╰─▶ Cross-device link (os error 18)

How to solve it

I haven't looked into the codebase enough, but I think that git-prole is trying to move the .git to a tempdir before it rearranges the current directory.

@lordkekz
Copy link
Contributor Author

The error happens because std::fs::rename errors when source and destination are on different filesystems. For example, in convert.rs#L477.

@9999years
Copy link
Owner

Huh, that's frustrating. I'm a little surprised that didn't get caught in the tests -- I guess none of the test environments run with the tempdir on a different filesystem, or maybe the whole test suite runs in the tempdir...

I think that we can create a tempdir in the parent of the outer-most worktree and use that to fix this.

lordkekz added a commit to lordkekz/git-prole that referenced this issue Oct 28, 2024
`git prole convert` now creates a tempdir in the parent of the
determined destination of the converted repo.
This prevents some errors when the /tmp directory is on a different
filesystem, such as a tmpfs.

The tempdir will be deleted if and only if it is empty after conversion.
This should always be the case and is to prevent any data loss.

Fixes issue 9999years#96
9999years added a commit that referenced this issue Nov 18, 2024
Fixes issue #96

I tested the change on some repos (no longer gives the error) and ran
the tests with `nix flake check`.
Please do review this carefully since I'm still pretty new to Rust. ^^

### Change summary
`git prole convert` now creates a tempdir in the parent of the
determined destination of the converted repo.
This prevents some errors when the /tmp directory is on a different
filesystem, such as a tmpfs.

The tempdir will be deleted if and only if it is empty after conversion.
This should always be the case and is to prevent any data loss.

---------

Co-authored-by: Rebecca Turner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants