Garux / netradiant-custom

The open-source, cross-platform level editor for id Tech based games.
https://garux.github.io/NRC/
Other
301 stars 52 forks source link

[patch] Keep symlinks #107

Closed wdoekes closed 1 year ago

wdoekes commented 2 years ago

When a file is a symlink, do not replace it with a real file: https://github.com/wdoekes/nrcradiant-deb/blob/main/patches/nrcradiant-no-move-map-symlink.patch

This patch also helps when coopering on map editing through a shared VCS.

Garux commented 2 years ago

Looks reasonable to not rename symlinks in general, unless we want to be more precise as in resolve to a file itself and operate on it. lstat is not crossplatform, this looks like solution https://en.cppreference.com/w/cpp/filesystem/is_symlink removal of ( !file_exists( backup ) || file_remove( backup ) ) // remove backup is error, rename does not necessarily overwrite https://stackoverflow.com/a/41926145/16652886

wdoekes commented 2 years ago

Confirmed, Microsoft decided to behave differently indeed:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/rename-wrename?view=msvc-170#remarks

The new name must not be the name of an existing file or directory.

https://man7.org/linux/man-pages/man2/rename.2.html

If newpath already exists, it will be atomically replaced, [...]

This looks like a portable version, behaving like posix: https://en.cppreference.com/w/cpp/filesystem/rename

I can whip up a PR.

wdoekes commented 2 years ago

^- PR