tldr-pages / tldr-c-client

C command-line client for tldr pages
MIT License
296 stars 49 forks source link

Fall back to `system("mv $tmp $outhome")` when `rename()` fails on Linux #65

Closed marchersimon closed 2 years ago

marchersimon commented 2 years ago

Fixes #64 This issue is actually two issues. The first one is in local.h. We download the file main.zip, which contains the directory tldr-main, but we expect tldr. This was may fault in #59 (Update: I moved this fix to #66, because it's more urgent.)

But this is not the actual issue here. As already explained in #21, Linux mounts /tmp on a different filesystem than the rest of the system. We now try to move a file across two filesystems, using rename(). This isn't supported and therefore it fails. The solution is to manually copy the directory and delete the old one afterwards.

The problem here is, that this is much more complex, than simply calling a function. (Which is probably why #21 didn't get merged). For now I'm simply calling mv /tmp/tldrxxxx/tldr-main ~/.tldrc/tldr. This works perfectly on Linux and maybe on macOS, but probably not on Windows. This would be an example of a cross-platform copying function.

Since that exceeds my C knowledge I'm asking you what to do. Is this client even indented to work on Windows at all?

Update: I now switched the moving back to rename() and only call system("mv $tmp $outhome") when it fails with errno == 18, like #21 attempted. This should not break anything on macOS and fix the issue on Linux.

marchersimon commented 2 years ago

I just got another insight: #59 broke the client on macOS, because of the wrong name, which can be fixed pretty easily by the change I made in local.h. But (at least that's how it seems to me), on Linux, the client never actually worked all those years.

marchersimon commented 2 years ago

Update: I now switched the moving back to rename() and only call system("mv $tmp $outhome") if it fails with errno == 18, like #21 attempted. This should not break anything on macOS and fix the issue on Linux.

github-actions[bot] commented 2 years ago

Hi all! This thread has not had any recent activity. Are there any updates? Thanks!

github-actions[bot] commented 2 years ago

Hi all! This thread has not had any recent activity. Are there any updates? Thanks!

github-actions[bot] commented 2 years ago

Hi all! This thread has not had any recent activity. Are there any updates? Thanks!

github-actions[bot] commented 2 years ago

Hi everyone. This thread is being closed as there was no response to the previous prompt. However, please leave a comment whenever you're ready to resume, so the thread can be reopened. Thanks again!