Re: utimes() no good for symbolic links?
Re: utimes() no good for symbolic links?
- Subject: Re: utimes() no good for symbolic links?
- From: Jerry Krinock <email@hidden>
- Date: Sat, 16 Dec 2006 08:20:53 -0800
- Thread-topic: utimes() no good for symbolic links?
OK, I tried FSSetCatalogInfo, and it fails for symlinks also, a little
differently. FSPathMakeRef seems to be trying to follow the link, and
instead of setting the times to the current times like utimes() does, it
leaves the times unchanged.
The Finder does not copy "Date Modified" as expected either. If I File >
Duplicate a regular file, the "Date Modified" of the copy is the same as
that of the original. But if I File > Duplicate a symlink, the the "Date
Modified" of the copy is the current time.
I'm getting a little off topic with the Carbon stuff, but if there is a
solution to this problem, I suspect it is at the BSD layer. Any ideas?
Thanks,
Jerry Krinock
********* TEST PROGRAM FOR FSSetCatalogInfo ************
Sorry for the kludgey conversion of seconds to years for display, but the
only way I know to do that uses Cocoa (NSDate), and I wanted to keep this
easily reproducible for the unix folks.
#include <stdio.h>
#import <CoreServices/CoreServices.h>
#include <sys/stat.h>
#define SECS_PER_YEAR (365.25 * 24 * 60 * 60)
int main (int argc, const char * argv[]) {
UInt32 y2k2_secs = (2002.2 - 1904) * SECS_PER_YEAR ;
UInt32 y2k3_secs = (2003.2 - 1904) * SECS_PER_YEAR ;
UTCDateTime y2k2_utc = {0, y2k2_secs, 0} ;
UTCDateTime y2k3_utc = {0, y2k3_secs, 0} ;
// Verify that the system thinks it can set this info:
printf(" kFSCatInfoSettableInfo = %4x\n", kFSCatInfoSettableInfo) ;
printf(" access time settable? %4x\n",
kFSCatInfoSettableInfo & kFSCatInfoAccessDate) ;
printf("modification time settable? %4x\n",
kFSCatInfoSettableInfo & kFSCatInfoContentMod) ;
// Make FSRef
FSRef pathRef;
OSErr osErr = FSPathMakeRef((UInt8*)"/f1", &pathRef, NULL);
printf("osErr %i from FSPathMakeRef\n", osErr) ;
// Change file to have these atime and mtime
FSCatalogInfo catInfo ;
catInfo.accessDate = y2k2_utc ;
catInfo.contentModDate = y2k3_utc ;
osErr = FSSetCatalogInfo(
&pathRef,
kFSCatInfoAccessDate | kFSCatInfoContentMod,
&catInfo) ;
printf("osErr %i from FSSetCatalogInfo\n", osErr) ;
// Now read the times back. Use lstat because gives info about
// the symlink, not the symlink target, for symlinks
struct stat stats ;
lstat("/f1", &stats) ;
printf("f1 atime: %f\n", stats.st_atime/SECS_PER_YEAR + 1970) ;
printf("f1 mtime: %f\n", stats.st_mtime/SECS_PER_YEAR + 1970) ;
return 0;
}
********* RESULTS **********************
SETUP. Since man utimes (2) says that you must be the super user, compile
the program and run under sudo, just to make sure. Create a file at path
/f1.
First of all, my system claims that both times are settable:
kFSCatInfoSettableInfo = 1fe3
access time settable? 100
modification time settable? 40
Case 1. If /f1 is a regular file, I get the desired result, with the times
set to sometime in 2002 and 2003:
osErr 0 from FSPathMakeRef
osErr 0 from FSSetCatalogInfo
f1 atime: 2002.198631
f1 mtime: 2003.198631
Case 2. If /f1 is a valid symlink, functions return no error but the times
are unchanged:
osErr 0 from FSPathMakeRef
osErr 0 from FSSetCatalogInfo
f1 atime: 2006.956309
f1 mtime: 2006.956309
Case 3. If /f1 is a broken symlink, FSPathMakeRef returns "file not found"
error and the times are unchanged:
osErr -43 from FSPathMakeRef
osErr -35 from FSSetCatalogInfo
f1 atime: 2006.956309
f1 mtime: 2006.956309
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden