i'm trying sandbox command-line app written in objective-c.
issue
when app not sandboxed, directory user invoked app using [[nsfilemanager defaultmanager] currentdirectorypath]. however, after sandboxing, app returns current directory /users/{my_account}/library/containers/{bundle_identifier}/data no matter command-line app invoked.
example code
actually, wanna know absolute path files user passed command arguments.
so when, example, invoke command-line app this:
$ pwd /users/my_account/desktop $ ./foo/my_executable subfolder/myfile.txt the following part:
nsurl *url = [nsurl fileurlwithfilesystemrepresentation:argv[1] isdirectory:no relativetourl:nil]; printf("path: %s\n", [[url absoluteurl] filesystemrepresentation]); returns on non-sandboxed app correctly:
path: /users/my_account/desktop/subfolder/myfile.txt but on sandboxed app:
path: /users/my_account/library/containers/bundle_identifier/data/subfolder/myfile.txt this of course incorrect.
question
is there alternative way correct full paths of passed file path arguments in sandboxed command-line app? or impossible , it's better give sandbox app?
solution
finally, found 1 of solution myself.
the environment property in [nsprocessinfo processinfo] has correct current user working directory app sandboxed.
nsdictionary *env = [[nsprocessinfo processinfo] environment]; nsstring *currentpath = env[@"pwd"]; at least, when call command in terminal.app, works. i'm not sure whether pwd exists always.
furthermore, @daij-djan pointed out below, don't have read permission given arguments. however, anyway matter of question once resolved.
(if there know way read file of path passed argument, please tell me answer!)
afaik (i tried while ago, things might have changed -- don't think though)
the paths passed via command line args wouldn't accessible if figured out :/
===> so: thats answer.. pointless im afraid because doesn't work
Comments
Post a Comment