summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2013-08-25 20:51:41 +0300
committerTor Lillqvist <tml@iki.fi>2013-08-25 21:14:08 +0300
commit0aeba08d3e0ee611883fc5d415b0c87319ca31e8 (patch)
tree59a9f55cd138646ea9ee1a81514723a19d6004e9 /sal
parent21fbeebc8e9cd264e42e76022607851391ce3868 (diff)
Fix "Save As" when sandboxed on OS X
Change-Id: Ibe2ea21265a0bb9c4fedcef137626df2a8019116
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/uunxapi.cxx27
1 files changed, 27 insertions, 0 deletions
diff --git a/sal/osl/unx/uunxapi.cxx b/sal/osl/unx/uunxapi.cxx
index 7eb2ed910467..3052538f484f 100644
--- a/sal/osl/unx/uunxapi.cxx
+++ b/sal/osl/unx/uunxapi.cxx
@@ -262,6 +262,33 @@ int open_c(const char *cpPath, int oflag, int mode)
int result = open(cpPath, oflag, mode);
+#if defined(MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 && HAVE_FEATURE_MACOSX_SANDBOX
+ if (result != -1 && (oflag & O_CREAT) && (oflag & O_EXCL))
+ {
+ // A new file was created. Check if it is outside the sandbox.
+ // (In that case it must be one the user selected as export or
+ // save destination in a file dialog, otherwise we wouldn't
+ // have been able to crete it.) Create and store a security
+ // scoped bookmark for it so that we can access the file in
+ // the future, too. (For the "Recent Files" functionality.)
+ const char *sandbox = [NSHomeDirectory() UTF8String];
+ if (!(memcmp(sandbox, cpPath, strlen(sandbox)) == 0 &&
+ cpPath[strlen(sandbox)] == '/'))
+ {
+ NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:cpPath]];
+ NSData *data = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
+ includingResourceValuesForKeys:nil
+ relativeToURL:nil
+ error:nil];
+ if (data != NULL)
+ {
+ [userDefaults setObject:data
+ forKey:[@"bookmarkFor:" stringByAppendingString:[url absoluteString]]];
+ }
+ }
+ }
+#endif
+
done_accessing_file_path(cpPath, state);
return result;