]> source.dussan.org Git - nextcloud-server.git/commitdiff
New system of unsharing files from self, and a small bug fix when all files inside...
authorMichael Gapczynski <GapczynskiM@gmail.com>
Wed, 17 Aug 2011 21:43:15 +0000 (17:43 -0400)
committerMichael Gapczynski <GapczynskiM@gmail.com>
Wed, 17 Aug 2011 21:43:15 +0000 (17:43 -0400)
apps/files_sharing/lib_share.php
apps/files_sharing/sharedstorage.php

index a4223a137d12f3492c5e8226ce0b84bce9c2df98..761a4da43942acad403f3deeb1bd95c9bd1f6a06 100644 (file)
@@ -199,7 +199,7 @@ class OC_Share {
                        $folder .= "/";
                }
                $length = strlen($folder);
-               $query = OC_DB::prepare("SELECT uid_owner, source, target FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups());
+               $query = OC_DB::prepare("SELECT uid_owner, source, target, permissions FROM *PREFIX*sharing WHERE SUBSTR(source, 1, ?) = ? OR SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups());
                return $query->execute(array($length, $folder, $length, $folder))->fetchAll();
        }
        
@@ -362,10 +362,15 @@ class OC_Share {
        *
        * @param $target The target location of the item
        */
-       public static function unshareFromMySelf($target) {
+       public static function unshareFromMySelf($target, $delete = true) {
                $target = self::cleanPath($target);
-               $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups());
-               $query->execute(array(strlen($target), $target));
+               if ($delete) {
+                       $query = OC_DB::prepare("DELETE FROM *PREFIX*sharing WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups());
+                       $query->execute(array(strlen($target), $target));
+               } else {
+                       $query = OC_DB::prepare("UPDATE *PREFIX*sharing SET permissions = ? WHERE SUBSTR(target, 1, ?) = ? AND uid_shared_with ".self::getUsersAndGroups());
+                       $query->execute(array(-1, strlen($target), $target));
+               }
        }
 
        /**
index 38f8f3e9ebbe5c1a5886664b8c396b4650942137..fc7b7ddc9ce94d5e9dd0a956fecebc37268a4228 100644 (file)
@@ -111,19 +111,22 @@ class OC_Filestorage_Shared extends OC_Filestorage {
                                        $targets = array();
                                        foreach ($modifiedItems as $item) {
                                                // If the item is in the current directory and has a different name than the source, add it to the arrays
-                                               if (dirname($item['target']) == $path && basename($item['source']) != basename($item['target'])) {
-                                                       $sources[] = basename($item['source']);
-                                                       $targets[] = basename($item['target']);
-                                               // If the item was unshared from self, add it it to the arrays
-                                               } elseif ($item['target'] == "/") {
-                                                       $sources[] = basename($item['source']);
-                                                       $targets[] = "";
+                                               if (dirname($item['target']) == $path) {
+                                                       // If the item was unshared from self, add it it to the arrays
+                                                       if ($item['permissions'] == -1) {
+                                                               $sources[] = basename($item['source']);
+                                                               $targets[] = "";
+                                                       } else {
+                                                               $sources[] = basename($item['source']);
+                                                               $targets[] = basename($item['target']);
+                                                       }
                                                }
                                        }
                                        // Don't waste time if there aren't any modified items in the current directory
                                        if (empty($sources)) {
                                                return $dh;
                                        } else {
+                                               $files = array();
                                                while (($filename = readdir($dh)) !== false) {
                                                        if ($filename != "." && $filename != "..") {
                                                                // If the file isn't in the sources array it isn't modified and can be added as is
@@ -402,9 +405,10 @@ class OC_Filestorage_Shared extends OC_Filestorage {
                if (OC_Share::getParentFolders($target)) {
                        // If entry for item already exists
                        if (OC_Share::getItem($target)) {
-                               OC_Share::setTarget($target, "/");
+                               OC_Share::unshareFromMySelf($target, false);
                        } else {
-                               OC_Share::pullOutOfFolder($target, "/");
+                               OC_Share::pullOutOfFolder($target, $target);
+                               OC_Share::unshareFromMySelf($target, false);
                        }
                // Delete the database entry
                } else {