Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apps/dav/lib/Connector/Sabre/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public function put($data) {
}
}

$lengthHeader = $this->request->getHeader('content-length');
$expected = $lengthHeader !== '' ? (int)$lengthHeader : null;

if ($partStorage->instanceOfStorage(IWriteStreamStorage::class)) {
$isEOF = false;
$wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF): void {
Expand All @@ -212,7 +215,7 @@ public function put($data) {
$count = -1;
try {
/** @var IWriteStreamStorage $partStorage */
$count = $partStorage->writeStream($internalPartPath, $wrappedData);
$count = $partStorage->writeStream($internalPartPath, $wrappedData, $expected);
} catch (GenericFileException $e) {
$logger = Server::get(LoggerInterface::class);
$logger->error('Error while writing stream to storage: ' . $e->getMessage(), ['exception' => $e, 'app' => 'webdav']);
Expand All @@ -232,10 +235,7 @@ public function put($data) {
[$count, $result] = \OC_Helper::streamCopy($data, $target);
fclose($target);
}

$lengthHeader = $this->request->getHeader('content-length');
$expected = $lengthHeader !== '' ? (int)$lengthHeader : -1;
if ($result === false && $expected >= 0) {
if ($result === false && $expected !== null) {
throw new Exception(
$this->l10n->t(
'Error while copying file to target location (copied: %1$s, expected filesize: %2$s)',
Expand All @@ -250,7 +250,7 @@ public function put($data) {
// if content length is sent by client:
// double check if the file was fully received
// compare expected and actual size
if ($expected >= 0
if ($expected !== null
&& $expected !== $count
&& $this->request->getMethod() === 'PUT'
) {
Expand Down
2 changes: 1 addition & 1 deletion apps/files_external/3rdparty/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
},
"require": {
"icewind/smb": "3.7.0",
"icewind/streams": "0.7.7"
"icewind/streams": "0.7.8"
}
}
20 changes: 5 additions & 15 deletions apps/files_external/3rdparty/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions apps/files_external/3rdparty/composer/InstalledVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class InstalledVersions
*/
private static $installed;

/**
* @var bool
*/
private static $installedIsLocalDir;

/**
* @var bool|null
*/
Expand Down Expand Up @@ -309,6 +314,12 @@ public static function reload($data)
{
self::$installed = $data;
self::$installedByVendor = array();

// when using reload, we disable the duplicate protection to ensure that self::$installed data is
// always returned, but we cannot know whether it comes from the installed.php in __DIR__ or not,
// so we have to assume it does not, and that may result in duplicate data being returned when listing
// all installed packages for example
self::$installedIsLocalDir = false;
}

/**
Expand All @@ -322,19 +333,27 @@ private static function getInstalled()
}

$installed = array();
$copiedLocalDir = false;

if (self::$canGetVendors) {
$selfDir = strtr(__DIR__, '\\', '/');
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
$vendorDir = strtr($vendorDir, '\\', '/');
if (isset(self::$installedByVendor[$vendorDir])) {
$installed[] = self::$installedByVendor[$vendorDir];
} elseif (is_file($vendorDir.'/composer/installed.php')) {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require $vendorDir.'/composer/installed.php';
$installed[] = self::$installedByVendor[$vendorDir] = $required;
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
self::$installed = $installed[count($installed) - 1];
self::$installedByVendor[$vendorDir] = $required;
$installed[] = $required;
if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
self::$installed = $required;
self::$installedIsLocalDir = true;
}
}
if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
$copiedLocalDir = true;
}
}
}

Expand All @@ -350,7 +369,7 @@ private static function getInstalled()
}
}

if (self::$installed !== array()) {
if (self::$installed !== array() && !$copiedLocalDir) {
$installed[] = self::$installed;
}

Expand Down
22 changes: 6 additions & 16 deletions apps/files_external/3rdparty/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,12 @@
},
{
"name": "icewind/streams",
"version": "v0.7.7",
"version_normalized": "0.7.7.0",
"version": "v0.7.8",
"version_normalized": "0.7.8.0",
"source": {
"type": "git",
"url": "https://github.com/icewind1991/Streams.git",
"reference": "64200fd7cfcc7f550c3c695c48d8fd8bba97fecb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/icewind1991/Streams/zipball/64200fd7cfcc7f550c3c695c48d8fd8bba97fecb",
"reference": "64200fd7cfcc7f550c3c695c48d8fd8bba97fecb",
"shasum": ""
"url": "https://codeberg.org/icewind/streams",
"reference": "cb2bd3ed41b516efb97e06e8da35a12ef58ba48b"
},
"require": {
"php": ">=7.1"
Expand All @@ -73,9 +67,9 @@
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^9"
},
"time": "2023-03-16T14:52:25+00:00",
"time": "2024-12-05T14:36:22+00:00",
"type": "library",
"installation-source": "dist",
"installation-source": "source",
"autoload": {
"psr-4": {
"Icewind\\Streams\\": "src/"
Expand All @@ -92,10 +86,6 @@
}
],
"description": "A set of generic stream wrappers",
"support": {
"issues": "https://github.com/icewind1991/Streams/issues",
"source": "https://github.com/icewind1991/Streams/tree/v0.7.7"
},
"install-path": "../icewind/streams"
}
],
Expand Down
10 changes: 5 additions & 5 deletions apps/files_external/3rdparty/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'files_external/3rdparty',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '101c7575ae7684a572e53740c63635cd12685995',
'reference' => '05e64418a77134e55824fc8c1a91125805428f3f',
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'files_external/3rdparty' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '101c7575ae7684a572e53740c63635cd12685995',
'reference' => '05e64418a77134e55824fc8c1a91125805428f3f',
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
Expand All @@ -29,9 +29,9 @@
'dev_requirement' => false,
),
'icewind/streams' => array(
'pretty_version' => 'v0.7.7',
'version' => '0.7.7.0',
'reference' => '64200fd7cfcc7f550c3c695c48d8fd8bba97fecb',
'pretty_version' => 'v0.7.8',
'version' => '0.7.8.0',
'reference' => 'cb2bd3ed41b516efb97e06e8da35a12ef58ba48b',
'type' => 'library',
'install_path' => __DIR__ . '/../icewind/streams',
'aliases' => array(),
Expand Down
11 changes: 11 additions & 0 deletions apps/files_external/3rdparty/icewind/streams/src/CountWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ protected function open() {
return true;
}

public function stream_seek($offset, $whence = SEEK_SET) {
if ($whence === SEEK_SET) {
$this->readCount = $offset;
$this->writeCount = $offset;
} else if ($whence === SEEK_CUR) {
$this->readCount += $offset;
$this->writeCount += $offset;
}
return parent::stream_seek($offset, $whence);
}

public function dir_opendir($path, $options) {
return $this->open();
}
Expand Down
9 changes: 9 additions & 0 deletions lib/private/Files/ObjectStore/IObjectStoreMetaData.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ public function getObjectMetaData(string $urn): array;
* @since 32.0.0
*/
public function listObjects(string $prefix = ''): \Iterator;

/**
* @param string $urn the unified resource name used to identify the object
* @param resource $stream stream with the data to write
* @param ObjectMetaData $metaData the metadata to set for the object
* @throws \Exception when something goes wrong, message will be logged
* @since 32.0.0
*/
public function writeObjectWithMetaData(string $urn, $stream, array $metaData): void;
}
37 changes: 23 additions & 14 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,12 @@ public function writeStream(string $path, $stream, ?int $size = null): int {

$mimetypeDetector = \OC::$server->getMimeTypeDetector();
$mimetype = $mimetypeDetector->detectPath($path);
$metadata = [
'mimetype' => $mimetype,
];
if ($size) {
$metadata['size'] = $size;
}

$stat['mimetype'] = $mimetype;
$stat['etag'] = $this->getETag($path);
Expand All @@ -500,24 +506,27 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
$urn = $this->getURN($fileId);
try {
//upload to object storage
if ($size === null) {
$countStream = CountWrapper::wrap($stream, function ($writtenSize) use ($fileId, &$size) {

$totalWritten = 0;
$countStream = CountWrapper::wrap($stream, function ($writtenSize) use ($fileId, $size, $exists, &$totalWritten) {
if (is_null($size) && !$exists) {
$this->getCache()->update($fileId, [
'size' => $writtenSize,
]);
$size = $writtenSize;
});
$this->objectStore->writeObject($urn, $countStream, $mimetype);
if (is_resource($countStream)) {
fclose($countStream);
}
$stat['size'] = $size;
$totalWritten = $writtenSize;
});

if ($this->objectStore instanceof IObjectStoreMetaData) {
$this->objectStore->writeObjectWithMetaData($urn, $countStream, $metadata);
} else {
$this->objectStore->writeObject($urn, $stream, $mimetype);
if (is_resource($stream)) {
fclose($stream);
}
$this->objectStore->writeObject($urn, $countStream, $metadata['mimetype']);
}
if (is_resource($countStream)) {
fclose($countStream);
}

$stat['size'] = $totalWritten;
} catch (\Exception $ex) {
if (!$exists) {
/*
Expand All @@ -541,7 +550,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
]
);
}
throw $ex; // make this bubble up
throw new GenericFileException('Error while writing stream to object store', 0, $ex);
}

if ($exists) {
Expand All @@ -557,7 +566,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
}
}

return $size;
return $totalWritten;
}

public function getObjectStore(): IObjectStore {
Expand Down
Loading
Loading