Re: Recursive search for files
Re: Recursive search for files
- Subject: Re: Recursive search for files
- From: James Merkel <email@hidden>
- Date: Tue, 24 May 2011 10:42:05 -0700
On May 24, 2011, at 5:15 AM, email@hidden wrote:
James Merkel wrote:
I was trying to come up with a way to prevent the user from
starting at the wrong place. (Putting up an Alert that says you
can't start there). There's a method in the NSFileManager class
called isDeletableFileAtPath. I am thinking that all of those
volumes and higher level directories that I want to avoid are not
deletable. Therefore I could use this as a filter.
You should test that assumption. Test it when logged in as both a
non-admin user and an admin user. You might be surprised.
You also might be surprised if Apple changes anything in permissions,
ACLs, etc. and suddenly you get a whole lot more files than you
planned for. So the whole premise seems a little shaky to me.
I'm not sure why you can't allow the user to start at "the volume
level", if by that you mean the root filesystem whose pathname is /.
If you want to limit depth, give the user a control to limit depth.
If you want to limit number of files, give the user a control for
that. Set reasonable defaults, but otherwise don't artificially
limit what users can do. You don't know how they've setup their
storage, and arbitrary limitations are obnoxious.
If your concern is traversing every mounted volume, there's an easy
way to detect that: it's the device-id in the struct filled in by stat
() (see man page for stat(2)). You don't have to decipher the device-
id, you just have to check for a change in device-id to some value
that differs from the device-id of where you started. For an example
of controlling depth, traversal of volumes, etc. look at the man page
for the 'find' command.
There are also readable attributes (flags and xattrs) that can offer
clues as to whether a directory is hidden from the GUI or not. See
man chflags, and man xattr. The idea here is to not traverse hidden
dirs unless the user says it should. Some of these are also
available as Spotlight metadata, so read up on that, too.
And don't put up any alert that says "You can't start there". Simply
dim or don't show any items that should not be traversed. Few things
are worse than a cycle of "You can't do that" alerts, when the proper
course is to only show things that can be done.
-- GG
Yes, I'm concluding that the best approach is to limit the depth of
the search by a user selectable amount and also to limit the number of
files that can be opened.
As far as starting at the wrong place -- probably 99% of the
directories are the wrong place, so I can't really prevent that and
shouldn't try to prevent it.
Thanks,
Jim Merkel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden