Professional Web Applications Themes

POSIX path to FSRef - Mac Programming

I need to create an FSRef from a POSIX path to a symbolic link file. The path is something like this: /directory/.../symbolic_link_file I tried FSPathMakeFSSpec() from MoreFilesX but it isn't suitable because it follows the symbolic link in the path, that is, it creates an FSRef to the file pointed to by the symbolic link instead of to the symbolic link file itself. Any ideas on how to best do what I need?...

  1. #1

    Default POSIX path to FSRef

    I need to create an FSRef from a POSIX path to a symbolic link file.
    The path is something like this:

    /directory/.../symbolic_link_file

    I tried FSPathMakeFSSpec() from MoreFilesX but it isn't suitable
    because it follows the symbolic link in the path, that is, it creates
    an FSRef to the file pointed to by the symbolic link instead of to the
    symbolic link file itself. Any ideas on how to best do what I need?
    Tidrix Guest

  2. #2

    Default Re: POSIX path to FSRef

    In article <121120030918401719%come>, Tidrix <come>
    wrote:
     

    I would expect CFURLCreateWithFileSystemSpecification followed by CFURLMakeFSRef
    to work as you expect.

    hth

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  3. #3

    Default Re: POSIX path to FSRef

    In article <mit.edu>,
    Miro Jurisic <org> wrote:
     

    Where are those calls doented? A search on developer.appe.com didn't
    find anything.
    Tidrix Guest

  4. #4

    Default Re: POSIX path to FSRef

    On Wed, 12 Nov 2003, Tidrix wrote:
     
    >
    > Where are those calls doented? A search on developer.appe.com didn't
    > find anything.
    >[/ref]
    I believe Miro actually meant CFURLCreateFromFileSystemRepresentation and
    CFURLGetFSRef, which you will find in the developer web site.

    Fred

    Frederick Guest

  5. #5

    Default Re: POSIX path to FSRef

    In article <121120030949211132%come>, Tidrix
    <come> wrote:
     

    Never mind. I am guessing you meant to say
    CFURLCreateFromFileSystemRepresentation and CFURLGetFSRef. Will try
    those and see what happens.
    Tidrix Guest

  6. #6

    Default Re: POSIX path to FSRef

    In article
    <srcf.societies.cam.ac.uk>,
    Frederick Cheung <DUH.ucam.org> wrote:
     
    > >
    > > Where are those calls doented? A search on developer.appe.com didn't
    > > find anything.
    > >[/ref]
    > I believe Miro actually meant CFURLCreateFromFileSystemRepresentation and
    > CFURLGetFSRef, which you will find in the developer web site.[/ref]

    Er, yeah, that. Thanks & sorry.

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  7. #7

    Default Re: POSIX path to FSRef

    In article <121120031016077488%come>, Tidrix
    <come> wrote:
     

    That didn't do the trick. The symbolic link is still being followed.
    Any other ideas?

    Here is the test code I am using to investigate this. It creates file
    testfile and symbolic link testlink that points to testfile, then
    creates an FSRef to testlink and tries to delete testlink via the
    FSRef. The testfile gets deleted instead.

    int main(
    int argc,
    char **argv
    ){
    CFURLRef urlR;
    Boolean flag;
    FSRef ref;
    char revpath[PATH_MAX];
    OSErr error;

    // make sure these two don't exist
    unlink("testfile");
    unlink("testlink");

    // create target file
    close(creat("testfile", 0777));
    // create symbolic link to target file
    symlink("testfile", "testlink");

    // create FSRef for path "./testlink"
    if (1) {
    urlR = CFURLCreateFromFileSystemRepresentation(0, "./testlink",
    sizeof("./testlink") - 1, false);
    flag = CFURLGetFSRef(urlR, &ref);
    } else {
    error = FSPathMakeRef("./testlink", &ref, false);
    }

    // see what the FSRef is really pointing to
    // I want to see "/Users/.../testlink", but get
    "/Users/.../testfile" instead
    error = FSRefMakePath(&ref, revpath, sizeof(revpath));
    printf("%s\n", revpath);

    // delete whatever the FSRef is really pointing to
    // I need to delete "./testlink" but this deletes "./testfile"
    instead
    error = FSDeleteObject(&ref);

    return 0;
    }
    Tidrix Guest

  8. #8

    Default Re: POSIX path to FSRef

    In article <121120031102465468%come>, Tidrix <come>
    wrote:
     
    >
    > That didn't do the trick. The symbolic link is still being followed.
    > Any other ideas?[/ref]

    I believe you are doomed. You will have to fall back on the BSD readlink() API.

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  9. #9

    Default Re: POSIX path to FSRef

    In article <mit.edu>,
    Miro Jurisic <org> wrote:
     
    > >
    > > That didn't do the trick. The symbolic link is still being followed.
    > > Any other ideas?[/ref]
    >
    > I believe you are doomed. You will have to fall back on the BSD readlink()
    > API.[/ref]

    Yep. As far as I know, FSRefs always follow symlinks. Whether that's a
    feature or a bug is a matter of opinion. :)

    -Eric

    --
    Eric Albert edu
    http://rescomp.stanford.edu/~ejalbert/
    Eric Guest

  10. #10

    Default Re: POSIX path to FSRef

    In article <stanford.edu>, Eric Albert <edu> wrote:
     

    Well, according to some Apple's sample code I just ran into, it is a bug. The code says

    /* Due to a bug in the X File Manager, 2489632, */
    /* FSPathMakeRef doesn't handle symlinks properly. It */
    /* automatically resolves it and returns an FSRef to the */
    /* symlinks target, not the symlink itself. So this is a */
    /* little workaround for it... */

    Lucky me, they offer a workaround. The trick is to create an FSRef to the parent directory of the
    symbolic link file, then use that along with the name of the symbolic link file to create an FSRef
    to the symbolic link file itself. I just tried it and it seems to work.

    The sample code is here for those interested:

    http://developer.apple.com/samplecode/Sample_Code/Files/FSCopyObject/HelloWorldTool.c.htm
    Tidrix Guest

  11. #11

    Default Re: POSIX path to FSRef

    In article <121120032326197055%come>, Tidrix <come>
    wrote:
     
    >
    > Lucky me, they offer a workaround. The trick is to create an FSRef to the
    > parent directory of the symbolic link file, then use that along with the name
    > of the symbolic link file to create an FSRef to the symbolic link file
    > itself. I just tried it and it seems to work.[/ref]

    Thanks!

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

Similar Threads

  1. POSIX::ctermid()
    By Peter Michael in forum PERL Modules
    Replies: 0
    Last Post: January 21st, 11:54 AM
  2. ANNOUNCE: POSIX::RT::Semaphore 0.01
    By Michael Pomraning in forum PERL Modules
    Replies: 0
    Last Post: November 12th, 06:12 PM
  3. POSIX::getchar
    By John Fisher in forum PERL Beginners
    Replies: 2
    Last Post: September 12th, 01:32 PM
  4. Posix queues
    By Rami in forum UNIX Programming
    Replies: 1
    Last Post: July 15th, 04:33 PM
  5. Standard Posix
    By GALVANO in forum Sun Solaris
    Replies: 3
    Last Post: July 13th, 09:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139