For a prototype that we are doing, we are mounting a disk image in the /private/tmp directory, and then trying to programmatically open a file in the mounted disk image from another user. We are finding that the file is not opened.
We are mounting the disk image with the following script:
#!/bin/sh
/usr/bin/hdiutil attach -readwrite -owners off -mountroot /tmp /Path/To/Disk/Image.dmg
chmod 777 /tmp/Image
Then we are attempting to open the file programmatically with the following:
BOOL value = [[NSWorkspace sharedWorkspace] openFile:[resource valueForKey:@"path"]];
Where [resource valueForKey:@"path"] returns the full path to a file that exists in the mounted disk image:
i.e.
/tmp/Image/some/subdirectory/image.tif
The above command returns YES, and everything works fine, if this is done with the same user that mounted the disk image (executed the above script). From Terminal, you can also execute the following:
open /tmp/Image/some/subdirectory/image.tif
And you can also traverse the path to the file in finder, and double-click to open it.
However if you do the above from a different user, the openFile: command still returns YES, and the default app becomes active (in this case, it is Preview), but the file is never opened.
Executing the "open" command from a terminal gets the same result.
Double clicking on the file in finder also gets the same result.
Even dropping the image onto a running Preview's icon doesn't open it.
However in Finder, when you have the file selected, the image shows up.
And executing the File->Open menu in Preview, and selecting the file DOES open the image.
Once I have opened the file with Preview, all of the above commands now work.
This tells me that the file is valid, and the second user does have permission to open the file.
Any suggestions? Code wise, or mounting the disk image wise to fix this?
Hopefully someone will have a clue.
Pat