tldr-pages / tldr-c-client

C command-line client for tldr pages
MIT License
293 stars 50 forks source link

Error: Could Not Rename: ... to ... #95

Closed ar7eniyan closed 11 months ago

ar7eniyan commented 1 year ago

Reproduction Rate

On each tldr <command> run without local database

Steps to Reproduce

  1. rm -rf ~/.tldrc
  2. tldr tldr

Result

Couple seconds of delay (downloading the tldr database), then the error message Error: Could Not Rename: /tmp/tldrXXXXXX/tldr-main to /home/<user>/.tldrc/tldr/, then the actual tldr page. strace shows that the rename call fails with EXDEV (Invalid cross-device link).

Expected Result

Normal output witout error

Additional Information

$ tldr --version
tldr v1.5.0 (v1.5.0-3-g903b38d)
Copyright (C) 2016 Arvid Gerstmann
Source available at https://github.com/tldr-pages/tldr-c-client

Arch Linux, tldr installed from tldr-git

MasterOdin commented 1 year ago

To help me understand the actual bug and fixing it, for your setup, do you have /tmp and /home mounted to different drives?

ar7eniyan commented 1 year ago

@MasterOdin Yes, /tmp is tmpfs and /home is ext4

eliminmax commented 1 year ago

Ran into this issue myself, and found another project with the same issue. Apparently, it's a limitation of the rename() library call, which can be worked around by copying the source to the destination, then deleting the source once it succeeds. This is what the mv command does.

My experience with C is very limited, and given that it does not seem like there's a simple, standard, cross-platform way to copy a file, I don't think I am the right person to fix this.

bric3 commented 1 year ago

I noticed this on a fedora, when doing an update with tldr --update.

The mount output shows indeed the different volumes, which is quite common for /tmp regardless of the distribution.

tmpfs on /tmp type tmpfs (rw,nosuid,nodev,seclabel,nr_inodes=1048576,inode64)
ar7eniyan commented 1 year ago

After some research, I haven't found any reliable cross-platform way to move a directory between different FS, doing it manually in C is error-prone and complicated. Seems like the best way to deal with it is to download a zip file to $HOME/.tldrc/tmp/main.zip. Or if it really needs to be in /tmp (which it doesn't), directory moving can be done using system("/bin/mv ...")

dylanmtaylor commented 1 year ago

I'm also hitting this.

Error: Could Not Rename: /tmp/tldrFB8aMw/tldr-main to /home/taylord/.tldrc/tldr/

My /home is on a separate partition as well.