Re: My private problems

2008-04-20 Thread Jens Alfke

To resolve symlinks in paths, call
-[NSString stringByResolvingSymlinksInPath:]

This is declared in NSPathUtilities.h, which makes it easy to  
overlook...


—Jens

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Re: My private problems

2008-04-20 Thread Jim Correia

On Apr 20, 2008, at 6:18 AM, Gerriet M. Denkmann wrote:

So - just for fun - how can I convert the symbolic link "/tmp" into  
an absolute pathname?

stringByResolvingSymlinksInPath leaves it unchanged.


That the /private prefix is removed is documented behavior.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: My private problems

2008-04-20 Thread Gerriet M. Denkmann


On 20 Apr 2008, at 10:53, [EMAIL PROTECTED] wrote:


On Sun, Apr 20, 2008 at 3:46 AM, stephen joseph butler <
[EMAIL PROTECTED]> wrote:


You can do this:

[[path stringByDeletingLastPathComponent]
stringByAppendingPathComponent:[fima pathContentOfSymbolicLinkAtPath


:path]];



I think that will work.

Actually, that won't. You have to write a special case still to  
handle if

the symbolic link is absolute.

What are you trying to accomplish, exactly?


I want to call statfs(), and had previously concluded that it does  
not follow symbolic links. It seems that on 10.4.11 this is no longer  
true.


So - just for fun - how can I convert the symbolic link "/tmp" into  
an absolute pathname?

stringByResolvingSymlinksInPath leaves it unchanged.
pathContentOfSymbolicLinkAtPath returns a relative path.
What to do?


Kind regards,

Gerriet.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: My private problems

2008-04-20 Thread Jean-Daniel Dupas


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

On Sun, Apr 20, 2008 at 3:19 AM, Gerriet M. Denkmann <[EMAIL PROTECTED] 
>

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];



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: My private problems

2008-04-20 Thread stephen joseph butler
On Sun, Apr 20, 2008 at 3:46 AM, stephen joseph butler <
[EMAIL PROTECTED]> wrote:

> You can do this:
>
> [[path stringByDeletingLastPathComponent]
> stringByAppendingPathComponent:[fima pathContentOfSymbolicLinkAtPath
> >
> > :path]];
>
>
> I think that will work.
>


Actually, that won't. You have to write a special case still to handle if
the symbolic link is absolute.

What are you trying to accomplish, exactly?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: My private problems

2008-04-20 Thread stephen joseph butler
On Sun, Apr 20, 2008 at 3:19 AM, Gerriet M. Denkmann <[EMAIL PROTECTED]>
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.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]