Skip navigation.
 
mlRe: My private problems
FROM : Jean-Daniel Dupas
DATE : Sun Apr 20 11:59:32 2008

Le 20 avr. 08 à 10:46, stephen joseph butler a écrit :

> On Sun, Apr 20, 2008 at 3:19 AM, Gerriet M. Denkmann <<email_removed>
> >
> wrote:
>

>> I need an absolute path.
>>
>> So I do:
>>
>> NSFileManager *fima = [ NSFileManager defaultManager ];
>> NSString *fileType = [ [ fima fileAttributesAtPath: path 
>> traverseLink: NO
>> ]; fileType ];
>> if ( [ fileType isEqualToString: NSFileTypeSymbolicLink ] )
>>      path = [ fima pathContentOfSymbolicLinkAtPath: path ];
>>
>> The problem is: "/tmp" is converted to  "private/tmp" (Note the 
>> missing
>> slash at the start).

>
>
> Well, it's not "converted". In OS X, "/tmp" is a relative symbolic 
> link.
> -[NSFileManager pathContentOfSymbolicLinkAtPath:] calls something like
> readlink(2) behind the scenes. So what you get back is the content 
> of the
> link... which is a relative directory name.
>

>>
>> Short of hardcoding a change from "private" to "/private" -
>> is there some Cocoa (or Carbon or bsd or whatever) way to get "/tmp"
>> converted to  "/private/tmp" (with the leading slash) ?
>> (Same problem exists for /etc and /var).

>
>
> You can do this:
>
> [[path stringByDeletingLastPathComponent]
> stringByAppendingPathComponent:[fima pathContentOfSymbolicLinkAtPath

>>
>> :path]];

>
>
> I think that will work.


Not if the link point to an absolute path.

NSString *absolute = [fima pathContentOfSymbolicLinkAtPath:path];
if (![absolute isAbsolutePath])
   absolute = [absolute stringByAppendingPathComponent:absolute];

Related mailsAuthorDate
mlMy private problems Gerriet M. Denkman… Apr 20, 10:19
mlRe: My private problems stephen joseph but… Apr 20, 10:46
mlRe: My private problems stephen joseph but… Apr 20, 10:51
mlRe: My private problems Jean-Daniel Dupas Apr 20, 11:59
mlRe: My private problems Gerriet M. Denkman… Apr 20, 12:18
mlRe: My private problems Jim Correia Apr 20, 15:15
mlRe: My private problems Jens Alfke Apr 20, 18:10