Issues 1665 & 1666; Symbolic links & backups

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Issues 1665 & 1666; Symbolic links & backups

Post by openBrain »

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. :)
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Issues 1665 & 1666; Symbolic links & backups

Post by adrianinsaval »

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
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Issues 1665 & 1666; Symbolic links & backups

Post by Zolko »

openBrain wrote: Tue Jun 21, 2022 8:40 am Another example is respecting the "read-only" parameter of the file.
yes, this, absolutely

* Copy temporary doc as "doc.FCStd"
if doc.FCStd is read-only, then you can't do this copy (at least not in the shell)
try the Assembly4 workbench for FreCAD — tutorials here and here
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Issues 1665 & 1666; Symbolic links & backups

Post by openBrain »

adrianinsaval wrote: Tue Jun 21, 2022 4:02 pm 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
In the 'Notes', it tells that this function "follows symlinks". So I guess it's for both 'from' and 'to', so this could work. ;)
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Issues 1665 & 1666; Symbolic links & backups

Post by adrianinsaval »

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.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Issues 1665 & 1666; Symbolic links & backups

Post by openBrain »

@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. ;)
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Issues 1665 & 1666; Symbolic links & backups

Post by adrianinsaval »

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

Code: Select all

"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
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Issues 1665 & 1666; Symbolic links & backups

Post by openBrain »

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

Code: Select all

"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.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Issues 1665 & 1666; Symbolic links & backups

Post by openBrain »

Sorry missed your post
Zolko wrote: Tue Jun 21, 2022 4:27 pm if doc.FCStd is read-only, then you can't do this copy (at least not in the shell)
Yes, that's why it fixes also the read-only issue. ;)
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Issues 1665 & 1666; Symbolic links & backups

Post by chrisb »

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).
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply