adrianinsaval wrote: ↑Tue Jun 21, 2022 2:17 pm
got it, but is that default behavior of c++ functions or something implemented by coreutils?
I'm not sure there is a "standard". Anyway FC uses its own implementations (that call OS-dependent APIs) so it won't just work in a snap.
See my post as a picture to give the idea rather than as a ready-to-go solution.
https://en.cppreference.com/w/cpp/filesystem/copy_file awfully written or I just don't have enough knowledge to get it. I don't understand what happens when to is an existing symlink, symlinks are only mentioned for the case were to doesn't exist and it's not clear to me if it's saying it follows symlinks in to or in from
edit: I think it's supposed to throw an error if the destination file is a symlink so I think copying the file wouldn't be a solution
adrianinsaval wrote: ↑Tue Jun 21, 2022 4:02 pmhttps://en.cppreference.com/w/cpp/filesystem/copy_file awfully written or I just don't have enough knowledge to get it. I don't understand what happens when to is an existing symlink, symlinks are only mentioned for the case were to doesn't exist and it's not clear to me if it's saying it follows symlinks in to or in from
In the 'Notes', it tells that this function "follows symlinks". So I guess it's for both 'from' and 'to', so this could work.
openBrain wrote: ↑Tue Jun 21, 2022 4:32 pm
In the 'Notes', it tells that this function "follows symlinks". So I guess it's for both 'from' and 'to', so this could work.
This
Report an error if any of the following is true:
• to is not a regular file as determined by !filesystem::is_regular_file(to)
makes me believe it would throw an error if to is a symlink, I believe that the notes refer to following symlinks in from, this is reinforced because as an alternative it mentions copy_symlink which is meant to copy a symlink to some location, not an arbitrary file to a symlink target.
Last edited by adrianinsaval on Tue Jun 21, 2022 5:10 pm, edited 1 time in total.
@adrianinsaval I think you got it wrong.
Doc says it also throw an error if 'from' is not a regular file. So if symlinks weren't considered as such, there would be no need to specifically comment about them.
Also the point is that you need to use 'copy_symlink' if you want to copy the link itself, because the actual function will follow it and actually copies the file it links to.
Ah! that makes sense, it could work then. It's confusing because in is_regular_file's doc it doesn't say what's the criterion for a regular file but there is mention of is_symlink as if they were separate things, if you look at the example code an example output it should output
adrianinsaval wrote: ↑Tue Jun 21, 2022 5:25 pm
Ah! that makes sense, it could work then. It's confusing because in is_regular_file's doc it doesn't say what's the criterion for a regular file but there is mention of is_symlink as if they were separate things, if you look at the example code an example output it should output
"sandbox/symlink" is a regular file
"sandbox/symlink" is a symlink
for a symlink, but they only show the line stating it's a symlink
Indeed the documentation is a bit imprecise. I don't know for C++, but in Qt it is as you say. A symlink is obviously seen as such, but also say it's a regular file if pointed file exists and is regular. I'll eventually run some tests soon to see exactly what happens there.
Looking again over the fence towards Emacs: there are quite some switches controlling the behaviour of the saving process, one of them is copy vs. rename. On systems supporting it, the ownership and access rights can be different on copy vs. move.
(Besides: I still would call Emacs the first program where free availability was not a matter of accidentially happening because it came from some university or so, but where the idea of freedom was actively promoted).