Set date of change of symbolic link in Cocoa

In Cocoa, I would like to set the date the symbolic link changes.

Usage [NSFileManager setAttributes:ofItemAtPath:error:]works well with regular files, but not with symbolic links.

How can i achieve this?

+3
source share
1 answer

There is no way to do this directly with NSFileManager. The setAttributes: ofItemAtPath: error: method terminates a bunch of BSD-based functions, such as utimes, setxattr, chown, etc. All of which follow symbolic links, and not directly to them.

, BSD. " ", , lchown, . , , , . fd-based futimes. :

int fd = open([NSFileManager fileSystemRepresentationWithPath:path], O_RDONLY | O_SYMLINK);
futimes(fd, 0);
close(fd);

, setAttributes: ofSymlinkAtPath: : NSFileManager, futimes, fchflags, fsetxattr ..

, ( , ..), , , , OS X . (Linux , , f *, BSD .)

, API- API NSURL , , ( Mac, ):

[[NSURL fileURLWithPath:path isDirectory:NO] setResourceValue:[NSDate date] forKey:NSURLContentModificationDateKey error:nil];
+6

All Articles