site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Thread-index: AcciUQG5QCPBk45EEducvAAWy6NyrA== Thread-topic: utimes() no good for symbolic links? User-agent: Microsoft-Entourage/11.2.5.060620 on 06/12/16 9:17, Quinn at eskimo1@apple.com wrote:
Try getting the times with <x-man-page://2/getattrlist>. That has an option to not following leaf symlinks (FSOPT_NOFOLLOW) and, if anything can return this information correctly, that'll be it.
Well, to ^return^ (read) the metadata datetimes was not my problem; lstat(2) can do this. The problem was to "set" (write) these datetimes. This should be do-able by utimes(), but it "just doesn't work". However, Quinn, your tip to getattrlist() pointed me to what I was possibly looking for, setattrlist(). So, I wrote a tool to test setattrlist(), with FSOPT_NOFOLLOW. TEST RESULTS: I find that setattrlist() has the same "undocumented behavior" as utimes(): When I tell it to set the metadata datetimes of a symlink, it smiles and returns 0, but "just doesn't work". The datetimes remain unchanged. (I tested creation, modification and access datetimes.) When this same tool is called upon a regular file, it "just works". Should I bother to file bug reports? To the Apple DTS Bug Reporter or is there a separate Darwin bug tracker? on 06/12/16 21:51, Terry Lambert at tlambert@apple.com wrote:
Here is the short answer:... Here is a long answer you are not going to like:... Here is a longer answer that you're really not going to like:...
Thanks very much, Terry. I had come across some of this history, but can now appreciate how dumb we are indeed when we look at an icon in a Finder window and say "That's a file", as if we know what that means! My assignment was to write code which would copy "symlinks with all their metadata". But I've not yet found a way to copy the datetimes metadata of a symlink. One unexplored possibility might be to copy the symlink, somehow setting it to to be a "regular file", so that I can fool utimes() or setattrlist() into setting its datetimes metadata to that of the "original symlink", and then after that, sneakily change the file type to be a symlink. But this seems too wacky to use in real life, and I might well run into another showstopper anyhow, because I noticed accidentally that setattrlist() fails with errno=22 "invalid argument" if I ever try and set the file type, ATTR_CMN_OBJTYPE. (By the way, this failure is undocumented also.) So, unless someone has another idea, I am going to resolve this issue by telling my user: "When you copy a symlink, the datetimes metadata of the copy will be the time of the copy, instead of the times on the original symlink, because a symlink cannot be copied, it can only be 'recreated'. This is OK because a symlink is not really a file. And who the hell cares ^when^ you created, modified or accessed a symlink anyhow, because it's only a stupid symlink, for God's sake!" Does that make sense? Jerry Krinock _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com