Re: checking if directory is writable

2012-01-12 Thread Kyle Sluder
On Tue, Jan 10, 2012 at 1:39 AM, Tony Arnold  wrote:
> Hi Rick,
>
> On 10/01/2012, at 7:49 PM, Rick C. wrote:
>
>> Just looking for confirmation, I can use NSFileManager isWritableAtPath: if 
>> I want to check if a directory can be written to correct?  Or do I have to 
>> use attributesOfItemAtPath:error:?  I don't need to change permissions just 
>> to see if it's writable.  Thanks!
>
> I was of the understanding that Apple's recommendation was just to try the 
> operation you wanted to perform, and handle the error if there is one. This 
> is taken from the NSFileManager header, directly above the isWriteableAtPath: 
> declaration:

Preflighting parent directory permissions is useful so you don't offer
the user the ability to do something you know is impossible. For
example, if a folder is not writeable, you can disable the "Save"
button, as long as you recheck often enough to reenable it when the
permissions change in your favor.

The opposite scenario, where you assume that you have permission to
write a file because of results of a check you made some milliseconds
ago, is the more problematic one. You need to be able to handle that.

--Kyle Sluder
___

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: checking if directory is writable

2012-01-12 Thread Wade Tregaskis
> I was of the understanding that Apple's recommendation was just to try the 
> operation you wanted to perform, and handle the error if there is one. This 
> is taken from the NSFileManager header, directly above the isWriteableAtPath: 
> declaration:
> 
> "The following methods are of limited utility. Attempting to predicate 
> behavior based on the current state of the filesystem or a particular file on 
> the filesystem is encouraging odd behavior in the face of filesystem race 
> conditions. It's far better to attempt an operation (like loading a file or 
> creating a directory) and handle the error gracefully than it is to try to 
> figure out ahead of time whether the operation will succeed."

There's a tendency to create a false dichotomy there, though.  It's true that 
only checking in advance is erroneous, but advanced checks can be useful if 
done appropriately.  For example, when the user first selects a file you could 
sanity check it, and if it looks like something is wrong you can subtly warn 
the user.  The key is to not stop them actually trying - the only true gauge is 
whether the real operation succeeds or not - and not to be too invasive.  For 
example, think about the standard Open dialog which by default disables files 
of unsupported formats.  Or the variant of the same which doesn't disable them, 
but shows a passive warning message within the dialog window if you select one.

It's not something to be considered too lightly, though, because to do a really 
good job of it takes more work than you might think.  For example, if you're 
going to indicate that the user can't seemingly write to the target folder, you 
really should be watching that folder for changes.  When it does become 
readable, you can remove the warning immediately, providing clear feedback to 
the user that a) they've fixed the issue correctly, and b) your app is paying 
attention.  Think about installers that require you to quit certain open apps, 
and compare the ones that make you re-run the installer manually versus those 
that will get immediately underway as soon as the apps are closed.
___

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: checking if directory is writable

2012-01-12 Thread Tony Arnold
Hi Rick,

On 10/01/2012, at 7:49 PM, Rick C. wrote:

> Just looking for confirmation, I can use NSFileManager isWritableAtPath: if I 
> want to check if a directory can be written to correct?  Or do I have to use 
> attributesOfItemAtPath:error:?  I don't need to change permissions just to 
> see if it's writable.  Thanks!

I was of the understanding that Apple's recommendation was just to try the 
operation you wanted to perform, and handle the error if there is one. This is 
taken from the NSFileManager header, directly above the isWriteableAtPath: 
declaration:

"The following methods are of limited utility. Attempting to predicate behavior 
based on the current state of the filesystem or a particular file on the 
filesystem is encouraging odd behavior in the face of filesystem race 
conditions. It's far better to attempt an operation (like loading a file or 
creating a directory) and handle the error gracefully than it is to try to 
figure out ahead of time whether the operation will succeed."

(Sorry for the resend — my original reply only went to Rick, not the entire 
list)

all the best,


Tony




--
Tony Arnold
http://thecocoabots.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: checking if directory is writable

2012-01-10 Thread Rick C.
Great thanks Mike!


On Jan 10, 2012, at 8:03 PM, Mike Abdullah wrote:

> In order of preference, the best technique last:
> 
> 1. -attributesOfItemAtPath:error: —   can only give you some info 
> info on if the file is writable
> 2. -isWritableAtPath: —   takes more into 
> account, but can't be sure. Gives you no details on *why* isn't writable
> 3. Actually try to write the directory
> 
> Always, always use #3 if you can; it's the only way to be sure.
> 
> On 10 Jan 2012, at 08:49, Rick C. wrote:
> 
>> Hi,
>> 
>> Just looking for confirmation, I can use NSFileManager isWritableAtPath: if 
>> I want to check if a directory can be written to correct?  Or do I have to 
>> use attributesOfItemAtPath:error:?  I don't need to change permissions just 
>> to see if it's writable.  Thanks!
>> 
>> rc___
>> 
>> 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/cocoadev%40mikeabdullah.net
>> 
>> This email sent to cocoa...@mikeabdullah.net
> 

___

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: checking if directory is writable

2012-01-10 Thread Mike Abdullah
In order of preference, the best technique last:

1. -attributesOfItemAtPath:error:   —   can only give you some info 
info on if the file is writable
2. -isWritableAtPath:   —   takes more into 
account, but can't be sure. Gives you no details on *why* isn't writable
3. Actually try to write the directory

Always, always use #3 if you can; it's the only way to be sure.

On 10 Jan 2012, at 08:49, Rick C. wrote:

> Hi,
> 
> Just looking for confirmation, I can use NSFileManager isWritableAtPath: if I 
> want to check if a directory can be written to correct?  Or do I have to use 
> attributesOfItemAtPath:error:?  I don't need to change permissions just to 
> see if it's writable.  Thanks!
> 
> rc___
> 
> 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/cocoadev%40mikeabdullah.net
> 
> This email sent to cocoa...@mikeabdullah.net

___

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


checking if directory is writable

2012-01-10 Thread Rick C.
Hi,

Just looking for confirmation, I can use NSFileManager isWritableAtPath: if I 
want to check if a directory can be written to correct?  Or do I have to use 
attributesOfItemAtPath:error:?  I don't need to change permissions just to see 
if it's writable.  Thanks!

rc___

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