From b4cf61ee324bb5b82710f344dfd5a97ac3234e10 Mon Sep 17 00:00:00 2001
From: Michael Gapczynski <GapczynskiM@gmail.com>
Date: Wed, 17 Aug 2011 21:58:53 -0400
Subject: [PATCH] Bug fixes for mkdir(), renaming/moving support for files
 inside a shared folder with write permission

---
 apps/files_sharing/sharedstorage.php | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
index 9650770ab2..c3e75c8f1e 100644
--- a/apps/files_sharing/sharedstorage.php
+++ b/apps/files_sharing/sharedstorage.php
@@ -60,15 +60,13 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 	}
 	
 	public function mkdir($path) {
-		if ($path == "" || $path == "/") {
+		if ($path == "" || $path == "/" || !$this->is_writeable($path)) {
 			return false; 
 		} else {
 			$source = $this->getSource($path);
 			if ($source) {
-				if ($this->is_writeable($path)) {
-					$storage = OC_Filesystem::getStorage($source);
-					return $storage->mkdir($this->getInternalPath($source));
-				}
+				$storage = OC_Filesystem::getStorage($source);
+				return $storage->mkdir($this->getInternalPath($source));
 			}
 		}
 	}
@@ -422,10 +420,14 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 		$oldTarget = $this->datadir.$path1;
 		$newTarget = $this->datadir.$path2;
 		// Check if the item is inside a shared folder
-		if (OC_Share::getParentFolders($oldTarget)) {
-			if ($this->is_writeable($path1)) {
+		if ($folders = OC_Share::getParentFolders($oldTarget)) {
+			$root1 = substr($path1, 0, strpos($path1, "/"));
+			$root2 = substr($path1, 0, strpos($path2, "/"));
+			if ($root1 !== $root2) {
+				return false;
+			} else if ($this->is_writeable($path1) && $this->is_writeable($path2)) {
 				$oldSource = $this->getSource($path1);
-				$newSource = dirname($oldSource)."/".basename($path2);
+				$newSource = $folders['source'].substr($newTarget, strlen($folders['target']));
 				if ($oldSource) {
 					$storage = OC_Filesystem::getStorage($oldSource);
 					return $storage->rename($this->getInternalPath($oldSource), $this->getInternalPath($newSource));
-- 
GitLab