Skip to content

Commit 132e2c6

Browse files
committed
Merge #247 [backport25] S3 Multipart turbo upload
2 parents 5f3310f + 6b96928 commit 132e2c6

33 files changed

+1077
-31
lines changed

apps/dav/composer/composer/autoload_classmap.php

+3
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@
294294
'OCA\\DAV\\Search\\EventsSearchProvider' => $baseDir . '/../lib/Search/EventsSearchProvider.php',
295295
'OCA\\DAV\\Search\\TasksSearchProvider' => $baseDir . '/../lib/Search/TasksSearchProvider.php',
296296
'OCA\\DAV\\Server' => $baseDir . '/../lib/Server.php',
297+
'OCA\\DAV\\Service\\CustomPropertiesService' => $baseDir . '/../lib/Service/CustomPropertiesService.php',
297298
'OCA\\DAV\\Settings\\AvailabilitySettings' => $baseDir . '/../lib/Settings/AvailabilitySettings.php',
298299
'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php',
299300
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => $baseDir . '/../lib/Storage/PublicOwnerWrapper.php',
@@ -307,8 +308,10 @@
307308
'OCA\\DAV\\Traits\\PrincipalProxyTrait' => $baseDir . '/../lib/Traits/PrincipalProxyTrait.php',
308309
'OCA\\DAV\\Upload\\AssemblyStream' => $baseDir . '/../lib/Upload/AssemblyStream.php',
309310
'OCA\\DAV\\Upload\\ChunkingPlugin' => $baseDir . '/../lib/Upload/ChunkingPlugin.php',
311+
'OCA\\DAV\\Upload\\ChunkingV2Plugin' => $baseDir . '/../lib/Upload/ChunkingV2Plugin.php',
310312
'OCA\\DAV\\Upload\\CleanupService' => $baseDir . '/../lib/Upload/CleanupService.php',
311313
'OCA\\DAV\\Upload\\FutureFile' => $baseDir . '/../lib/Upload/FutureFile.php',
314+
'OCA\\DAV\\Upload\\PartFile' => $baseDir . '/../lib/Upload/PartFile.php',
312315
'OCA\\DAV\\Upload\\RootCollection' => $baseDir . '/../lib/Upload/RootCollection.php',
313316
'OCA\\DAV\\Upload\\UploadFile' => $baseDir . '/../lib/Upload/UploadFile.php',
314317
'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
@@ -309,6 +309,7 @@ class ComposerStaticInitDAV
309309
'OCA\\DAV\\Search\\EventsSearchProvider' => __DIR__ . '/..' . '/../lib/Search/EventsSearchProvider.php',
310310
'OCA\\DAV\\Search\\TasksSearchProvider' => __DIR__ . '/..' . '/../lib/Search/TasksSearchProvider.php',
311311
'OCA\\DAV\\Server' => __DIR__ . '/..' . '/../lib/Server.php',
312+
'OCA\\DAV\\Service\\CustomPropertiesService' => __DIR__ . '/..' . '/../lib/Service/CustomPropertiesService.php',
312313
'OCA\\DAV\\Settings\\AvailabilitySettings' => __DIR__ . '/..' . '/../lib/Settings/AvailabilitySettings.php',
313314
'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php',
314315
'OCA\\DAV\\Storage\\PublicOwnerWrapper' => __DIR__ . '/..' . '/../lib/Storage/PublicOwnerWrapper.php',
@@ -322,8 +323,10 @@ class ComposerStaticInitDAV
322323
'OCA\\DAV\\Traits\\PrincipalProxyTrait' => __DIR__ . '/..' . '/../lib/Traits/PrincipalProxyTrait.php',
323324
'OCA\\DAV\\Upload\\AssemblyStream' => __DIR__ . '/..' . '/../lib/Upload/AssemblyStream.php',
324325
'OCA\\DAV\\Upload\\ChunkingPlugin' => __DIR__ . '/..' . '/../lib/Upload/ChunkingPlugin.php',
326+
'OCA\\DAV\\Upload\\ChunkingV2Plugin' => __DIR__ . '/..' . '/../lib/Upload/ChunkingV2Plugin.php',
325327
'OCA\\DAV\\Upload\\CleanupService' => __DIR__ . '/..' . '/../lib/Upload/CleanupService.php',
326328
'OCA\\DAV\\Upload\\FutureFile' => __DIR__ . '/..' . '/../lib/Upload/FutureFile.php',
329+
'OCA\\DAV\\Upload\\PartFile' => __DIR__ . '/..' . '/../lib/Upload/PartFile.php',
327330
'OCA\\DAV\\Upload\\RootCollection' => __DIR__ . '/..' . '/../lib/Upload/RootCollection.php',
328331
'OCA\\DAV\\Upload\\UploadFile' => __DIR__ . '/..' . '/../lib/Upload/UploadFile.php',
329332
'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
@@ -266,6 +266,14 @@ public function getInternalFileId() {
266266
return $this->info->getId();
267267
}
268268

269+
public function getInternalPath(): string {
270+
return $this->info->getInternalPath();
271+
}
272+
273+
public function getAbsoluteInternalPath(): string {
274+
return $this->info->getPath();
275+
}
276+
269277
/**
270278
* @param string $user
271279
* @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
@@ -26,6 +26,7 @@
2626

2727
use Exception;
2828
use OCP\DB\QueryBuilder\IQueryBuilder;
29+
use OCA\DAV\Service\CustomPropertiesService;
2930
use OCP\IDBConnection;
3031
use OCP\IUser;
3132
use Sabre\DAV\PropertyStorage\Backend\BackendInterface;
@@ -114,6 +115,11 @@ class CustomPropertiesBackend implements BackendInterface {
114115
*/
115116
private $connection;
116117

118+
/**
119+
* @var CustomPropertiesService
120+
*/
121+
private $customPropertiesService;
122+
117123
/**
118124
* @var IUser
119125
*/
@@ -134,9 +140,11 @@ class CustomPropertiesBackend implements BackendInterface {
134140
public function __construct(
135141
Tree $tree,
136142
IDBConnection $connection,
143+
CustomPropertiesService $customPropertiesService,
137144
IUser $user) {
138145
$this->tree = $tree;
139146
$this->connection = $connection;
147+
$this->customPropertiesService = $customPropertiesService;
140148
$this->user = $user;
141149
}
142150

@@ -210,12 +218,7 @@ public function propPatch($path, PropPatch $propPatch) {
210218
* @param string $path path of node for which to delete properties
211219
*/
212220
public function delete($path) {
213-
$statement = $this->connection->prepare(
214-
'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'
215-
);
216-
$statement->execute([$this->user->getUID(), $this->formatPath($path)]);
217-
$statement->closeCursor();
218-
221+
$this->customPropertiesService->delete($this->user->getUID(), $path);
219222
unset($this->userCache[$path]);
220223
}
221224

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)