diff options
author | Robin Appelman <robin@icewind.nl> | 2024-09-19 21:19:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-19 21:19:38 +0200 |
commit | 017951f8624aec4a337f32c7249009d5afa04da6 (patch) | |
tree | 2c66088766d6c7860d9f57ad4bfc82c0519107cc /lib | |
parent | c2170cf74ee6aad1717cafe383cb9c9295d986c2 (diff) | |
parent | b731f9533a673e6ba3dd8f16b8e5b4a033019e8c (diff) | |
download | nextcloud-server-017951f8624aec4a337f32c7249009d5afa04da6.tar.gz nextcloud-server-017951f8624aec4a337f32c7249009d5afa04da6.zip |
Merge pull request #48214 from nextcloud/backport/48205/stable29
[stable29] Ci fixes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 3 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/ObjectStoreStorage.php | 22 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/StorageObjectStore.php | 4 |
3 files changed, 19 insertions, 10 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 7f52935489d..0386aaa06df 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -298,6 +298,9 @@ class Cache implements ICache { if (!isset($data['parent'])) { $data['parent'] = $this->getParentId($file); } + if ($data['parent'] === -1 && $file !== '') { + throw new \Exception('Parent folder not in filecache for ' . $file); + } $data['name'] = basename($file); [$values, $extensionValues] = $this->normalizeData($data); diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 8b770ee19c5..423255e2c9a 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -485,13 +485,10 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil } public function file_put_contents($path, $data) { - $handle = $this->fopen($path, 'w+'); - if (!$handle) { - return false; - } - $result = fwrite($handle, $data); - fclose($handle); - return $result; + $fh = fopen('php://temp', 'w+'); + fwrite($fh, $data); + rewind($fh); + return $this->writeStream($path, $fh, strlen($data)); } public function writeStream(string $path, $stream, ?int $size = null): int { @@ -521,6 +518,10 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil if ($exists) { $fileId = $stat['fileid']; } else { + $parent = $this->normalizePath(dirname($path)); + if (!$this->is_dir($parent)) { + throw new \InvalidArgumentException("trying to upload a file ($path) inside a non-directory ($parent)"); + } $fileId = $this->getCache()->put($uploadPath, $stat); } @@ -623,15 +624,20 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil $sourceCacheEntry = $sourceCache->get($sourceInternalPath); } if ($sourceCacheEntry->getMimeType() === FileInfo::MIMETYPE_FOLDER) { + $this->mkdir($targetInternalPath); foreach ($sourceCache->getFolderContents($sourceInternalPath) as $child) { $this->moveFromStorage($sourceStorage, $child->getPath(), $targetInternalPath . '/' . $child->getName()); } $sourceStorage->rmdir($sourceInternalPath); } else { + $sourceStream = $sourceStorage->fopen($sourceInternalPath, 'r'); + if (!$sourceStream) { + return false; + } // move the cache entry before the contents so that we have the correct fileid/urn for the target $this->getCache()->moveFromCache($sourceCache, $sourceInternalPath, $targetInternalPath); try { - $this->writeStream($targetInternalPath, $sourceStorage->fopen($sourceInternalPath, 'r'), $sourceCacheEntry->getSize()); + $this->writeStream($targetInternalPath, $sourceStream, $sourceCacheEntry->getSize()); } catch (\Exception $e) { // restore the cache entry $sourceCache->moveFromCache($this->getCache(), $targetInternalPath, $sourceInternalPath); diff --git a/lib/private/Files/ObjectStore/StorageObjectStore.php b/lib/private/Files/ObjectStore/StorageObjectStore.php index d968adb3c29..b01a2ade7a0 100644 --- a/lib/private/Files/ObjectStore/StorageObjectStore.php +++ b/lib/private/Files/ObjectStore/StorageObjectStore.php @@ -45,8 +45,8 @@ class StorageObjectStore implements IObjectStore { * @return string the container or bucket name where objects are stored * @since 7.0.0 */ - public function getStorageId() { - $this->storage->getId(); + public function getStorageId(): string { + return $this->storage->getId(); } /** |