Merge pull request #5805 from owncloud/shared-storage-copy-folder
Use View::copy and View::rename when copying or renaming files in the shared storage
This commit is contained in:
commit
58ff8a8673
|
@ -257,7 +257,8 @@ class Shared extends \OC\Files\Storage\Common {
|
||||||
if ($source = $this->getSourcePath($path)) {
|
if ($source = $this->getSourcePath($path)) {
|
||||||
// Check if permission is granted
|
// Check if permission is granted
|
||||||
if (($this->file_exists($path) && !$this->isUpdatable($path))
|
if (($this->file_exists($path) && !$this->isUpdatable($path))
|
||||||
|| ($this->is_dir($path) && !$this->isCreatable($path))) {
|
|| ($this->is_dir($path) && !$this->isCreatable($path))
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$info = array(
|
$info = array(
|
||||||
|
@ -305,30 +306,15 @@ class Shared extends \OC\Files\Storage\Common {
|
||||||
$pos2 = strpos($path2, '/', 1);
|
$pos2 = strpos($path2, '/', 1);
|
||||||
if ($pos1 !== false && $pos2 !== false && ($oldSource = $this->getSourcePath($path1))) {
|
if ($pos1 !== false && $pos2 !== false && ($oldSource = $this->getSourcePath($path1))) {
|
||||||
$newSource = $this->getSourcePath(dirname($path2)) . '/' . basename($path2);
|
$newSource = $this->getSourcePath(dirname($path2)) . '/' . basename($path2);
|
||||||
if (dirname($path1) == dirname($path2)) {
|
// Within the same folder, we only need UPDATE permissions
|
||||||
// Rename the file if UPDATE permission is granted
|
if (dirname($path1) == dirname($path2) and $this->isUpdatable($path1)) {
|
||||||
if ($this->isUpdatable($path1)) {
|
|
||||||
list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource);
|
list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource);
|
||||||
list(, $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource);
|
list(, $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource);
|
||||||
return $storage->rename($oldInternalPath, $newInternalPath);
|
return $storage->rename($oldInternalPath, $newInternalPath);
|
||||||
}
|
// otherwise DELETE and CREATE permissions required
|
||||||
} else {
|
} elseif ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) {
|
||||||
// Move the file if DELETE and CREATE permissions are granted
|
$rootView = new \OC\Files\View('');
|
||||||
if ($this->isDeletable($path1) && $this->isCreatable(dirname($path2))) {
|
return $rootView->rename($oldSource, $newSource);
|
||||||
// Get the root shared folder
|
|
||||||
$folder1 = substr($path1, 0, $pos1);
|
|
||||||
$folder2 = substr($path2, 0, $pos2);
|
|
||||||
// Copy and unlink the file if it exists in a different shared folder
|
|
||||||
if ($folder1 != $folder2) {
|
|
||||||
if ($this->copy($path1, $path2)) {
|
|
||||||
return $this->unlink($path1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
list($storage, $oldInternalPath) = \OC\Files\Filesystem::resolvePath($oldSource);
|
|
||||||
list( , $newInternalPath) = \OC\Files\Filesystem::resolvePath($newSource);
|
|
||||||
return $storage->rename($oldInternalPath, $newInternalPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -338,10 +324,10 @@ class Shared extends \OC\Files\Storage\Common {
|
||||||
public function copy($path1, $path2) {
|
public function copy($path1, $path2) {
|
||||||
// Copy the file if CREATE permission is granted
|
// Copy the file if CREATE permission is granted
|
||||||
if ($this->isCreatable(dirname($path2))) {
|
if ($this->isCreatable(dirname($path2))) {
|
||||||
$source = $this->fopen($path1, 'r');
|
$oldSource = $this->getSourcePath($path1);
|
||||||
$target = $this->fopen($path2, 'w');
|
$newSource = $this->getSourcePath(dirname($path2)) . '/' . basename($path2);
|
||||||
list ($count, $result) = \OC_Helper::streamCopy($source, $target);
|
$rootView = new \OC\Files\View('');
|
||||||
return $result;
|
return $rootView->copy($oldSource, $newSource);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -412,6 +398,7 @@ class Shared extends \OC\Files\Storage\Common {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function touch($path, $mtime = null) {
|
public function touch($path, $mtime = null) {
|
||||||
if ($source = $this->getSourcePath($path)) {
|
if ($source = $this->getSourcePath($path)) {
|
||||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
||||||
|
@ -422,7 +409,8 @@ class Shared extends \OC\Files\Storage\Common {
|
||||||
|
|
||||||
public static function setup($options) {
|
public static function setup($options) {
|
||||||
if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user']
|
if (!\OCP\User::isLoggedIn() || \OCP\User::getUser() != $options['user']
|
||||||
|| \OCP\Share::getItemsSharedWith('file')) {
|
|| \OCP\Share::getItemsSharedWith('file')
|
||||||
|
) {
|
||||||
$user_dir = $options['user_dir'];
|
$user_dir = $options['user_dir'];
|
||||||
\OC\Files\Filesystem::mount('\OC\Files\Storage\Shared',
|
\OC\Files\Filesystem::mount('\OC\Files\Storage\Shared',
|
||||||
array('sharedFolder' => '/Shared'),
|
array('sharedFolder' => '/Shared'),
|
||||||
|
|
Loading…
Reference in New Issue