[Libreoffice-commits] core.git: fpicker/source sal/osl

Tor Lillqvist tml at iki.fi
Sun Aug 25 11:14:33 PDT 2013


 fpicker/source/aqua/SalAquaFilePicker.mm |    6 ++++++
 sal/osl/unx/uunxapi.cxx                  |   27 +++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

New commits:
commit 0aeba08d3e0ee611883fc5d415b0c87319ca31e8
Author: Tor Lillqvist <tml at iki.fi>
Date:   Sun Aug 25 20:51:41 2013 +0300

    Fix "Save As" when sandboxed on OS X
    
    Change-Id: Ibe2ea21265a0bb9c4fedcef137626df2a8019116

diff --git a/fpicker/source/aqua/SalAquaFilePicker.mm b/fpicker/source/aqua/SalAquaFilePicker.mm
index ffa9c9c..fbae6e4 100644
--- a/fpicker/source/aqua/SalAquaFilePicker.mm
+++ b/fpicker/source/aqua/SalAquaFilePicker.mm
@@ -340,6 +340,12 @@ uno::Sequence<rtl::OUString> SAL_CALL SalAquaFilePicker::getFiles() throw( uno::
         if (userDefaults != NULL &&
             [url respondsToSelector:@selector(bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:)])
         {
+            // In the case of "Save As" when the user has input a new
+            // file name, this call will return nil, as bookmarks can
+            // (naturally) only be created for existing file system
+            // objects. In that case, code at a much lower level, in
+            // sal, takes care of creating a bookmark when a new file
+            // has been created outside the sandbox.
             NSData *data = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
                          includingResourceValuesForKeys:nil
                                           relativeToURL:nil
diff --git a/sal/osl/unx/uunxapi.cxx b/sal/osl/unx/uunxapi.cxx
index 7eb2ed9..3052538 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;


More information about the Libreoffice-commits mailing list