]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix sharing of folders. First we need to collect all files. Than we need to find...
authorBjörn Schießle <schiessle@owncloud.com>
Mon, 22 Apr 2013 09:58:39 +0000 (11:58 +0200)
committerBjörn Schießle <schiessle@owncloud.com>
Mon, 22 Apr 2013 09:58:39 +0000 (11:58 +0200)
apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/util.php

index 2731ee1112555e280d7fb37f7528801f5d3ae4ab..13cf352b4ed604c84a92839b6976bf8032948649 100644 (file)
@@ -166,8 +166,8 @@ class Hooks {
        /**\r
         * @brief \r
         */\r
-       public static function postShared( $params ) {\r
-       \r
+       public static function postShared($params) {\r
+\r
                // NOTE: $params has keys:\r
                // [itemType] => file\r
                // itemSource -> int, filecache file ID\r
@@ -183,50 +183,46 @@ class Hooks {
                // [fileSource] => 13\r
                // [fileTarget] => /test8\r
                // [id] => 10\r
-               // [token] => \r
-               \r
+               // [token] =>\r
                // TODO: Should other kinds of item be encrypted too?\r
-               if ( $params['itemType'] === 'file' ) {\r
-               \r
-                       $view = new \OC_FilesystemView( '/' );\r
+               if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {\r
+\r
+                       $view = new \OC_FilesystemView('/');\r
                        $session = new Session($view);\r
                        $userId = \OCP\User::getUser();\r
-                       $util = new Util( $view, $userId );\r
-                       $path = $util->fileIdToPath( $params['itemSource'] );\r
+                       $util = new Util($view, $userId);\r
+                       $path = $util->fileIdToPath($params['itemSource']);\r
 \r
                        $sharingEnabled = \OCP\Share::isEnabled();\r
-                       $usersSharing = $util->getSharingUsersArray( $sharingEnabled, $path);\r
-                       \r
-                       // Recursively expand path to include subfiles\r
-                       $allPaths = $util->getPaths( $path );\r
-                       \r
-                       $failed = array();\r
-                       \r
-                       // Loop through all subfiles\r
-                       foreach ( $allPaths as $path ) {\r
-                       \r
+\r
+                       if ($params['itemType'] === 'folder') {\r
+                               //list($owner, $ownerPath) = $util->getUidAndFilename($filePath);\r
+                               $allFiles = $util->getAllFiles($path);\r
+                       } else {\r
+                               $allFiles = array($path);\r
+                       }\r
+\r
+                       foreach ($allFiles as $path) {\r
+                               $usersSharing = $util->getSharingUsersArray($sharingEnabled, $path);\r
+\r
+                               $failed = array();\r
+\r
                                // Attempt to set shareKey\r
-                               if ( ! $util->setSharedFileKeyfiles( $session, $usersSharing, $path ) ) {\r
-                               \r
+                               if (!$util->setSharedFileKeyfiles($session, $usersSharing, $path)) {\r
+\r
                                        $failed[] = $path;\r
-                                       \r
                                }\r
-                               \r
                        }\r
-                       \r
+\r
                        // If no attempts to set keyfiles failed\r
-                       if ( empty( $failed ) ) {\r
-                       \r
+                       if (empty($failed)) {\r
+\r
                                return true;\r
-                               \r
                        } else {\r
-                       \r
+\r
                                return false;\r
-                               \r
                        }\r
-               \r
                }\r
-               \r
        }\r
        \r
        /**\r
index 8807de7c2ad8381990bde111f6d72312caeebe76..b3df7f0db03882872c71af8d3eeacd2f4b604f4b 100644 (file)
@@ -939,4 +939,24 @@ class Util {
                
        }
 
+       /**
+        *@ brief geo recursively through a dir and collect all files and sub files.
+        * @param type $dir relative to the users files folder
+        * @return array with list of files relative to the users files folder
+        */
+       public function getAllFiles($dir) {
+               $result = array();
+               $path = $this->view->getLocalFile();
+               $content = $this->view->getDirectoryContent("/".$this->userFilesDir.'/'.$this->filesFolderName.$dir);
+
+               foreach ($content as $c) {
+                       if ($c['type'] === "dir" ) {
+                               $result = array_merge($result, $this->getAllFiles(substr($c['path'],5)));
+                       } else {
+                               $result[] = substr($c['path'], 5);
+                       }
+               }
+               return $result;
+       }
+
 }