Re: How to ResolvingSymlinksInPath ?

2016-11-04 Thread Charles Srstka
> On Nov 3, 2016, at 10:39 PM, Ken Thomases  wrote:
> 
> On Nov 3, 2016, at 10:08 PM, Gerriet M. Denkmann  > wrote:
>> 
>> URLByResolvingAliasFileAtURL does almost the same, has no special behaviour 
>> with “/private”, and even can resolve an alias.
>> But: only when this alias is the final component of a path.
>> I.e. /path/aliasToFoo will be resolved to /path/foo; but  
>> /path/aliasToFoo/someFile will not.
> 
> Paths "through" alias files make no sense.  Nothing else in the system will 
> resolve an alias there, so nothing will ever produce such a path.  If your 
> code is producing such paths, you should fix it, because nothing else will be 
> able to process them.

Oh, and it isn’t quite true that *nothing* else on the system will be able to 
process paths through an alias; old-style HFS paths separated by the ‘:’ 
character do resolve through aliases if they go through the old-style Carbon 
file manager. You can test this yourself by writing an AppleScript like this:

tell application "Finder"
get file “Macintosh HD:path:to:someAlias:someFile.txt"
end tell

Replace ‘Macintosh HD’ with your boot disk’s name, and the rest by the 
appropriate filenames, and you should get a valid reference to the file.

Charles
___

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

This email sent to arch...@mail-archive.com

Re: How to ResolvingSymlinksInPath ?

2016-11-04 Thread Charles Srstka
> On Nov 3, 2016, at 10:39 PM, Ken Thomases  wrote:
> 
> On Nov 3, 2016, at 10:08 PM, Gerriet M. Denkmann  > wrote:
>> 
>> URLByResolvingAliasFileAtURL does almost the same, has no special behaviour 
>> with “/private”, and even can resolve an alias.
>> But: only when this alias is the final component of a path.
>> I.e. /path/aliasToFoo will be resolved to /path/foo; but  
>> /path/aliasToFoo/someFile will not.
> 
> Paths "through" alias files make no sense.  Nothing else in the system will 
> resolve an alias there, so nothing will ever produce such a path.  If your 
> code is producing such paths, you should fix it, because nothing else will be 
> able to process them.
> 
>>> On 3 Nov 2016, at 23:05, Jens Alfke >> > wrote:
>>> 
>>> (I’m not sure why you need to remove all symlinks, but I’ll assume you have 
>>> a good reason…)
>> 
>> I don’t know whether the reason is good, but I want to compare stuff 
>> returned from FSEventStreams.
> 
> You should construct NSURL objects from the two paths, use 
> -getResourceValue:forKey:error: with the key NSURLFileResourceIdentifierKey 
> to get the resource ID for each, and then use [resourceID1 
> isEqual:resourceID2] to determine if the two paths refer to the same 
> file-system object.

One thing that may be worth mentioning is that file resource identifier keys 
apparently use the inode to compare the files, which means that comparing the 
file resource identifiers of two hard links that point to the same inode will 
return true. This is great if that’s what you want, but if you need to 
determine that they represent the same catalog node rather than the same 
underlying data, it may not be appropriate.

Charles

___

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

This email sent to arch...@mail-archive.com

Re: How to ResolvingSymlinksInPath ?

2016-11-03 Thread Gerriet M. Denkmann

> On 4 Nov 2016, at 10:39, Ken Thomases  wrote:
> 
> On Nov 3, 2016, at 10:08 PM, Gerriet M. Denkmann  wrote:
>> 
>> URLByResolvingAliasFileAtURL does almost the same, has no special behaviour 
>> with “/private”, and even can resolve an alias.
>> But: only when this alias is the final component of a path.
>> I.e. /path/aliasToFoo will be resolved to /path/foo; but  
>> /path/aliasToFoo/someFile will not.
> 
> Paths "through" alias files make no sense.  Nothing else in the system will 
> resolve an alias there, so nothing will ever produce such a path.  

I typed in some OpenPanel: “/tmp/a1 alias/a2/aFile” and 
“/private/tmp/a1/a2/aFile” was opened without any problems.
But this may well be the only place where this works.

My app just needs the same functionality.


> If your code is producing such paths, you should fix it, because nothing else 
> will be able to process them.
No, it does not. It just wants to read files.


> You should construct NSURL objects from the two paths, use 
> -getResourceValue:forKey:error: with the key NSURLFileResourceIdentifierKey 
> to get the resource ID for each, and then use [resourceID1 
> isEqual:resourceID2] to determine if the two paths refer to the same 
> file-system object.

What I need is: 
goodPath = [ pathFromFSEventStream hasPrefix: somePath ]

pathFromFSEventStream might no longer exist (FSEventStream notifying me of it’s 
demise). I would still consider it a “ goodPath” if it has the right prefix.

Even if it does exist, I would need something like:
[ fileResourceIdentifierFromFSEventStream isEqualOrDescendentOf: 
someFileResourceIdentifier ].

This might become rather more involved than a simple hasPrefix.


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

This email sent to arch...@mail-archive.com

Re: How to ResolvingSymlinksInPath ?

2016-11-03 Thread Ken Thomases
On Nov 3, 2016, at 10:08 PM, Gerriet M. Denkmann  wrote:
> 
> URLByResolvingAliasFileAtURL does almost the same, has no special behaviour 
> with “/private”, and even can resolve an alias.
> But: only when this alias is the final component of a path.
> I.e. /path/aliasToFoo will be resolved to /path/foo; but  
> /path/aliasToFoo/someFile will not.

Paths "through" alias files make no sense.  Nothing else in the system will 
resolve an alias there, so nothing will ever produce such a path.  If your code 
is producing such paths, you should fix it, because nothing else will be able 
to process them.

>> On 3 Nov 2016, at 23:05, Jens Alfke  wrote:
>> 
>> (I’m not sure why you need to remove all symlinks, but I’ll assume you have 
>> a good reason…)
> 
> I don’t know whether the reason is good, but I want to compare stuff returned 
> from FSEventStreams.

You should construct NSURL objects from the two paths, use 
-getResourceValue:forKey:error: with the key NSURLFileResourceIdentifierKey to 
get the resource ID for each, and then use [resourceID1 isEqual:resourceID2] to 
determine if the two paths refer to the same file-system object.

Regards,
Ken


___

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

This email sent to arch...@mail-archive.com

Re: How to ResolvingSymlinksInPath ?

2016-11-03 Thread Gerriet M. Denkmann

> On 3 Nov 2016, at 23:05, Jens Alfke  wrote:
> 
> The docs for -stringByResolvingSymlinksInPath say that “for absolute paths, 
> all symbolic links are guaranteed to be removed.” If it doesn’t actually do 
> that, then there’s either a bug in the implementation or a bug in the docs; 
> either way, you should file a Radar.

I seem to be remember that the special handling of “/private” paths (not parts) 
was documented once.
Maybe there was even a compelling reason given for this quirk.

URLByResolvingAliasFileAtURL does almost the same, has no special behaviour 
with “/private”, and even can resolve an alias.
But: only when this alias is the final component of a path.
I.e. /path/aliasToFoo will be resolved to /path/foo; but  
/path/aliasToFoo/someFile will not.

Symlinks are resolved in any position.

> 
> (I’m not sure why you need to remove all symlinks, but I’ll assume you have a 
> good reason…)


I don’t know whether the reason is good, but I want to compare stuff returned 
from FSEventStreams.


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

This email sent to arch...@mail-archive.com

Re: How to ResolvingSymlinksInPath ?

2016-11-03 Thread Jens Alfke
The docs for -stringByResolvingSymlinksInPath say that “for absolute paths, all 
symbolic links are guaranteed to be removed.” If it doesn’t actually do that, 
then there's either a bug in the implementation or a bug in the docs; either 
way, you should file a Radar.

(I’m not sure why you need to remove all symlinks, but I’ll assume you have a 
good reason…)

—Jens
___

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

This email sent to arch...@mail-archive.com

Re: How to ResolvingSymlinksInPath ?

2016-11-03 Thread Gerriet M. Denkmann

> On 2 Nov 2016, at 20:40, Stephane Sudre  wrote:
> 
> https://www.cocoawithlove.com/2010/02/resolving-path-containing-mixture-of.html

I finally came up with this (all error checking removed):

- (NSString *)resolvedPathFor: (NSString *)rawPath
{
NSURL *url = [ NSURL fileURLWithPath: rawPath ];
NSArray *pathComponents = url.pathComponents;
NSError *outError;
NSURL *urlIter = nil;
for ( NSString *pathComponent in pathComponents )
{
NSURL *uTemp = urlIter == nil ? [ NSURL fileURLWithPath: 
pathComponent ] : 
[ 
urlIter URLByAppendingPathComponent: pathComponent ];
urlIter = [ NSURL URLByResolvingAliasFileAtURL: uTemp  options: 
0  error:  ];  
BOOL ok = [ urlIter checkResourceIsReachableAndReturnError: 
 ];
};

return urlIter.path;
}

This should handle /tmp, aliases, symlinks and any combination thereof.

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

This email sent to arch...@mail-archive.com

How to ResolvingSymlinksInPath ?

2016-11-02 Thread Gerriet M. Denkmann
I want to remove all symlinks from a path.

stringByResolvingSymlinksInPath does NOT do this (e.g. it does not change: /tmp 
to: /private/tmp).

Currently I am using:

int fd = open( filename, O_EVTONLY );
fcntl( fd, F_GETPATH, buffer );
close(fd);

Is there something better or more suitable?
macOS 12.1.

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

This email sent to arch...@mail-archive.com