Rename file1 and file2 to source and target in Storage abstraction

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
pull/34624/head
Carl Schwan 2 years ago
parent 732badf552
commit a5ea677370

@ -574,16 +574,16 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return true;
}
public function copy($path1, $path2, $isFile = null) {
$path1 = $this->normalizePath($path1);
$path2 = $this->normalizePath($path2);
public function copy($source, $target, $isFile = null) {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
if ($isFile === true || $this->is_file($path1)) {
if ($isFile === true || $this->is_file($source)) {
try {
$this->getConnection()->copyObject([
'Bucket' => $this->bucket,
'Key' => $this->cleanKey($path2),
'CopySource' => S3Client::encodeKey($this->bucket . '/' . $path1)
'Key' => $this->cleanKey($target),
'CopySource' => S3Client::encodeKey($this->bucket . '/' . $source)
]);
$this->testTimeout();
} catch (S3Exception $e) {
@ -594,10 +594,10 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return false;
}
} else {
$this->remove($path2);
$this->remove($target);
try {
$this->mkdir($path2);
$this->mkdir($target);
$this->testTimeout();
} catch (S3Exception $e) {
$this->logger->error($e->getMessage(), [
@ -607,38 +607,38 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return false;
}
foreach ($this->getDirectoryContent($path1) as $item) {
$source = $path1 . '/' . $item['name'];
$target = $path2 . '/' . $item['name'];
foreach ($this->getDirectoryContent($source) as $item) {
$source = $source . '/' . $item['name'];
$target = $target . '/' . $item['name'];
$this->copy($source, $target, $item['mimetype'] !== FileInfo::MIMETYPE_FOLDER);
}
}
$this->invalidateCache($path2);
$this->invalidateCache($target);
return true;
}
public function rename($path1, $path2) {
$path1 = $this->normalizePath($path1);
$path2 = $this->normalizePath($path2);
public function rename($source, $target) {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
if ($this->is_file($path1)) {
if ($this->copy($path1, $path2) === false) {
if ($this->is_file($source)) {
if ($this->copy($source, $target) === false) {
return false;
}
if ($this->unlink($path1) === false) {
$this->unlink($path2);
if ($this->unlink($source) === false) {
$this->unlink($target);
return false;
}
} else {
if ($this->copy($path1, $path2) === false) {
if ($this->copy($source, $target) === false) {
return false;
}
if ($this->rmdir($path1) === false) {
$this->rmdir($path2);
if ($this->rmdir($source) === false) {
$this->rmdir($target);
return false;
}
}

@ -333,9 +333,9 @@ class FTP extends Common {
}
}
public function rename($path1, $path2) {
$this->unlink($path2);
return $this->getConnection()->rename($this->buildPath($path1), $this->buildPath($path2));
public function rename($source, $target) {
$this->unlink($target);
return $this->getConnection()->rename($this->buildPath($source), $this->buildPath($target));
}
public function getDirectoryContent($directory): \Traversable {

@ -85,8 +85,8 @@ class FtpConnection {
return @ftp_rmdir($this->connection, $path);
}
public function rename(string $path1, string $path2) {
return @ftp_rename($this->connection, $path1, $path2);
public function rename(string $source, string $target) {
return @ftp_rename($this->connection, $source, $target);
}
public function mdtm(string $path) {

@ -435,14 +435,14 @@ class SFTP extends \OC\Files\Storage\Common {
/**
* {@inheritdoc}
*/
public function rename($path1, $path2) {
public function rename($source, $target) {
try {
if ($this->file_exists($path2)) {
$this->unlink($path2);
if ($this->file_exists($target)) {
$this->unlink($target);
}
return $this->getConnection()->rename(
$this->absPath($path1),
$this->absPath($path2)
$this->absPath($source),
$this->absPath($target)
);
} catch (\Exception $e) {
return false;

@ -306,22 +306,22 @@ class SMB extends Common implements INotifyStorage {
/**
* Rename the files. If the source or the target is the root, the rename won't happen.
*
* @param string $path1 the old name of the path
* @param string $path2 the new name of the path
* @param string $source the old name of the path
* @param string $target the new name of the path
* @return bool true if the rename is successful, false otherwise
*/
public function rename($path1, $path2, $retry = true) {
if ($this->isRootDir($path1) || $this->isRootDir($path2)) {
public function rename($source, $target, $retry = true): bool {
if ($this->isRootDir($source) || $this->isRootDir($target)) {
return false;
}
$absoluteSource = $this->buildPath($path1);
$absoluteTarget = $this->buildPath($path2);
$absoluteSource = $this->buildPath($source);
$absoluteTarget = $this->buildPath($target);
try {
$result = $this->share->rename($absoluteSource, $absoluteTarget);
} catch (AlreadyExistsException $e) {
if ($retry) {
$this->remove($path2);
$this->remove($target);
$result = $this->share->rename($absoluteSource, $absoluteTarget);
} else {
$this->logger->logException($e, ['level' => ILogger::WARN]);
@ -329,7 +329,7 @@ class SMB extends Common implements INotifyStorage {
}
} catch (InvalidArgumentException $e) {
if ($retry) {
$this->remove($path2);
$this->remove($target);
$result = $this->share->rename($absoluteSource, $absoluteTarget);
} else {
$this->logger->logException($e, ['level' => ILogger::WARN]);

@ -117,8 +117,8 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common {
return copy($path, $this->constructUrl($target));
}
public function rename($path1, $path2) {
return rename($this->constructUrl($path1), $this->constructUrl($path2));
public function rename($source, $target) {
return rename($this->constructUrl($source), $this->constructUrl($target));
}
public function stat($path) {

@ -482,25 +482,25 @@ class Swift extends \OC\Files\Storage\Common {
}
}
public function copy($path1, $path2) {
$path1 = $this->normalizePath($path1);
$path2 = $this->normalizePath($path2);
public function copy($source, $target) {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
$fileType = $this->filetype($path1);
$fileType = $this->filetype($source);
if ($fileType) {
// make way
$this->unlink($path2);
$this->unlink($target);
}
if ($fileType === 'file') {
try {
$source = $this->fetchObject($path1);
$source->copy([
'destination' => $this->bucket . '/' . $path2
$sourceObject = $this->fetchObject($source);
$sourceObject->copy([
'destination' => $this->bucket . '/' . $target
]);
// invalidate target object to force repopulation on fetch
$this->objectCache->remove($path2);
$this->objectCache->remove($path2 . '/');
$this->objectCache->remove($target);
$this->objectCache->remove($target . '/');
} catch (BadResponseError $e) {
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
@ -510,13 +510,13 @@ class Swift extends \OC\Files\Storage\Common {
}
} elseif ($fileType === 'dir') {
try {
$source = $this->fetchObject($path1 . '/');
$source->copy([
'destination' => $this->bucket . '/' . $path2 . '/'
$sourceObject = $this->fetchObject($source . '/');
$sourceObject->copy([
'destination' => $this->bucket . '/' . $target . '/'
]);
// invalidate target object to force repopulation on fetch
$this->objectCache->remove($path2);
$this->objectCache->remove($path2 . '/');
$this->objectCache->remove($target);
$this->objectCache->remove($target . '/');
} catch (BadResponseError $e) {
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
@ -525,14 +525,14 @@ class Swift extends \OC\Files\Storage\Common {
return false;
}
$dh = $this->opendir($path1);
$dh = $this->opendir($source);
while ($file = readdir($dh)) {
if (\OC\Files\Filesystem::isIgnoredDir($file)) {
continue;
}
$source = $path1 . '/' . $file;
$target = $path2 . '/' . $file;
$source = $source . '/' . $file;
$target = $target . '/' . $file;
$this->copy($source, $target);
}
} else {
@ -543,22 +543,22 @@ class Swift extends \OC\Files\Storage\Common {
return true;
}
public function rename($path1, $path2) {
$path1 = $this->normalizePath($path1);
$path2 = $this->normalizePath($path2);
public function rename($source, $target) {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
$fileType = $this->filetype($path1);
$fileType = $this->filetype($source);
if ($fileType === 'dir' || $fileType === 'file') {
// copy
if ($this->copy($path1, $path2) === false) {
if ($this->copy($source, $target) === false) {
return false;
}
// cleanup
if ($this->unlink($path1) === false) {
if ($this->unlink($source) === false) {
throw new \Exception('failed to remove original');
$this->unlink($path2);
$this->unlink($target);
return false;
}

@ -334,15 +334,15 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
/**
* see https://www.php.net/manual/en/function.rename.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
*/
public function rename($path1, $path2): bool {
public function rename($source, $target): bool {
$this->init();
$isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
$targetExists = $this->file_exists($path2);
$sameFolder = dirname($path1) === dirname($path2);
$isPartFile = pathinfo($source, PATHINFO_EXTENSION) === 'part';
$targetExists = $this->file_exists($target);
$sameFolder = dirname($source) === dirname($target);
if ($targetExists || ($sameFolder && !$isPartFile)) {
if (!$this->isUpdatable('')) {
@ -354,7 +354,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
}
}
return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
return $this->nonMaskedStorage->rename($this->getUnjailedPath($source), $this->getUnjailedPath($target));
}
/**

@ -1108,9 +1108,7 @@
<TooManyArguments occurrences="1">
<code>dispatch</code>
</TooManyArguments>
<InvalidArgument occurrences="1">
<code>dispatch</code>
</InvalidArgument>
<InvalidArgument occurrences="1"/>
</file>
<file src="apps/files_sharing/lib/AppInfo/Application.php">
<InvalidArgument occurrences="6">
@ -2748,10 +2746,6 @@
<InvalidScalarArgument occurrences="1">
<code>$source</code>
</InvalidScalarArgument>
<ParamNameMismatch occurrences="2">
<code>$source</code>
<code>$target</code>
</ParamNameMismatch>
</file>
<file src="lib/private/Files/ObjectStore/S3ConnectionTrait.php">
<InternalClass occurrences="1">
@ -3013,10 +3007,6 @@
<code>$free</code>
<code>'ext'</code>
</InvalidScalarArgument>
<ParamNameMismatch occurrences="2">
<code>$source</code>
<code>$target</code>
</ParamNameMismatch>
</file>
<file src="lib/private/Files/Storage/Wrapper/Wrapper.php">
<InvalidReturnStatement occurrences="1">

@ -599,12 +599,12 @@ class Filesystem {
return self::$defaultInstance->unlink($path);
}
public static function rename($path1, $path2) {
return self::$defaultInstance->rename($path1, $path2);
public static function rename($source, $target) {
return self::$defaultInstance->rename($source, $target);
}
public static function copy($path1, $path2) {
return self::$defaultInstance->copy($path1, $path2);
public static function copy($source, $target) {
return self::$defaultInstance->copy($source, $target);
}
public static function fopen($path, $mode) {

@ -558,17 +558,17 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
}
public function copy($path1, $path2) {
$path1 = $this->normalizePath($path1);
$path2 = $this->normalizePath($path2);
public function copy($source, $target) {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
$cache = $this->getCache();
$sourceEntry = $cache->get($path1);
$sourceEntry = $cache->get($source);
if (!$sourceEntry) {
throw new NotFoundException('Source object not found');
}
$this->copyInner($sourceEntry, $path2);
$this->copyInner($sourceEntry, $target);
return true;
}

@ -213,21 +213,21 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
return $count;
}
public function rename($path1, $path2) {
$this->remove($path2);
public function rename($source, $target) {
$this->remove($target);
$this->removeCachedFile($path1);
return $this->copy($path1, $path2) and $this->remove($path1);
$this->removeCachedFile($source);
return $this->copy($source, $target) and $this->remove($source);
}
public function copy($path1, $path2) {
if ($this->is_dir($path1)) {
$this->remove($path2);
$dir = $this->opendir($path1);
$this->mkdir($path2);
public function copy($source, $target) {
if ($this->is_dir($source)) {
$this->remove($target);
$dir = $this->opendir($source);
$this->mkdir($target);
while ($file = readdir($dir)) {
if (!Filesystem::isIgnoredDir($file)) {
if (!$this->copy($path1 . '/' . $file, $path2 . '/' . $file)) {
if (!$this->copy($source . '/' . $file, $target . '/' . $file)) {
closedir($dir);
return false;
}
@ -236,13 +236,13 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
closedir($dir);
return true;
} else {
$source = $this->fopen($path1, 'r');
$target = $this->fopen($path2, 'w');
[, $result] = \OC_Helper::streamCopy($source, $target);
$sourceStream = $this->fopen($source, 'r');
$targetStream = $this->fopen($target, 'w');
[, $result] = \OC_Helper::streamCopy($sourceStream, $targetStream);
if (!$result) {
\OC::$server->get(LoggerInterface::class)->warning("Failed to write data while copying $path1 to $path2");
\OCP\Server::get(LoggerInterface::class)->warning("Failed to write data while copying $source to $target");
}
$this->removeCachedFile($path2);
$this->removeCachedFile($target);
return $result;
}
}

@ -518,30 +518,30 @@ class DAV extends Common {
}
/** {@inheritdoc} */
public function rename($path1, $path2) {
public function rename($source, $target) {
$this->init();
$path1 = $this->cleanPath($path1);
$path2 = $this->cleanPath($path2);
$source = $this->cleanPath($source);
$target = $this->cleanPath($target);
try {
// overwrite directory ?
if ($this->is_dir($path2)) {
if ($this->is_dir($target)) {
// needs trailing slash in destination
$path2 = rtrim($path2, '/') . '/';
$target = rtrim($target, '/') . '/';
}
$this->client->request(
'MOVE',
$this->encodePath($path1),
$this->encodePath($source),
null,
[
'Destination' => $this->createBaseUri() . $this->encodePath($path2),
'Destination' => $this->createBaseUri() . $this->encodePath($target),
]
);
$this->statCache->clear($path1 . '/');
$this->statCache->clear($path2 . '/');
$this->statCache->set($path1, false);
$this->statCache->set($path2, true);
$this->removeCachedFile($path1);
$this->removeCachedFile($path2);
$this->statCache->clear($source . '/');
$this->statCache->clear($target . '/');
$this->statCache->set($source, false);
$this->statCache->set($target, true);
$this->removeCachedFile($source);
$this->removeCachedFile($target);
return true;
} catch (\Exception $e) {
$this->convertException($e);
@ -550,27 +550,27 @@ class DAV extends Common {
}
/** {@inheritdoc} */
public function copy($path1, $path2) {
public function copy($source, $target) {
$this->init();
$path1 = $this->cleanPath($path1);
$path2 = $this->cleanPath($path2);
$source = $this->cleanPath($source);
$target = $this->cleanPath($target);
try {
// overwrite directory ?
if ($this->is_dir($path2)) {
if ($this->is_dir($target)) {
// needs trailing slash in destination
$path2 = rtrim($path2, '/') . '/';
$target = rtrim($target, '/') . '/';
}
$this->client->request(
'COPY',
$this->encodePath($path1),
$this->encodePath($source),
null,
[
'Destination' => $this->createBaseUri() . $this->encodePath($path2),
'Destination' => $this->createBaseUri() . $this->encodePath($target),
]
);
$this->statCache->clear($path2 . '/');
$this->statCache->set($path2, true);
$this->removeCachedFile($path2);
$this->statCache->clear($target . '/');
$this->statCache->set($target, true);
$this->removeCachedFile($target);
return true;
} catch (\Exception $e) {
$this->convertException($e);

@ -129,11 +129,11 @@ class FailedStorage extends Common {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
public function rename($path1, $path2) {
public function rename($source, $target) {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}
public function copy($path1, $path2) {
public function copy($source, $target) {
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
}

@ -333,9 +333,9 @@ class Local extends \OC\Files\Storage\Common {
}
}
public function rename($path1, $path2) {
$srcParent = dirname($path1);
$dstParent = dirname($path2);
public function rename($source, $target) {
$srcParent = dirname($source);
$dstParent = dirname($target);
if (!$this->isUpdatable($srcParent)) {
\OC::$server->get(LoggerInterface::class)->error('unable to rename, source directory is not writable : ' . $srcParent, ['app' => 'core']);
@ -347,44 +347,44 @@ class Local extends \OC\Files\Storage\Common {
return false;
}
if (!$this->file_exists($path1)) {
\OC::$server->get(LoggerInterface::class)->error('unable to rename, file does not exists : ' . $path1, ['app' => 'core']);
if (!$this->file_exists($source)) {
\OC::$server->get(LoggerInterface::class)->error('unable to rename, file does not exists : ' . $source, ['app' => 'core']);
return false;
}
if ($this->is_dir($path2)) {
$this->rmdir($path2);
} elseif ($this->is_file($path2)) {
$this->unlink($path2);
if ($this->is_dir($target)) {
$this->rmdir($target);
} elseif ($this->is_file($target)) {
$this->unlink($target);
}
if ($this->is_dir($path1)) {
if ($this->is_dir($source)) {
// we can't move folders across devices, use copy instead
$stat1 = stat(dirname($this->getSourcePath($path1)));
$stat2 = stat(dirname($this->getSourcePath($path2)));
$stat1 = stat(dirname($this->getSourcePath($source)));
$stat2 = stat(dirname($this->getSourcePath($target)));
if ($stat1['dev'] !== $stat2['dev']) {
$result = $this->copy($path1, $path2);
$result = $this->copy($source, $target);
if ($result) {
$result &= $this->rmdir($path1);
$result &= $this->rmdir($source);
}
return $result;
}
$this->checkTreeForForbiddenItems($this->getSourcePath($path1));
$this->checkTreeForForbiddenItems($this->getSourcePath($source));
}
return rename($this->getSourcePath($path1), $this->getSourcePath($path2));
return rename($this->getSourcePath($source), $this->getSourcePath($target));
}
public function copy($path1, $path2) {
if ($this->is_dir($path1)) {
return parent::copy($path1, $path2);
public function copy($source, $target) {
if ($this->is_dir($source)) {
return parent::copy($source, $target);
} else {
$oldMask = umask($this->defUMask);
if ($this->unlinkOnTruncate) {
$this->unlink($path2);
$this->unlink($target);
}
$result = copy($this->getSourcePath($path1), $this->getSourcePath($path2));
$result = copy($this->getSourcePath($source), $this->getSourcePath($target));
umask($oldMask);
return $result;
}

@ -64,15 +64,15 @@ trait CopyDirectory {
*/
abstract public function mkdir($path);
public function copy($path1, $path2) {
if ($this->is_dir($path1)) {
if ($this->file_exists($path2)) {
$this->unlink($path2);
public function copy($source, $target) {
if ($this->is_dir($source)) {
if ($this->file_exists($target)) {
$this->unlink($target);
}
$this->mkdir($path2);
return $this->copyRecursive($path1, $path2);
$this->mkdir($target);
return $this->copyRecursive($source, $target);
} else {
return parent::copy($path1, $path2);
return parent::copy($source, $target);
}
}

@ -288,20 +288,20 @@ class Availability extends Wrapper {
}
/** {@inheritdoc} */
public function rename($path1, $path2) {
public function rename($source, $target) {
$this->checkAvailability();
try {
return parent::rename($path1, $path2);
return parent::rename($source, $target);
} catch (StorageNotAvailableException $e) {
$this->setUnavailable($e);
}
}
/** {@inheritdoc} */
public function copy($path1, $path2) {
public function copy($source, $target) {
$this->checkAvailability();
try {
return parent::copy($path1, $path2);
return parent::copy($source, $target);
} catch (StorageNotAvailableException $e) {
$this->setUnavailable($e);
}

@ -338,24 +338,24 @@ class Encoding extends Wrapper {
/**
* see https://www.php.net/manual/en/function.rename.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
*/
public function rename($path1, $path2) {
public function rename($source, $target) {
// second name always NFC
return $this->storage->rename($this->findPathToUse($path1), $this->findPathToUse($path2));
return $this->storage->rename($this->findPathToUse($source), $this->findPathToUse($target));
}
/**
* see https://www.php.net/manual/en/function.copy.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
*/
public function copy($path1, $path2) {
return $this->storage->copy($this->findPathToUse($path1), $this->findPathToUse($path2));
public function copy($source, $target) {
return $this->storage->copy($this->findPathToUse($source), $this->findPathToUse($target));
}
/**

@ -270,28 +270,28 @@ class Encryption extends Wrapper {
/**
* see https://www.php.net/manual/en/function.rename.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
*/
public function rename($path1, $path2) {
$result = $this->storage->rename($path1, $path2);
public function rename($source, $target) {
$result = $this->storage->rename($source, $target);
if ($result &&
// versions always use the keys from the original file, so we can skip
// this step for versions
$this->isVersion($path2) === false &&
$this->isVersion($target) === false &&
$this->encryptionManager->isEnabled()) {
$source = $this->getFullPath($path1);
if (!$this->util->isExcluded($source)) {
$target = $this->getFullPath($path2);
if (isset($this->unencryptedSize[$source])) {
$this->unencryptedSize[$target] = $this->unencryptedSize[$source];
$sourcePath = $this->getFullPath($source);
if (!$this->util->isExcluded($sourcePath)) {
$targetPath = $this->getFullPath($target);
if (isset($this->unencryptedSize[$sourcePath])) {
$this->unencryptedSize[$targetPath] = $this->unencryptedSize[$sourcePath];
}
$this->keyStorage->renameKeys($source, $target);
$module = $this->getEncryptionModule($path2);
$this->keyStorage->renameKeys($sourcePath, $targetPath);
$module = $this->getEncryptionModule($target);
if ($module) {
$module->update($target, $this->uid, []);
$module->update($targetPath, $this->uid, []);
}
}
}
@ -344,21 +344,20 @@ class Encryption extends Wrapper {
/**
* see https://www.php.net/manual/en/function.copy.php
*
* @param string $path1
* @param string $path2
* @return bool
* @param string $source
* @param string $target
*/
public function copy($path1, $path2) {
$source = $this->getFullPath($path1);
public function copy($source, $target): bool {
$sourcePath = $this->getFullPath($source);
if ($this->util->isExcluded($source)) {
return $this->storage->copy($path1, $path2);
if ($this->util->isExcluded($sourcePath)) {
return $this->storage->copy($source, $target);
}
// need to stream copy file by file in case we copy between a encrypted
// and a unencrypted storage
$this->unlink($path2);
return $this->copyFromStorage($this, $path1, $path2);
$this->unlink($target);
return $this->copyFromStorage($this, $source, $target);
}
/**

@ -281,23 +281,23 @@ class Jail extends Wrapper {
/**
* see https://www.php.net/manual/en/function.rename.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
*/
public function rename($path1, $path2) {
return $this->getWrapperStorage()->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
public function rename($source, $target) {
return $this->getWrapperStorage()->rename($this->getUnjailedPath($source), $this->getUnjailedPath($target));
}
/**
* see https://www.php.net/manual/en/function.copy.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
*/
public function copy($path1, $path2) {
return $this->getWrapperStorage()->copy($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
public function copy($source, $target) {
return $this->getWrapperStorage()->copy($this->getUnjailedPath($source), $this->getUnjailedPath($target));
}
/**

@ -78,16 +78,16 @@ class PermissionsMask extends Wrapper {
return $this->storage->getPermissions($path) & $this->mask;
}
public function rename($path1, $path2) {
public function rename($source, $target) {
//This is a rename of the transfer file to the original file
if (dirname($path1) === dirname($path2) && strpos($path1, '.ocTransferId') > 0) {
return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($path1, $path2);
if (dirname($source) === dirname($target) && strpos($source, '.ocTransferId') > 0) {
return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($source, $target);
}
return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($path1, $path2);
return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($source, $target);
}
public function copy($path1, $path2) {
return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($path1, $path2);
public function copy($source, $target) {
return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($source, $target);
}
public function touch($path, $mtime = null) {

@ -271,23 +271,23 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea
/**
* see https://www.php.net/manual/en/function.rename.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
*/
public function rename($path1, $path2) {
return $this->getWrapperStorage()->rename($path1, $path2);
public function rename($source, $target) {
return $this->getWrapperStorage()->rename($source, $target);
}
/**
* see https://www.php.net/manual/en/function.copy.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
*/
public function copy($path1, $path2) {
return $this->getWrapperStorage()->copy($path1, $path2);
public function copy($source, $target) {
return $this->getWrapperStorage()->copy($source, $target);
}
/**

@ -749,65 +749,65 @@ class View {
/**
* Rename/move a file or folder from the source path to target path.
*
* @param string $path1 source path
* @param string $path2 target path
* @param string $source source path
* @param string $target target path
*
* @return bool|mixed
* @throws LockedException
*/
public function rename($path1, $path2) {
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
public function rename($source, $target) {
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($source));
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($target));
$result = false;
if (
Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
and !Filesystem::isFileBlacklisted($path2)
Filesystem::isValidPath($target)
and Filesystem::isValidPath($source)
and !Filesystem::isFileBlacklisted($target)
) {
$path1 = $this->getRelativePath($absolutePath1);
$path2 = $this->getRelativePath($absolutePath2);
$exists = $this->file_exists($path2);
$source = $this->getRelativePath($absolutePath1);
$target = $this->getRelativePath($absolutePath2);
$exists = $this->file_exists($target);
if ($path1 == null or $path2 == null) {
if ($source == null or $target == null) {
return false;
}
$this->lockFile($path1, ILockingProvider::LOCK_SHARED, true);
$this->lockFile($source, ILockingProvider::LOCK_SHARED, true);
try {
$this->lockFile($path2, ILockingProvider::LOCK_SHARED, true);
$this->lockFile($target, ILockingProvider::LOCK_SHARED, true);
$run = true;
if ($this->shouldEmitHooks($path1) && (Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2))) {
if ($this->shouldEmitHooks($source) && (Cache\Scanner::isPartialFile($source) && !Cache\Scanner::isPartialFile($target))) {
// if it was a rename from a part file to a regular file it was a write and not a rename operation
$this->emit_file_hooks_pre($exists, $path2, $run);
} elseif ($this->shouldEmitHooks($path1)) {
$this->emit_file_hooks_pre($exists, $target, $run);
} elseif ($this->shouldEmitHooks($source)) {
\OC_Hook::emit(
Filesystem::CLASSNAME, Filesystem::signal_rename,
[
Filesystem::signal_param_oldpath => $this->getHookPath($path1),
Filesystem::signal_param_newpath => $this->getHookPath($path2),
Filesystem::signal_param_oldpath => $this->getHookPath($source),
Filesystem::signal_param_newpath => $this->getHookPath($target),
Filesystem::signal_param_run => &$run
]
);
}
if ($run) {
$this->verifyPath(dirname($path2), basename($path2));
$this->verifyPath(dirname($target), basename($target));
$manager = Filesystem::getMountManager();
$mount1 = $this->getMount($path1);
$mount2 = $this->getMount($path2);
$mount1 = $this->getMount($source);
$mount2 = $this->getMount($target);
$storage1 = $mount1->getStorage();
$storage2 = $mount2->getStorage();
$internalPath1 = $mount1->getInternalPath($absolutePath1);
$internalPath2 = $mount2->getInternalPath($absolutePath2);
$this->changeLock($path1, ILockingProvider::LOCK_EXCLUSIVE, true);
$this->changeLock($source, ILockingProvider::LOCK_EXCLUSIVE, true);
try {
$this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE, true);
$this->changeLock($target, ILockingProvider::LOCK_EXCLUSIVE, true);
if ($internalPath1 === '') {
if ($mount1 instanceof MoveableMount) {
$sourceParentMount = $this->getMount(dirname($path1));
$sourceParentMount = $this->getMount(dirname($source));
if ($sourceParentMount === $mount2 && $this->targetIsNotShared($storage2, $internalPath2)) {
/**
* @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount1
@ -833,7 +833,7 @@ class View {
$result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
}
if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
if ((Cache\Scanner::isPartialFile($source) && !Cache\Scanner::isPartialFile($target)) && $result !== false) {
// if it was a rename from a part file to a regular file it was a write and not a rename operation
$this->writeUpdate($storage2, $internalPath2);
} elseif ($result) {
@ -844,22 +844,22 @@ class View {
} catch (\Exception $e) {
throw $e;
} finally {
$this->changeLock($path1, ILockingProvider::LOCK_SHARED, true);
$this->changeLock($path2, ILockingProvider::LOCK_SHARED, true);
$this->changeLock($source, ILockingProvider::LOCK_SHARED, true);
$this->changeLock($target, ILockingProvider::LOCK_SHARED, true);
}
if ((Cache\Scanner::isPartialFile($path1) && !Cache\Scanner::isPartialFile($path2)) && $result !== false) {
if ((Cache\Scanner::isPartialFile($source) && !Cache\Scanner::isPartialFile($target)) && $result !== false) {
if ($this->shouldEmitHooks()) {
$this->emit_file_hooks_post($exists, $path2);
$this->emit_file_hooks_post($exists, $target);
}
} elseif ($result) {
if ($this->shouldEmitHooks($path1) and $this->shouldEmitHooks($path2)) {
if ($this->shouldEmitHooks($source) and $this->shouldEmitHooks($target)) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_post_rename,
[
Filesystem::signal_param_oldpath => $this->getHookPath($path1),
Filesystem::signal_param_newpath => $this->getHookPath($path2)
Filesystem::signal_param_oldpath => $this->getHookPath($source),
Filesystem::signal_param_newpath => $this->getHookPath($target)
]
);
}
@ -868,8 +868,8 @@ class View {
} catch (\Exception $e) {
throw $e;
} finally {
$this->unlockFile($path1, ILockingProvider::LOCK_SHARED, true);
$this->unlockFile($path2, ILockingProvider::LOCK_SHARED, true);
$this->unlockFile($source, ILockingProvider::LOCK_SHARED, true);
$this->unlockFile($target, ILockingProvider::LOCK_SHARED, true);
}
}
return $result;
@ -878,57 +878,57 @@ class View {
/**
* Copy a file/folder from the source path to target path
*
* @param string $path1 source path
* @param string $path2 target path
* @param string $source source path
* @param string $target target path
* @param bool $preserveMtime whether to preserve mtime on the copy
*
* @return bool|mixed
*/
public function copy($path1, $path2, $preserveMtime = false) {
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
public function copy($source, $target, $preserveMtime = false) {
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($source));
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($target));
$result = false;
if (
Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
and !Filesystem::isFileBlacklisted($path2)
Filesystem::isValidPath($target)
and Filesystem::isValidPath($source)
and !Filesystem::isFileBlacklisted($target)
) {
$path1 = $this->getRelativePath($absolutePath1);
$path2 = $this->getRelativePath($absolutePath2);
$source = $this->getRelativePath($absolutePath1);
$target = $this->getRelativePath($absolutePath2);
if ($path1 == null or $path2 == null) {
if ($source == null or $target == null) {
return false;
}
$run = true;
$this->lockFile($path2, ILockingProvider::LOCK_SHARED);
$this->lockFile($path1, ILockingProvider::LOCK_SHARED);
$this->lockFile($target, ILockingProvider::LOCK_SHARED);
$this->lockFile($source, ILockingProvider::LOCK_SHARED);
$lockTypePath1 = ILockingProvider::LOCK_SHARED;
$lockTypePath2 = ILockingProvider::LOCK_SHARED;
try {
$exists = $this->file_exists($path2);
$exists = $this->file_exists($target);
if ($this->shouldEmitHooks()) {
\OC_Hook::emit(
Filesystem::CLASSNAME,
Filesystem::signal_copy,
[
Filesystem::signal_param_oldpath => $this->getHookPath($path1),
Filesystem::signal_param_newpath => $this->getHookPath($path2),
Filesystem::signal_param_oldpath => $this->getHookPath($source),
Filesystem::signal_param_newpath => $this->getHookPath($target),
Filesystem::signal_param_run => &$run
]
);
$this->emit_file_hooks_pre($exists, $path2, $run);
$this->emit_file_hooks_pre($exists, $target, $run);
}
if ($run) {
$mount1 = $this->getMount($path1);
$mount2 = $this->getMount($path2);
$mount1 = $this->getMount($source);
$mount2 = $this->getMount($target);
$storage1 = $mount1->getStorage();
$internalPath1 = $mount1->getInternalPath($absolutePath1);
$storage2 = $mount2->getStorage();
$internalPath2 = $mount2->getInternalPath($absolutePath2);
$this->changeLock($path2, ILockingProvider::LOCK_EXCLUSIVE);
$this->changeLock($target, ILockingProvider::LOCK_EXCLUSIVE);
$lockTypePath2 = ILockingProvider::LOCK_EXCLUSIVE;
if ($mount1->getMountPoint() == $mount2->getMountPoint()) {
@ -943,7 +943,7 @@ class View {
$this->writeUpdate($storage2, $internalPath2);
$this->changeLock($path2, ILockingProvider::LOCK_SHARED);
$this->changeLock($target, ILockingProvider::LOCK_SHARED);
$lockTypePath2 = ILockingProvider::LOCK_SHARED;
if ($this->shouldEmitHooks() && $result !== false) {
@ -951,21 +951,21 @@ class View {
Filesystem::CLASSNAME,
Filesystem::signal_post_copy,
[
Filesystem::signal_param_oldpath => $this->getHookPath($path1),
Filesystem::signal_param_newpath => $this->getHookPath($path2)
Filesystem::signal_param_oldpath => $this->getHookPath($source),
Filesystem::signal_param_newpath => $this->getHookPath($target)
]
);
$this->emit_file_hooks_post($exists, $path2);
$this->emit_file_hooks_post($exists, $target);
}
}
} catch (\Exception $e) {
$this->unlockFile($path2, $lockTypePath2);
$this->unlockFile($path1, $lockTypePath1);
$this->unlockFile($target, $lockTypePath2);
$this->unlockFile($source, $lockTypePath1);
throw $e;
}
$this->unlockFile($path2, $lockTypePath2);
$this->unlockFile($path1, $lockTypePath1);
$this->unlockFile($target, $lockTypePath2);
$this->unlockFile($source, $lockTypePath1);
}
return $result;
}

@ -113,11 +113,11 @@ class NullStorage extends Common {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
public function rename($path1, $path2) {
public function rename($source, $target) {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}
public function copy($path1, $path2) {
public function copy($source, $target) {
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
}

@ -244,22 +244,22 @@ interface Storage extends IStorage {
/**
* see https://www.php.net/manual/en/function.rename.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
* @since 6.0.0
*/
public function rename($path1, $path2);
public function rename($source, $target);
/**
* see https://www.php.net/manual/en/function.copy.php
*
* @param string $path1
* @param string $path2
* @param string $soruce
* @param string $target
* @return bool
* @since 6.0.0
*/
public function copy($path1, $path2);
public function copy($source, $target);
/**
* see https://www.php.net/manual/en/function.fopen.php

@ -241,22 +241,22 @@ interface IStorage {
/**
* see https://www.php.net/manual/en/function.rename.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
* @since 9.0.0
*/
public function rename($path1, $path2);
public function rename($source, $target);
/**
* see https://www.php.net/manual/en/function.copy.php
*
* @param string $path1
* @param string $path2
* @param string $source
* @param string $target
* @return bool
* @since 9.0.0
*/
public function copy($path1, $path2);
public function copy($source, $target);
/**
* see https://www.php.net/manual/en/function.fopen.php

Loading…
Cancel
Save