Setting the attributeModDate
Setting the attributeModDate
- Subject: Setting the attributeModDate
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Mon, 15 Sep 2008 14:20:58 +0700
I am trying to copy a file using NSFilemanagers
copyPath:toPath:handler: method.
The (Tiger) documentation says: "File or directory attributes—that
is, metadata such as owner and group numbers, file permissions, and
modification date—are also copied."
Well, the attributeModDate is not.
So I had a look at the File Manager Reference and found
FSSetCatalogInfo.
It said about kFSCatInfoAttrMod: "Retrieve or set the date that an
attribute or named fork was last modified."
I tried it and nothing happened. No error message. But no change of
attributeModDate either.
Here is the code:
#import <Foundation/Foundation.h>
NSDate *dateFromUTCDateTime( const UTCDateTime *f );
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSProcessInfo *processInfo = [ NSProcessInfo processInfo ];
NSArray *arguments = [ processInfo arguments ];
NSString *lastFileTo = [ arguments objectAtIndex: 1 ];
OSStatus status;
FSRef fileFsRefTo;
const UInt8 *patHTo = (const UInt8 *)[ lastFileTo
fileSystemRepresentation ];
status = FSPathMakeRefWithOptions ( patHTo,
kFSPathMakeRefDoNotFollowLeafSymlink,
&fileFsRefTo,
NULL
);
if ( status != noErr ) return 2;
FSCatalogInfoBitmap whichInfo = kFSCatInfoAttrMod; // attributes
modification date
FSCatalogInfo catalogInfo;
OSErr resul1;
resul1 = FSGetCatalogInfo( &fileFsRefTo, whichInfo, &catalogInfo,
NULL, NULL, NULL);
if ( resul1 != noErr ) return 3;
NSDate *p1 = dateFromUTCDateTime( &catalogInfo.attributeModDate );
NSLog(@"%s got old changeDate on \"%@\" as %@", __FUNCTION__,
lastFileTo, p1 );
catalogInfo.attributeModDate.highSeconds = 0;
catalogInfo.attributeModDate.lowSeconds = 0xf0000000;
catalogInfo.attributeModDate.fraction = 0;
resul1 = FSSetCatalogInfo( &fileFsRefTo, whichInfo, &catalogInfo );
if ( resul1 != noErr ) return 4;
NSDate *p2 = dateFromUTCDateTime( &catalogInfo.attributeModDate );
NSLog(@"%s did set changeDate on \"%@\" to %@", __FUNCTION__,
lastFileTo, p2 );
resul1 = FSGetCatalogInfo( &fileFsRefTo, whichInfo, &catalogInfo,
NULL, NULL, NULL);
if ( resul1 != noErr )return 5;
NSDate *p3 = dateFromUTCDateTime( &catalogInfo.attributeModDate );
NSLog(@"%s got new changeDate on \"%@\" as %@", __FUNCTION__,
lastFileTo, p3 );
[pool release];
return 0;
}
NSDate *dateFromUTCDateTime( const UTCDateTime *ff )
{
CFAbsoluteTime oCFTime;
OSStatus ko = UCConvertUTCDateTimeToCFAbsoluteTime ( ff, &oCFTime );
if ( ko != noErr ) return nil;
NSDate *gy = [ NSDate dateWithTimeIntervalSinceReferenceDate:
oCFTime ];
return gy;
}
Result:
got old changeDate on "/tmp/a" as 2008-09-15 13:25:14 +0700
did set changeDate on "/tmp/a" to 2031-08-05 16:04:00 +0700
got new changeDate on "/tmp/a" as 2008-09-15 13:25:14 +0700
ChangeDate has exited with status 0.
So what did I do wrong? Tested on Tiger 10.4.11.
Kind regards,
Gerriet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden