Re: IsReadableFileAtPath

2010-03-08 Thread gMail.com
Hi, thanks to all of you.
After some days trynign and thinking, I have used lstat to check the
filePermissions because I need to check thousands files per session.
However I realized that Permissions and isReadableFile or isWritableFile or
isDeletableFile are two different things, so please may you tell me whether
my methods here below are right or wrong? Short version:

IsReadableFile:filePath
 cPath = [mManager fileSystemRepresentationWithPath:filePath];
lstat(cPath, sb);
return ((sb.st_mode  S_IRUSR) != 0);

IsWritableFile:filePath
//I check here the ParentFolder of the filePath
parentFolder = [filePath stringByDeletingLastPathComponent];
cPath = [mManager fileSystemRepresentationWithPath:parentFolder];
lstat(cPath, sb);
return ((sb.st_mode  (S_IWUSR | S_IXUSR)) != 0);

IsDeletableFile:filePath
the same as IsWritableFile:filePath above

Will these methods work on any volume mounted on my desktop?
(e.g. Local volume, remote volume, disk image volume, on webdav, smb, ftp,
afp, hfs, on remote win disk...)

Thanks
Leo


 Da: Kevin Perry kpe...@apple.com
 Data: Mon, 1 Mar 2010 11:37:06 -0800
 A: gMail.com mac.iphone@gmail.com
 Cc: cocoa-dev@lists.apple.com
 Oggetto: Re: IsReadableFileAtPath
 
 
 -Kevin
 
 On Mar 1, 2010, at 11:20 AM, gMail.com wrote:
 
 Hi,
 I need to check whether a file or a symlink could be really copied.
 I have just seen that the Cocoa API isReadableFileAtPath traverses the
 symlink, so, in case the target file is not readable, my app doesn't copy
 the symlink, while the Finder can properly do. So my app does wrong.
 
 The question is:
 How can I understand whether a file or symlink can really be copied?
 I have seen that isReadableFileAtPath uses the C command access which
 indeed traverses the symlink. So I cannot use it. So, any idea?
 And I wouldn't use the Carbon APIs because I need to compile for 64 bit.
 Thank you.
 
 Leonardo
 
 
 ___
 
 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/kperry%40apple.com
 
 This email sent to kpe...@apple.com
 


___

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 arch...@mail-archive.com


Re: IsReadableFileAtPath

2010-03-08 Thread Jeremy Pereira

On 8 Mar 2010, at 11:32, gMail.com wrote:

 Hi, thanks to all of you.
 After some days trynign and thinking, I have used lstat to check the
 filePermissions because I need to check thousands files per session.
 However I realized that Permissions and isReadableFile or isWritableFile or
 isDeletableFile are two different things, so please may you tell me whether
 my methods here below are right or wrong? Short version:

That depends on the semantics you want for isReadableFile: and isWriteableFile: 
 The code as written checks if the owner of the file can read or write it.  
However, you probably want to know if the currently running process can read or 
write it which may have a different answer if the owner of the process is not 
the same as the owner of the file.

isDeleteableFile: is wrong.  You need to check whether you have write access to 
the directory containing the file.  See below script:

monica:~ jeremyp$ mkdir foo
monica:~ jeremyp$ cd foo
monica:foo jeremyp$ touch foo
monica:foo jeremyp$ chmod -w .
monica:foo jeremyp$ ls -la
total 0
dr-xr-xr-x3 jeremyp  staff   102  8 Mar 11:49 .
drwx--+ 115 jeremyp  staff  3910  8 Mar 11:49 ..
-rw-r--r--1 jeremyp  staff 0  8 Mar 11:49 foo
monica:foo jeremyp$ rm foo
rm: foo: Permission denied
  


 
 IsReadableFile:filePath
 cPath = [mManager fileSystemRepresentationWithPath:filePath];
lstat(cPath, sb);
return ((sb.st_mode  S_IRUSR) != 0);
 
 IsWritableFile:filePath
//I check here the ParentFolder of the filePath
parentFolder = [filePath stringByDeletingLastPathComponent];
cPath = [mManager fileSystemRepresentationWithPath:parentFolder];
lstat(cPath, sb);
return ((sb.st_mode  (S_IWUSR | S_IXUSR)) != 0);
 
 IsDeletableFile:filePath
the same as IsWritableFile:filePath above
 
 Will these methods work on any volume mounted on my desktop?
 (e.g. Local volume, remote volume, disk image volume, on webdav, smb, ftp,
 afp, hfs, on remote win disk...)
 
 Thanks
 Leo
 
 
 Da: Kevin Perry kpe...@apple.com
 Data: Mon, 1 Mar 2010 11:37:06 -0800
 A: gMail.com mac.iphone@gmail.com
 Cc: cocoa-dev@lists.apple.com
 Oggetto: Re: IsReadableFileAtPath
 
 
 -Kevin
 
 On Mar 1, 2010, at 11:20 AM, gMail.com wrote:
 
 Hi,
 I need to check whether a file or a symlink could be really copied.
 I have just seen that the Cocoa API isReadableFileAtPath traverses the
 symlink, so, in case the target file is not readable, my app doesn't copy
 the symlink, while the Finder can properly do. So my app does wrong.
 
 The question is:
 How can I understand whether a file or symlink can really be copied?
 I have seen that isReadableFileAtPath uses the C command access which
 indeed traverses the symlink. So I cannot use it. So, any idea?
 And I wouldn't use the Carbon APIs because I need to compile for 64 bit.
 Thank you.
 
 Leonardo
 
 
 ___
 
 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/kperry%40apple.com
 
 This email sent to kpe...@apple.com
 
 
 
 ___
 
 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/adc%40jeremyp.net
 
 This email sent to a...@jeremyp.net


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
___

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 arch...@mail-archive.com


IsReadableFileAtPath

2010-03-01 Thread gMail.com
Hi,
I need to check whether a file or a symlink could be really copied.
I have just seen that the Cocoa API isReadableFileAtPath traverses the
symlink, so, in case the target file is not readable, my app doesn't copy
the symlink, while the Finder can properly do. So my app does wrong.

The question is:
How can I understand whether a file or symlink can really be copied?
I have seen that isReadableFileAtPath uses the C command access which
indeed traverses the symlink. So I cannot use it. So, any idea?
And I wouldn't use the Carbon APIs because I need to compile for 64 bit.
Thank you.

Leonardo


___

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 arch...@mail-archive.com


Re: IsReadableFileAtPath

2010-03-01 Thread Nick Zitzmann

On Mar 1, 2010, at 12:20 PM, gMail.com wrote:

 I need to check whether a file or a symlink could be really copied.
 I have just seen that the Cocoa API isReadableFileAtPath traverses the
 symlink, so, in case the target file is not readable, my app doesn't copy
 the symlink, while the Finder can properly do. So my app does wrong.
 
 The question is:
 How can I understand whether a file or symlink can really be copied?

Maybe lstat() would better suit your needs?

Nick Zitzmann
http://www.chronosnet.com/

___

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 arch...@mail-archive.com


Re: IsReadableFileAtPath

2010-03-01 Thread Jens Alfke

On Mar 1, 2010, at 11:20 AM, gMail.com wrote:

 I have just seen that the Cocoa API isReadableFileAtPath traverses the
 symlink, so, in case the target file is not readable, my app doesn't copy
 the symlink, while the Finder can properly do. So my app does wrong.

-isReadableFileAtPath is just a convenience. If you don't want to traverse 
symlinks, call -fileAttributesAtPath:traverseLink: and use NO for the second 
parameter.

 How can I understand whether a file or symlink can really be copied?

You can't preflight file operations with 100% accuracy, because there's always 
a race condition — the file's permissions could be modified in between checking 
permission and doing the actual copy. You should still do the preflighting if 
it helps the user experience (by disabling a button, for example); but always 
be prepared to handle errors from the actual operation itself. 

If you don't need preflighting for your UI, just skip it. In other words, don't 
do the following:
if (fileIsCopyable(file))
copyFile(file);
Instead just call copyFile() and handle any error it returns.

 And I wouldn't use the Carbon APIs because I need to compile for 64 bit.

The Carbon File Manager API is available in 64-bit, and it's perfectly 
appropriate to use it in Cocoa apps. It's only a subset of Carbon High-Level 
Toolbox APIs that aren't available in 64-bit (and you wouldn't be using those 
in a Cocoa app anyway.)

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

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


Re: IsReadableFileAtPath

2010-03-01 Thread Kevin Perry
In general, this kind of check-then-do pattern opens the door for file system 
race conditions. The documentation for this method (and related methods) has a 
little more information about this in the Note section.

Could you just try to copy the symlink and then deal with any errors that 
result?

-Kevin

On Mar 1, 2010, at 11:20 AM, gMail.com wrote:

 Hi,
 I need to check whether a file or a symlink could be really copied.
 I have just seen that the Cocoa API isReadableFileAtPath traverses the
 symlink, so, in case the target file is not readable, my app doesn't copy
 the symlink, while the Finder can properly do. So my app does wrong.
 
 The question is:
 How can I understand whether a file or symlink can really be copied?
 I have seen that isReadableFileAtPath uses the C command access which
 indeed traverses the symlink. So I cannot use it. So, any idea?
 And I wouldn't use the Carbon APIs because I need to compile for 64 bit.
 Thank you.
 
 Leonardo
 
 
 ___
 
 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/kperry%40apple.com
 
 This email sent to kpe...@apple.com

___

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 arch...@mail-archive.com


Re: IsReadableFileAtPath

2010-03-01 Thread Charles Srstka
On Mar 1, 2010, at 3:24 PM, Jens Alfke wrote:

 -isReadableFileAtPath is just a convenience. If you don't want to traverse 
 symlinks, call -fileAttributesAtPath:traverseLink: and use NO for the second 
 parameter.

Unfortunately, fileAttributesAtPath:traverseLink: is deprecated. The 
replacement given is attributesOfItemAtPath:error:, which doesn’t traverse 
symlinks. However, the documentation claims that this behavior is not 
guaranteed, and may change in a future version of OS X. Sadly, there does not 
seem to be a non-deprecated replacement for fileAttributesAtPath:traverseLink: 
which has guaranteed behavior.

The best thing to do is probably to use POSIX calls such as lstat().

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

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