Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My OSX Mountain Lion has two users (say, me and otheruser).

When logged in as me, I can look at /Users/otheruser/Public, and drop files into /Users/otheruser/Public/Drop Box, where I can't see them. This works the same with finder and shell (ls "/Users/otheruser/Public/Drop Box" prints ls: .: Permission denied).

However, if the file named identically to the one you're trying to drop into /Users/otheruser/Public/Drop Box is already there, things change:

With Finder: .

With the shell:

$ cp a.txt "/Users/otheruser/Public/Drop Box"

$

The copy is successful, and the file in /Users/otheruser/Public/Drop Box is overridden.

The file is also overridden if the copy is made via filesystem APIs in a program.

What causes the difference in behavior? Is the difference intentional (i.e. did Apple want this)? If it's not intentional, which behavior is correct?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I'd consider the Finder's behavior to be a bug, but the difference is partly intentional (and due to a difference in philosophy). When you use cp to copy one file on top of another, it simply replaces the file without asking (or even noting that it's happened). Normally, the Finder will ask if you're sure that you want to replace it; in this case, it appears that the folder permissions prevent it from doing this successfully, so you get an error instead.

I should probably explain the permissions on the Drop Box folder a bit to clarify what the permissions actually allow and disallow. There are three basic access permissions you can have on a folder: read, write, and "execute" (sometimes called "search"). Read gives you the ability to read the names of the items in a folder, but doesn't actually grant any ability to touch them in any way. Write gives the ability to add, remove, and rename items within the folder. "Execute" gives the ability to "touch" the contents of the folder if you know the filenames.

When you use the Finder to grant someone "read only" access to a folder, it actually grants read and execute; this means they can see the names of the files and folders in it, and interact with them (subject to the permissions on the items themselves). If you actually granted read access without execute, they could see the filenames but not anything else about the files (i.e. ls on such a folder would work, but ls -l will get permissions errors when it tries to get the files' properties).

If you grant someone execute access to a folder (and nothing else), that means they can work with the files in that folder if they know (or guess) the file names. ls /path/to/exec-folder will fail, but ls -l /path/to/exec-folder/filename will work if a file by that name exists.

What the Drop Box folder has is write and execute (but no read access) for everyone but the owner. This means that in /Users/otheruser/Public/Drop Box, you can add files, list their properties (if you know their names), and even move, rename, or delete them (again, if you know their names). The Finder can't take advantage of this, because it really wants to be able to look around at the contents of the folder; since it can't do this, it gives up on interacting with the Drop Box. Many command line tools are much more precise in what they do, and hence never even notice they're working in an unreadable folder:

$ echo "This is the file's contents." >somefile.txt
$ cp somefile.txt /Users/otheruser/Public/Drop\ Box
$ ls /Users/otheruser/Public/Drop\ Box    # Unable to look around
ls: Drop Box: Permission denied
$ ls -l /Users/otheruser/Public/Drop\ Box/somefile.txt    # But if you know the filename...
-rw-r--r--+ 1 gordon  staff     29 Mar 26 21:35 /Users/otheruser/Public/Drop Box/somefile.txt
$ more /Users/otheruser/Public/Drop\ Box/somefile.txt
This is the file's contents.
$ mv /Users/otheruser/Public/Drop\ Box/somefile.txt /Users/otheruser/Public/Drop\ Box/newname.txt
$ rm /Users/otheruser/Public/Drop\ Box/newname.txt
$
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.