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