]> source.dussan.org Git - nextcloud-server.git/commitdiff
always use oc filesystem for rename operation
authorBjoern Schiessle <schiessle@owncloud.com>
Mon, 23 Jun 2014 14:14:52 +0000 (16:14 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Wed, 25 Jun 2014 10:27:30 +0000 (12:27 +0200)
apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/helper.php

index df101acab9d9645ab23ae78e4bd44aec59685c96..3625d5a09f3ac3de581081547e32bcbe75718649 100644 (file)
@@ -464,61 +464,44 @@ class Hooks {
                        $newShareKeyPath = $ownerNew . '/files_encryption/share-keys/' . $pathNew;\r
                }\r
 \r
-               // add key ext if this is not an folder\r
+               // create new key folders if it doesn't exists\r
+               if (!$view->file_exists(dirname($newShareKeyPath))) {\r
+                               $view->mkdir(dirname($newShareKeyPath));\r
+               }\r
+               if (!$view->file_exists(dirname($newKeyfilePath))) {\r
+                       $view->mkdir(dirname($newKeyfilePath));\r
+               }\r
+\r
+               // handle share keys\r
                if (!$view->is_dir($oldKeyfilePath)) {\r
                        $oldKeyfilePath .= '.key';\r
                        $newKeyfilePath .= '.key';\r
 \r
                        // handle share-keys\r
-                       $localKeyPath = $view->getLocalFile($oldShareKeyPath);\r
-                       $escapedPath = Helper::escapeGlobPattern($localKeyPath);\r
-                       $matches = glob($escapedPath . '*.shareKey');\r
+                       $matches = Helper::findShareKeys($oldShareKeyPath, $view);\r
                        foreach ($matches as $src) {\r
                                $dst = \OC\Files\Filesystem::normalizePath(str_replace($pathOld, $pathNew, $src));\r
-\r
-                               // create destination folder if not exists\r
-                               if (!file_exists(dirname($dst))) {\r
-                                       mkdir(dirname($dst), 0750, true);\r
-                               }\r
-\r
-                               rename($src, $dst);\r
+                               $view->rename($src, $dst);\r
                        }\r
 \r
                } else {\r
                        // handle share-keys folders\r
-\r
-                       // create destination folder if not exists\r
-                       if (!$view->file_exists(dirname($newShareKeyPath))) {\r
-                               mkdir($view->getLocalFile($newShareKeyPath), 0750, true);\r
-                       }\r
-\r
                        $view->rename($oldShareKeyPath, $newShareKeyPath);\r
                }\r
 \r
                // Rename keyfile so it isn't orphaned\r
                if ($view->file_exists($oldKeyfilePath)) {\r
-\r
-                       // create destination folder if not exists\r
-                       if (!$view->file_exists(dirname($newKeyfilePath))) {\r
-                               mkdir(dirname($view->getLocalFile($newKeyfilePath)), 0750, true);\r
-                       }\r
-\r
                        $view->rename($oldKeyfilePath, $newKeyfilePath);\r
                }\r
 \r
-               // build the path to the file\r
-               $newPath = '/' . $ownerNew . '/files' . $pathNew;\r
+               // update share keys\r
+               $sharingEnabled = \OCP\Share::isEnabled();\r
 \r
-               if ($util->fixFileSize($newPath)) {\r
-                       // get sharing app state\r
-                       $sharingEnabled = \OCP\Share::isEnabled();\r
-\r
-                       // get users\r
-                       $usersSharing = $util->getSharingUsersArray($sharingEnabled, $pathNew);\r
+               // get users\r
+               $usersSharing = $util->getSharingUsersArray($sharingEnabled, $pathNew);\r
 \r
-                       // update sharing-keys\r
-                       $util->setSharedFileKeyfiles($session, $usersSharing, $pathNew);\r
-               }\r
+               // update sharing-keys\r
+               $util->setSharedFileKeyfiles($session, $usersSharing, $pathNew);\r
 \r
                \OC_FileProxy::$enabled = $proxyStatus;\r
        }\r
index 2684bf7be3377a45d6196c3e81d81cf58b522c32..c6f18602b2b945b9e6d16615a2e9aa3e62c8810b 100755 (executable)
@@ -438,6 +438,30 @@ class Helper {
                return preg_replace('/(\*|\?|\[)/', '[$1]', $path);
        }
 
+       /**
+        * find all share keys for a given file
+        * @param string $path to the file
+        * @param \OC\Files\View $view view, relative to data/
+        */
+       public static function findShareKeys($path, $view) {
+               $result = array();
+               $pathinfo = pathinfo($path);
+               $dirContent = $view->opendir($pathinfo['dirname']);
+
+               if (is_resource($dirContent)) {
+                       while (($file = readdir($dirContent)) !== false) {
+                               if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
+                                       if (preg_match("/" . $pathinfo['filename'] . ".(.*).shareKey/", $file)) {
+                                               $result[] = $pathinfo['dirname'] . '/' . $file;
+                                       }
+                               }
+                       }
+                       closedir($dirContent);
+               }
+
+               return $result;
+       }
+
        /**
         * remember from which file the tmp file (getLocalFile() call) was created
         * @param string $tmpFile path of tmp file