Skip to content

Commit

Permalink
Merge pull request #10624 from owncloud/set-chunking-version
Browse files Browse the repository at this point in the history
[tests-only][full-ci] refactor: Set chunking version 1 as default
  • Loading branch information
saw-jan authored Dec 13, 2024
2 parents 09536fa + e4a8365 commit fbf49a7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 314 deletions.
174 changes: 11 additions & 163 deletions tests/acceptance/TestHelpers/UploadHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class UploadHelper extends Assert {
* @param string|null $xRequestId
* @param array|null $headers
* @param int|null $davPathVersionToUse (1|2)
* @param int|null $chunkingVersion (1|2|null)
* if set to null chunking will not be used
* @param bool $doChunkUpload
* @param int|null $noOfChunks how many chunks to upload
* @param bool|null $isGivenStep
*
Expand All @@ -63,12 +62,11 @@ public static function upload(
?string $xRequestId = '',
?array $headers = [],
?int $davPathVersionToUse = 1,
?int $chunkingVersion = null,
bool $doChunkUpload = false,
?int $noOfChunks = 1,
?bool $isGivenStep = false
?bool $isGivenStep = false,
): ResponseInterface {
//simple upload with no chunking
if ($chunkingVersion === null) {
if (!$doChunkUpload) {
$data = \file_get_contents($source);
return WebDavHelper::makeDavRequest(
$baseUrl,
Expand All @@ -91,56 +89,16 @@ public static function upload(
null,
$isGivenStep
);
} else {
//prepare chunking
$chunks = self::chunkFile($source, $noOfChunks);
$chunkingId = 'chunking-' . \rand(1000, 9999);
$v2ChunksDestination = '/uploads/' . $user . '/' . $chunkingId;
}

//prepare chunking
$chunks = self::chunkFile($source, $noOfChunks);
$chunkingId = 'chunking-' . \rand(1000, 9999);
$result = null;

//prepare chunking version specific stuff
if ($chunkingVersion === 1) {
$headers['OC-Chunked'] = '1';
} elseif ($chunkingVersion === 2) {
$result = WebDavHelper::makeDavRequest(
$baseUrl,
$user,
$password,
'MKCOL',
$v2ChunksDestination,
$headers,
null,
$xRequestId,
null,
$davPathVersionToUse,
"uploads",
null,
"basic",
false,
0,
null,
[],
null,
$isGivenStep
);
if ($result->getStatusCode() >= 400) {
return $result;
}
}

//upload chunks
foreach ($chunks as $index => $chunk) {
if ($chunkingVersion === 1) {
$filename = $destination . "-" . $chunkingId . "-" .
\count($chunks) . '-' . $index;
$davRequestType = "files";
} else {
// do chunking version 2
$filename = $v2ChunksDestination . '/' . $index;
$davRequestType = "uploads";
}
$filename = $destination . "-" . $chunkingId . "-" . \count($chunks) . '-' . $index;
$result = WebDavHelper::makeDavRequest(
$baseUrl,
$user,
Expand All @@ -152,38 +110,7 @@ public static function upload(
$xRequestId,
$chunk,
$davPathVersionToUse,
$davRequestType,
null,
"basic",
false,
0,
null,
[],
null,
$isGivenStep
);
if ($result->getStatusCode() >= 400) {
return $result;
}
}
//finish upload for new chunking
if ($chunkingVersion === 2) {
$source = $v2ChunksDestination . '/.file';
$headers['Destination'] = $baseUrl . "/" .
WebDavHelper::getDavPath($davPathVersionToUse, $user) .
$destination;
$result = WebDavHelper::makeDavRequest(
$baseUrl,
$user,
$password,
'MOVE',
$source,
$headers,
null,
$xRequestId,
null,
$davPathVersionToUse,
"uploads",
"files",
null,
"basic",
false,
Expand All @@ -197,88 +124,9 @@ public static function upload(
return $result;
}
}
self::assertNotNull($result, __METHOD__ . " chunking version $chunkingVersion was requested but no upload was done.");
return $result;
}

/**
* Upload the same file multiple times with different mechanisms.
*
* @param string|null $baseUrl URL of owncloud
* @param string|null $user user who uploads
* @param string|null $password
* @param string|null $source source file path
* @param string|null $destination destination path on the server
* @param string|null $xRequestId
* @param bool $overwriteMode when false creates separate files to test uploading brand-new files,
* when true it just overwrites the same file over and over again with the same name
* @param string|null $exceptChunkingType empty string or "old" or "new"
*
* @return array of ResponseInterface
* @throws GuzzleException
*/
public static function uploadWithAllMechanisms(
?string $baseUrl,
?string $user,
?string $password,
?string $source,
?string $destination,
?string $xRequestId = '',
?bool $overwriteMode = false,
?string $exceptChunkingType = ''
):array {
$responses = [];
foreach ([1, 2] as $davPathVersion) {
if ($davPathVersion === 1) {
$davHuman = 'old';
} else {
$davHuman = 'new';
}

switch ($exceptChunkingType) {
case 'old':
$exceptChunkingVersion = 1;
break;
case 'new':
$exceptChunkingVersion = 2;
break;
default:
$exceptChunkingVersion = -1;
break;
}

foreach ([null, 1, 2] as $chunkingVersion) {
if ($chunkingVersion === $exceptChunkingVersion) {
continue;
}
$valid = WebDavHelper::isValidDavChunkingCombination(
$davPathVersion,
$chunkingVersion
);
if ($valid === false) {
continue;
}
$finalDestination = $destination;
if (!$overwriteMode && $chunkingVersion !== null) {
$finalDestination .= "-{$davHuman}dav-{$davHuman}chunking";
} elseif (!$overwriteMode && $chunkingVersion === null) {
$finalDestination .= "-{$davHuman}dav-regular";
}
$responses[] = self::upload(
$baseUrl,
$user,
$password,
$source,
$finalDestination,
$xRequestId,
[],
$davPathVersion,
$chunkingVersion,
2
);
}
}
return $responses;
self::assertNotNull($result, __METHOD__ . " chunking was requested but no upload was done.");
return $result;
}

/**
Expand Down
28 changes: 0 additions & 28 deletions tests/acceptance/TestHelpers/WebDavHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,34 +816,6 @@ public static function sanitizeUrl(?string $url, ?bool $trailingSlash = false):s
return \preg_replace("/([^:]\/)\/+/", '$1', $url);
}

/**
* Decides if the proposed dav version and chunking version are
* a valid combination.
* If no chunkingVersion is specified, then any dav version is valid.
* If a chunkingVersion is specified, then it has to match the dav version.
* Note: in future, the dav and chunking versions might or might not
* move together and/or be supported together. So a more complex
* matrix could be needed here.
*
* @param string|int $davPathVersion
* @param string|int|null $chunkingVersion
*
* @return boolean is this a valid combination
*/
public static function isValidDavChunkingCombination(
$davPathVersion,
$chunkingVersion
): bool {
if ($davPathVersion === self::DAV_VERSION_SPACES) {
// allow only old chunking version when using the spaces dav
return $chunkingVersion === 1;
}
return (
($chunkingVersion === 'no' || $chunkingVersion === null) ||
($davPathVersion === $chunkingVersion)
);
}

/**
* get Mtime of File in a public link share
*
Expand Down
Loading

0 comments on commit fbf49a7

Please sign in to comment.