Skip to content

Commit e1ed2db

Browse files
committed
Merge #247 [backport25] S3 Multipart turbo upload
2 parents 336924a + c684599 commit e1ed2db

33 files changed

+1069
-31
lines changed

apps/dav/composer/composer/autoload_classmap.php

+3
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@
297297
'OCA\\DAV\\Search\\EventsSearchProvider' => $baseDir . '/../lib/Search/EventsSearchProvider.php',
298298
'OCA\\DAV\\Search\\TasksSearchProvider' => $baseDir . '/../lib/Search/TasksSearchProvider.php',
299299
'OCA\\DAV\\Server' => $baseDir . '/../lib/Server.php',
300+
'OCA\\DAV\\Service\\CustomPropertiesService' => $baseDir . '/../lib/Service/CustomPropertiesService.php',
300301
'OCA\\DAV\\Settings\\AvailabilitySettings' => $baseDir . '/../lib/Settings/AvailabilitySettings.php',
301302
'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php',
302303
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => $baseDir . '/../lib/Storage/PublicOwnerWrapper.php',
@@ -311,8 +312,10 @@
311312
'OCA\\DAV\\Traits\\PrincipalProxyTrait' => $baseDir . '/../lib/Traits/PrincipalProxyTrait.php',
312313
'OCA\\DAV\\Upload\\AssemblyStream' => $baseDir . '/../lib/Upload/AssemblyStream.php',
313314
'OCA\\DAV\\Upload\\ChunkingPlugin' => $baseDir . '/../lib/Upload/ChunkingPlugin.php',
315+
'OCA\\DAV\\Upload\\ChunkingV2Plugin' => $baseDir . '/../lib/Upload/ChunkingV2Plugin.php',
314316
'OCA\\DAV\\Upload\\CleanupService' => $baseDir . '/../lib/Upload/CleanupService.php',
315317
'OCA\\DAV\\Upload\\FutureFile' => $baseDir . '/../lib/Upload/FutureFile.php',
318+
'OCA\\DAV\\Upload\\PartFile' => $baseDir . '/../lib/Upload/PartFile.php',
316319
'OCA\\DAV\\Upload\\RootCollection' => $baseDir . '/../lib/Upload/RootCollection.php',
317320
'OCA\\DAV\\Upload\\UploadFile' => $baseDir . '/../lib/Upload/UploadFile.php',
318321
'OCA\\DAV\\Upload\\UploadFolder' => $baseDir . '/../lib/Upload/UploadFolder.php',

apps/dav/composer/composer/autoload_static.php

+3
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ class ComposerStaticInitDAV
312312
'OCA\\DAV\\Search\\EventsSearchProvider' => __DIR__ . '/..' . '/../lib/Search/EventsSearchProvider.php',
313313
'OCA\\DAV\\Search\\TasksSearchProvider' => __DIR__ . '/..' . '/../lib/Search/TasksSearchProvider.php',
314314
'OCA\\DAV\\Server' => __DIR__ . '/..' . '/../lib/Server.php',
315+
'OCA\\DAV\\Service\\CustomPropertiesService' => __DIR__ . '/..' . '/../lib/Service/CustomPropertiesService.php',
315316
'OCA\\DAV\\Settings\\AvailabilitySettings' => __DIR__ . '/..' . '/../lib/Settings/AvailabilitySettings.php',
316317
'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php',
317318
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => __DIR__ . '/..' . '/../lib/Storage/PublicOwnerWrapper.php',
@@ -326,8 +327,10 @@ class ComposerStaticInitDAV
326327
'OCA\\DAV\\Traits\\PrincipalProxyTrait' => __DIR__ . '/..' . '/../lib/Traits/PrincipalProxyTrait.php',
327328
'OCA\\DAV\\Upload\\AssemblyStream' => __DIR__ . '/..' . '/../lib/Upload/AssemblyStream.php',
328329
'OCA\\DAV\\Upload\\ChunkingPlugin' => __DIR__ . '/..' . '/../lib/Upload/ChunkingPlugin.php',
330+
'OCA\\DAV\\Upload\\ChunkingV2Plugin' => __DIR__ . '/..' . '/../lib/Upload/ChunkingV2Plugin.php',
329331
'OCA\\DAV\\Upload\\CleanupService' => __DIR__ . '/..' . '/../lib/Upload/CleanupService.php',
330332
'OCA\\DAV\\Upload\\FutureFile' => __DIR__ . '/..' . '/../lib/Upload/FutureFile.php',
333+
'OCA\\DAV\\Upload\\PartFile' => __DIR__ . '/..' . '/../lib/Upload/PartFile.php',
331334
'OCA\\DAV\\Upload\\RootCollection' => __DIR__ . '/..' . '/../lib/Upload/RootCollection.php',
332335
'OCA\\DAV\\Upload\\UploadFile' => __DIR__ . '/..' . '/../lib/Upload/UploadFile.php',
333336
'OCA\\DAV\\Upload\\UploadFolder' => __DIR__ . '/..' . '/../lib/Upload/UploadFolder.php',

apps/dav/lib/BackgroundJob/UploadCleanup.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
namespace OCA\DAV\BackgroundJob;
2929

3030
use OC\User\NoUserException;
31+
use OCA\DAV\Service\CustomPropertiesService;
3132
use OCP\AppFramework\Utility\ITimeFactory;
3233
use OCP\BackgroundJob\IJob;
3334
use OCP\BackgroundJob\IJobList;
@@ -42,12 +43,14 @@
4243
class UploadCleanup extends TimedJob {
4344
private IRootFolder $rootFolder;
4445
private IJobList $jobList;
46+
private CustomPropertiesService $customPropertiesService;
4547
private LoggerInterface $logger;
4648

47-
public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList, LoggerInterface $logger) {
49+
public function __construct(ITimeFactory $time, IRootFolder $rootFolder, IJobList $jobList, CustomPropertiesService $customPropertiesService, LoggerInterface $logger) {
4850
parent::__construct($time);
4951
$this->rootFolder = $rootFolder;
5052
$this->jobList = $jobList;
53+
$this->customPropertiesService = $customPropertiesService;
5154
$this->logger = $logger;
5255

5356
// Run once a day
@@ -70,6 +73,10 @@ protected function run($argument) {
7073
return;
7174
}
7275

76+
$files = $uploadFolder->getDirectoryListing();
77+
78+
$davPath = 'uploads/' . $uid . '/' . $uploadFolder->getName();
79+
7380
// Remove if all files have an mtime of more than a day
7481
$time = $this->time->getTime() - 60 * 60 * 24;
7582

@@ -93,6 +100,7 @@ protected function run($argument) {
93100
}, $initial);
94101

95102
if ($expire) {
103+
$this->customPropertiesService->delete($uid, $davPath);
96104
$uploadFolder->delete();
97105
$this->jobList->remove(self::class, $argument);
98106
}

apps/dav/lib/Capabilities.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(IConfig $config) {
3636
public function getCapabilities() {
3737
$capabilities = [
3838
'dav' => [
39-
'chunking' => '1.0',
39+
'chunking' => '2.0'
4040
]
4141
];
4242
if ($this->config->getSystemValueBool('bulkupload.enabled', true)) {

apps/dav/lib/Connector/Sabre/Directory.php

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
4040
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
4141
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
42+
use OCA\DAV\Upload\FutureFile;
4243
use OCP\Files\FileInfo;
4344
use OCP\Files\Folder;
4445
use OCP\Files\ForbiddenException;

apps/dav/lib/Connector/Sabre/Node.php

+8
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ public function getInternalFileId() {
269269
return $this->info->getId();
270270
}
271271

272+
public function getInternalPath(): string {
273+
return $this->info->getInternalPath();
274+
}
275+
276+
public function getAbsoluteInternalPath(): string {
277+
return $this->info->getPath();
278+
}
279+
272280
/**
273281
* @param string $user
274282
* @return int

apps/dav/lib/Connector/Sabre/ServerFactory.php

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use OCA\DAV\AppInfo\PluginManager;
3636
use OCA\DAV\DAV\ViewOnlyPlugin;
3737
use OCA\DAV\Files\BrowserErrorPagePlugin;
38+
use OCA\DAV\Service\CustomPropertiesService;
3839
use OCP\Files\Mount\IMountManager;
3940
use OCP\IConfig;
4041
use OCP\IDBConnection;
@@ -190,6 +191,7 @@ public function createServer(string $baseUri,
190191
new \OCA\DAV\DAV\CustomPropertiesBackend(
191192
$objectTree,
192193
$this->databaseConnection,
194+
\OC::$server->get(CustomPropertiesService::class),
193195
$this->userSession->getUser()
194196
)
195197
)

apps/dav/lib/DAV/CustomPropertiesBackend.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Exception;
2929
use OCA\DAV\Connector\Sabre\Directory;
3030
use OCP\DB\QueryBuilder\IQueryBuilder;
31+
use OCA\DAV\Service\CustomPropertiesService;
3132
use OCP\IDBConnection;
3233
use OCP\IUser;
3334
use Sabre\DAV\PropertyStorage\Backend\BackendInterface;
@@ -116,6 +117,11 @@ class CustomPropertiesBackend implements BackendInterface {
116117
*/
117118
private $connection;
118119

120+
/**
121+
* @var CustomPropertiesService
122+
*/
123+
private $customPropertiesService;
124+
119125
/**
120126
* @var IUser
121127
*/
@@ -136,10 +142,12 @@ class CustomPropertiesBackend implements BackendInterface {
136142
public function __construct(
137143
Tree $tree,
138144
IDBConnection $connection,
145+
CustomPropertiesService $customPropertiesService,
139146
IUser $user
140147
) {
141148
$this->tree = $tree;
142149
$this->connection = $connection;
150+
$this->customPropertiesService = $customPropertiesService;
143151
$this->user = $user;
144152
}
145153

@@ -218,12 +226,7 @@ public function propPatch($path, PropPatch $propPatch) {
218226
* @param string $path path of node for which to delete properties
219227
*/
220228
public function delete($path) {
221-
$statement = $this->connection->prepare(
222-
'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'
223-
);
224-
$statement->execute([$this->user->getUID(), $this->formatPath($path)]);
225-
$statement->closeCursor();
226-
229+
$this->customPropertiesService->delete($this->user->getUID(), $path);
227230
unset($this->userCache[$path]);
228231
}
229232

apps/dav/lib/Server.php

+4
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@
6868
use OCA\DAV\Files\LazySearchBackend;
6969
use OCA\DAV\Profiler\ProfilerPlugin;
7070
use OCA\DAV\Provisioning\Apple\AppleProvisioningPlugin;
71+
use OCA\DAV\Service\CustomPropertiesService;
7172
use OCA\DAV\SystemTag\SystemTagPlugin;
7273
use OCA\DAV\Upload\ChunkingPlugin;
7374
use OCP\AppFramework\Http\Response;
7475
use OCP\Diagnostics\IEventLogger;
76+
use OCA\DAV\Upload\ChunkingV2Plugin;
7577
use OCP\EventDispatcher\IEventDispatcher;
7678
use OCP\IRequest;
7779
use OCP\Profiler\IProfiler;
@@ -215,6 +217,7 @@ public function __construct(IRequest $request, string $baseUri) {
215217

216218
$this->server->addPlugin(new CopyEtagHeaderPlugin());
217219
$this->server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class)));
220+
$this->server->addPlugin(new ChunkingV2Plugin());
218221
$this->server->addPlugin(new ChunkingPlugin());
219222

220223
// allow setup of additional plugins
@@ -267,6 +270,7 @@ public function __construct(IRequest $request, string $baseUri) {
267270
new CustomPropertiesBackend(
268271
$this->server->tree,
269272
\OC::$server->getDatabaseConnection(),
273+
\OC::$server->get(CustomPropertiesService::class),
270274
\OC::$server->getUserSession()->getUser()
271275
)
272276
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/*
3+
* @copyright Copyright (c) 2021 Julius Härtl <jus@bitgrid.net>
4+
*
5+
* @author Julius Härtl <jus@bitgrid.net>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
declare(strict_types=1);
25+
26+
27+
namespace OCA\DAV\Service;
28+
29+
use OCP\IDBConnection;
30+
31+
class CustomPropertiesService {
32+
33+
/** @var IDBConnection */
34+
private $connection;
35+
36+
public function __construct(IDBConnection $connection) {
37+
$this->connection = $connection;
38+
}
39+
40+
public function delete(string $userId, string $path): void {
41+
$statement = $this->connection->prepare(
42+
'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'
43+
);
44+
$result = $statement->execute([$userId, $this->formatPath($path)]);
45+
$result->closeCursor();
46+
}
47+
48+
/**
49+
* long paths are hashed to ensure they fit in the database
50+
*
51+
* @param string $path
52+
* @return string
53+
*/
54+
private function formatPath(string $path): string {
55+
if (strlen($path) > 250) {
56+
return sha1($path);
57+
}
58+
return $path;
59+
}
60+
}

0 commit comments

Comments
 (0)