Another filesystem mystery

  •   Boy, filtering files for the open panel is turning out to be a good
    deal harder than I had expected.  :->
      I've just bumped into the problem that
    -stringByResolvingSymlinksInPath doesn't resolve alias files, and that
    such alias files then say they are files even if they point to
    directories.  Apparently I need to resolve such aliases by hand.  I've
    just logged a bug that Cocoa ought to make this issue more or less
    completely invisible, at least when -stringByResolvingSymlinksInPath is
    used.  Sigh.
      So after an hour or so searching the archives for every relevant
    keyword I could think of, I found only one small snippet of actual
    example code that is written to handle this, and there are big caveats
    attached to it that it's untested, etc.  Does anybody have known good
    code they would be willing to share?  I'm hoping for an NSString
    category like -stringByResolvingSymlinksAndAliasesInPath, but anything I
    can massage into that form myself would be welcome.
      Please reply directly to me, I'll post the best code I get (or
    write :->) to the list later.  Thanks!

    Ben Haller
    Stick Software
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Ben,

    (I know - I just wrote you on this, but since it seems to come up now
    and again...)

    On Monday, February 25, 2002, at 09:37 PM, <bhaller...> wrote:

    > I've just bumped into the problem that
    > -stringByResolvingSymlinksInPath doesn't resolve alias files, and that
    > such alias files then say they are files even if they point to
    > directories.  Apparently I need to resolve such aliases by hand.  I've
    > just logged a bug that Cocoa ought to make this issue more or less
    > completely invisible, at least when -stringByResolvingSymlinksInPath is
    > used.  Sigh.

    This is a known issue, and its being addressed for one of those "future
    release" things.

    .chris

    --
    Chris Parker <ctp...>
    Cocoa Frameworks Engineer
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Tuesday, February 26, 2002, at 05:37 AM, <bhaller...> wrote:

    > I've just bumped into the problem that
    > -stringByResolvingSymlinksInPath doesn't resolve alias files, and that
    > such alias files then say they are files even if they point to
    > directories.  Apparently I need to resolve such aliases by hand.  I've
    > just logged a bug that Cocoa ought to make this issue more or less
    > completely invisible, at least when -stringByResolvingSymlinksInPath is
    > used.  Sigh.

    http://bdistributed.com/Projects/BDAlias/

      -- Finlay
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Tuesday, February 26, 2002, at 11:38  AM, Finlay Dobbie wrote:

    > On Tuesday, February 26, 2002, at 05:37 AM, <bhaller...> wrote:
    >
    >> I've just bumped into the problem that
    >> -stringByResolvingSymlinksInPath doesn't resolve alias files, and that
    >> such alias files then say they are files even if they point to
    >> directories.  Apparently I need to resolve such aliases by hand.  I've
    >> just logged a bug that Cocoa ought to make this issue more or less
    >> completely invisible, at least when -stringByResolvingSymlinksInPath
    >> is used.  Sigh.
    >
    > http://bdistributed.com/Projects/BDAlias/

    Well, that gets you about halfway there. BDAlias is useful for using
    alias *records*, but it won't directly resolve the Finder's alias
    *files* for you.  (I think the fact that the Finder alias files contain
    alias records internally is considered an implementation detail, subject
    to change.)

    You can use FSResolveAliasFile() (or related functions) in Carbon to
    resolve alias files.  Note that there are various complications with
    this, if the alias points to something on a server that needs to be
    mounted (which might require asking for a password), and so on.  I
    haven't yet seen a Cocoa class to do this, and I agree that Apple should
    be the ones providing it.

    (BDAlias will at least give you a good example of using the Carbon Alias
    Manager, though.)

    --
    Kurt Revis
    <krevis...>
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  •   Well, some followup to my question already went over the list, but I
    thought it might be useful for somebody to see the code I ended up
    with.  It's a combination of code from several replies, together with my
    own innovations.  :->  It seems to work nicely for me, although I'll
    admit I haven't tested cases where aliases point onto unmounted volumes,
    etc.
      If any sort of failure occurs, it falls back on
    -stringByResolvingSymlinksInPath's result.  This is important, as
    otherwise this method would return nil for any path that did not
    actually exist on the filesystem.  It's an interesting question what
    this method will do with a path that does not exist, but that starts
    with a path that *does* exist but contains an alias.  I believe it will
    return the full path without resolving the alias in the middle, but I
    haven't tried it.  Beyond a certain point, I can't bring myself to
    care.  :->
      I look forward to the promised fix for these problems in Foundation!

    @interface NSString (CocoaExtra)

    - (NSString *)stringByResolvingSymlinksAndAliasesInPath;

    @end

    @implementation NSString (CocoaExtra)

    - (NSString *)stringByResolvingSymlinksAndAliasesInPath
    {
    NSString *path = [self stringByResolvingSymlinksInPath];
    NSString *outString = nil;
    CFURLRef url = NULL;
    Boolean success = false;
    FSRef aliasRef;
    OSErr anErr = noErr;
    Boolean targetIsFolder;
    Boolean wasAliased;

    url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
              (CFStringRef)path,
              kCFURLPOSIXPathStyle,
              false);

    if (url == NULL)
      return path;

    success = CFURLGetFSRef(url, &aliasRef);

    CFRelease(url);

    if (success == false)
      return path;

    anErr = FSResolveAliasFileWithMountFlags(&aliasRef, true,
    &targetIsFolder,
      &wasAliased, kARMMountVol | kARMNoUI | kARMMultVols | kARMSearch);

    if (anErr != noErr)
      return path;

    url = CFURLCreateFromFSRef(kCFAllocatorDefault, &aliasRef);

    if (url == NULL)
      return path;

    outString = (NSString *)CFURLCopyFileSystemPath(url,
    kCFURLPOSIXPathStyle);

    CFRelease(url);

    return (outString ? [outString autorelease] : path);
    }

    @end

      I hope this is useful to somebody...

    Ben Haller
    Stick Software
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month february 2002 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      
Go to today