NSFileManager destroying target of symlink at changefileattributes

  • dear list,

    following code is executed as root in a test foundation tool.
    it simply copies the localtime symlink (/etc/localtime) to another
    partition and then tries to clone
    its fileattributes. if a copy of the source fileattributes dictionary
    is used
    instead of the original one, the changefileattributes call damages the
    target
    of the symlink replacing it with a broken symlink.

    (ie /usr/share/zoneinfo/yourzone will be damaged, destroying your
    timezone setting.
    make a copy before testing this!)

    if the original dict is used, everything is fine.
    i nslogged both dicts and both are identical.

    (only in this example code i use a trivial copy of the attributes
    dict. the original code has to use
    a mutable copy to alter the permission flags between source and
    target. since this modification
    is not related to the issue i have altered the testcode to just use a
    trivial copy)

    thanks and regards
    thomas bauer - freeridecoding

    #import <Foundation/Foundation.h>

    int main (int argc, const char * argv[]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSFileManager *fm = [NSFileManager defaultManager];
    [fm copyPath:@"/private/etc/localtime" toPath:@"/Volumes/tigerclone/
    localtime" handler:nil];

    NSDictionary *sourceAttributes = [fm fileAttributesAtPath:@"/private/
    etc/localtime" traverseLink:NO];
    NSDictionary *copyattrs= [NSDictionary
    dictionaryWithDictionary:sourceAttributes];

    // [fm changeFileAttributes:copyattrs atPath:@"/Volumes/tigerclone/
    localtime"];    // THIS BREAKS TARGET OF SOURCE SYMLINK
    [fm changeFileAttributes:sourceAttributes atPath:@"/Volumes/
    tigerclone/localtime"];    //THIS IS OK

    [pool release];
        return 0;
    }

    d
  • dear list,

    sorry. in my confustion i forgot the question (although obvious):

    what is going on? why cannot i use a modified copy of attributes
    on the target symlink file?
    how am i supposed to modify a symlinks attributes?
    is writing of attributes to symlinks not supported by nsfilemanager?
    any hint is appreciated....

    regards
    thomas bauer

    Begin forwarded message:

    > From: thomas bauer <tb...>
    > Date: 18. November 2007 20:39:29 GMT+01:00
    > To: <Cocoa-dev...>
    > Subject: NSFileManager destroying target of symlink at
    > changefileattributes
    >
    > dear list,
    >
    > following code is executed as root in a test foundation tool.
    > it simply copies the localtime symlink (/etc/localtime) to another
    > partition and then tries to clone
    > its fileattributes. if a copy of the source fileattributes
    > dictionary is used
    > instead of the original one, the changefileattributes call damages
    > the target
    > of the symlink replacing it with a broken symlink.
    >
    > (ie /usr/share/zoneinfo/yourzone will be damaged, destroying your
    > timezone setting.
    > make a copy before testing this!)
    >
    > if the original dict is used, everything is fine.
    > i nslogged both dicts and both are identical.
    >
    > (only in this example code i use a trivial copy of the attributes
    > dict. the original code has to use
    > a mutable copy to alter the permission flags between source and
    > target. since this modification
    > is not related to the issue i have altered the testcode to just use
    > a trivial copy)
    >
    > thanks and regards
    > thomas bauer - freeridecoding
    >
    >
    > #import <Foundation/Foundation.h>
    >
    > int main (int argc, const char * argv[]) {
    > NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    >
    > NSFileManager *fm = [NSFileManager defaultManager];
    > [fm copyPath:@"/private/etc/localtime" toPath:@"/Volumes/tigerclone/
    > localtime" handler:nil];
    >
    > NSDictionary *sourceAttributes = [fm fileAttributesAtPath:@"/
    > private/etc/localtime" traverseLink:NO];
    > NSDictionary *copyattrs= [NSDictionary
    > dictionaryWithDictionary:sourceAttributes];
    >
    > // [fm changeFileAttributes:copyattrs atPath:@"/Volumes/tigerclone/
    > localtime"];    // THIS BREAKS TARGET OF SOURCE SYMLINK
    > [fm changeFileAttributes:sourceAttributes atPath:@"/Volumes/
    > tigerclone/localtime"];    //THIS IS OK
    >
    > [pool release];
    > return 0;
    > }
    >
    > d
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today