How do I set file information on a *link*

This forum is for general developer support questions.
colinward
Beta Tester
Beta Tester
Posts: 8
Joined: Sun Jan 06, 2013 9:29 am

How do I set file information on a *link*

Post by colinward »

Hello everyone.

I have some self written backup software and I have just added support for copying links. This works very well and both the link and the file it points to are now copied to the destination directory and the new link points to the new file correctly. I had to add this support to get my SDK to function on my new Amiga as there are lots of soft links in the SDK! :D

Just one problem. When my backup software copies a file it then sets the time, date and attributes of the newly copied target file to be the same as the source file. But when I try to set the time and date on the link I have created, the IDOS->SetDate() function resolves the link and sets the time and date on the *target* file. Of course in 99.5% of situations this is what you want, but in this case I want to set the date and time on the *link* and not the target.

This means that my backup software always thinks the link has changed and copies it again. You can see here that using the "list" command it shows that the link itself has its own date and time attributes:

Code: Select all

$List Ram:C/Perl#?
Directory "Ram:C" on Wednesday 02-Dec-15
perl5.8.5                  2130268 ----rwed 03-Nov-13 15:22:22
perl                        2130268 ----rwed Today    07:30:29
> Ram:C/perl5.8.5
Any ideas how I can set the time and date on a link?
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1479
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: How do I set file information on a *link*

Post by tonyw »

Hi Colin,

There is a discrepancy here between the way that I understand it and the way that it works with RAM Disk. Let me consult the Guru about it.

BTW, the date/time displayed for the link is what the file system decides to display. In the case of another file system, the displayed date/time might be different.
cheers
tony
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: How do I set file information on a *link*

Post by xenic »

colinward wrote:Any ideas how I can set the time and date on a link?
I just tested changing a link date on an SFS partition and it appeared to work correctly; the date of the link was changed and not the file it points to. The same goes for changing the protection bits. However, I think that the link should be created with the same protection bits as the file it points to. It appears that links are always created with 'RWED' protection bits which makes it appear that the link points to an executable file.

I also just noticed that the wrong protection bits are set by the echo command. Whan text is redirected to a file (like 'echo testing >ram:file') the E (executable) protection bit should not be set. If we're going to have protection bits, at least the system programs and AmigaDOS commands should set them correctly.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: How do I set file information on a *link*

Post by broadblues »

@xenic
echo example
No in fact the opposite is true redirection files are created with no protection bits set all. Which is why they show up as ----rwed.

Check the autodoc on IDOS->SetProtect() to understand why.

I just tested changing a link date on an SFS partition and it appeared to work correctly; the date of the link was changed and not the file it points to. The same goes for changing the protection bits.
Actually no, it depends how you "list" them see below. The file was updated not the link, you just thought it was the link because you listed the link explicitly.
However, I think that the link should be created with the same protection bits as the file it points to. It appears that links are always created with 'RWED' protection bits which makes it appear that the link points to an executable file.
(Soft) Links actually show the protection bits of the target file if you list them explictly or rwed if you list them as part fo a directory.

eg

9.RAM Disk:> list bash
bash 4 -s--rw-d Today 20:24:42
1 file - 4 bytes - 2 blocks used
9.RAM Disk:> list
bash 4 ----rwed Today 20:25:11
> foo
foo 4 -s--rw-d Today 20:24:42

Links are not files, do not expect them to be.


[edits]
Quote structure and appaling spolling
User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 207
Joined: Mon Aug 15, 2011 9:20 am
Location: Brisbane, QLD. Australia.

Re: How do I set file information on a *link*

Post by colinw »

As broadblues indicated above...

What you see displayed for a softlink is totally dependant on what the display software wants to show,
it alone is responsible for resolving the softlink to the target object, the cannonical behaviour is to display
the meta-data for the target object, the softlink itself has no meta-data per se, even though it still uses the
same data structure as all other objects in the directory scanner.

So, when scanning a directory, the softlink entry itself should only have a valid "Name", "Type", "ObjectID"
and conditionally the "Link" field with the target name, if that option is selected.

A basic creation datestamp and possibly default protection bits may also be there from when the common
routine in the filesystem created it, but there is absolutely no guarantee that a filesystem would even do that,
however, it is most likely you would see that if one were to displaying the raw softlink entry data structure,
no matter how pointless it may be.

There is no actual method available to change meta-data for softlinks, the protection mask, datestamp,
comment strings, user ID, group ID or any other meta-data that I forgot to mention.

In DOS, the only operations that can affect a softlink itself are the MakeLink(), Delete() and conditionally
Rename() functions. All other functions affect only the softlink target object, this is generally indicated
in the first line of the autodoc, eg....

* NAME
* SetDate -- Sets the modification date for a file or directory.

* NAME
* SetProtection -- Set protection for a file or directory

* NAME
* Delete -- Delete a file, directory or symbolic link.

* NAME
* Rename -- Rename a file, directory or symbolic link.
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: How do I set file information on a *link*

Post by xenic »

broadblues wrote:No in fact the opposite is true redirection files are created with no protection bits set all. Which is why they show up as ----rwed.

Check the autodoc on IDOS->SetProtect() to understand why.
I know how it works; I'm saying that I think it should work differently. The default protection bits for any redirected data (> or >>) should exclude the executable bit; even if it means the bits should be changed after the file is written. The same should be true for any AmigaDOS commands that have a 'TO' argument that directs the output to a filesystem device.
Actually no, it depends how you "list" them see below. The file was updated not the link, you just thought it was the link because you listed the link explicitly.
To me that's an inconsistancy in the list command that shouldn't exist. Metaphorically speaking, a duck is a duck; whether it stands alone or in a group of ducks.
(Soft) Links actually show the protection bits of the target file if you list them explictly or rwed if you list them as part fo a directory.
As I stated above, I think that's inconsistant and should be fixed.
Links are not files, do not expect them to be.
True but that doesn't mean AmigaDOS commands can't display them in a consistant way.
AmigaOne X1000 with 2GB memory - OS4.1 FE
xenic
Posts: 1185
Joined: Sun Jun 19, 2011 12:06 am

Re: How do I set file information on a *link*

Post by xenic »

@Colin
I retested and found that I was mistaken about the results in my first test. I was observing the results in Dopus4 which doesn't show date changes with SFS or RAM: unless you explicitly 'rescan' the directory. However, on an FFS partition the date of the link is changed and Dopus4 shows the change without an explicit rescan. I ran the tests using the list command to list the entire directory and got these results:

Using AmigaDOS Setdate on a link with SFS changes the target file date but not the link.
Using AmigaDOS Setdate on a link with RAM: changes the target file date but not the link.
Using AmigaDOS Setdate on a link with FFS changes the the link date but not the target file.

I don't like the idea that when a user attempts to change link metadata, the target file metadate is actually changed. There is also an inconsistancy in the way different filesystems handle such changes. Personally, I think it would be better to change the DOS library date and protection functions to silently fail if a user (or programmer) attempts to change link dates or protection bits. That would eliminate filesystem inconsistancies for link metadata.
AmigaOne X1000 with 2GB memory - OS4.1 FE
User avatar
colinw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 207
Joined: Mon Aug 15, 2011 9:20 am
Location: Brisbane, QLD. Australia.

Re: How do I set file information on a *link*

Post by colinw »

xenic wrote:@Colin
...
I don't like the idea that when a user attempts to change link metadata, the target file metadate is actually changed.
There is also an inconsistancy in the way different filesystems handle such changes.
Personally, I think it would be better to change the DOS library date and protection functions to silently fail if a user
(or programmer) attempts to change link dates or protection bits.
That would eliminate filesystem inconsistancies for link metadata.
Unfortunately that defeats the purpose of symbolic links.
An operation on the link is supposed to be equivalent to an operation on the target object.
colinward
Beta Tester
Beta Tester
Posts: 8
Joined: Sun Jan 06, 2013 9:29 am

Re: How do I set file information on a *link*

Post by colinward »

Unfortunately that defeats the purpose of symbolic links.
An operation on the link is supposed to be equivalent to an operation on the target object.
Coming back to this subject after a three month distraction...

The conversation you have all had in this thread is all very interesting, but you have forgotten one small point, that I mentioned in my original E-Mail - it only applies to 99% of use cases! The 1% of use cases is represented by backup software, where you want to mirror *exactly* what is on the source disk onto the target disk, and this includes the link metadata. On Windows when you set the date/time or protection bits on a link, you can specify a flag that specifies whether to follow the link or not. On 99% of the software you would follow the link, but on backup software you do not. This allows independently setting the metadata of the link and the file that it points to.

If at a later time the link changes then the backup software knows to copy the link, which is a different operation to copying the file it points to.

So I would say that we have missing API functionality on Amiga OS. I guess I will just have to tolerate that my backup software will always recreate links because it will always think that they have changed due to the metadata of the source link being different to the metadata of the destination link.

@Colin Wenzel, if I raised a Buzgilla asking for Windows style "perform this operation on the link, not on the file it points to" functionality, would there be a chance of it being implemented?
User avatar
tonyw
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 1479
Joined: Wed Mar 09, 2011 1:36 pm
Location: Sydney, Australia

Re: How do I set file information on a *link*

Post by tonyw »

[deleted]
cheers
tony
Post Reply