Skip to content

Commit b0c7fb4

Browse files
committed
Wrap-up changes for updated subfolders
When a subfolder is updated, the changes were not saved. Changed folders are now tracked and changes metadata update are done for the all the changed folders instead of the top one. Signed-off-by: Louis Chemineau <[email protected]>
1 parent 47f2d4a commit b0c7fb4

File tree

7 files changed

+65
-9
lines changed

7 files changed

+65
-9
lines changed

lib/Controller/LockingController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,14 @@ public function unlockFolder(int $id, ?string $shareToken = null): DataResponse
151151
throw new OCSForbiddenException($this->l10n->t('You are not allowed to remove the lock'));
152152
}
153153

154-
$this->fileService->finalizeChanges($nodes[0]);
154+
$touchFoldersIds = $this->metaDataStorage->getTouchedFolders($token);
155+
foreach ($touchFoldersIds as $folderId) {
156+
$this->fileService->finalizeChanges($userFolder->getById($folderId)[0]);
155157

156-
$this->metaDataStorage->saveIntermediateFile($ownerId, $id);
158+
$this->metaDataStorage->saveIntermediateFile($ownerId, $folderId);
159+
}
160+
161+
$this->metaDataStorage->clearTouchedFolders($token);
157162

158163
try {
159164
$this->lockManager->unlockFile($id, $token);

lib/Controller/MetaDataController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function updateMetaData(int $id, string $metaData): DataResponse {
136136
}
137137

138138
try {
139-
$this->metaDataStorage->updateMetaDataIntoIntermediateFile($this->userId, $id, $metaData);
139+
$this->metaDataStorage->updateMetaDataIntoIntermediateFile($this->userId, $id, $metaData, $e2eToken);
140140
} catch (MissingMetaDataException $e) {
141141
throw new OCSNotFoundException($this->l10n->t('Metadata-file does not exist'));
142142
} catch (NotFoundException $e) {
@@ -201,7 +201,7 @@ public function addMetadataFileDrop(int $id, string $fileDrop, ?string $shareTok
201201
$decodedMetadata['filedrop'] = array_merge($decodedMetadata['filedrop'] ?? [], $decodedFileDrop);
202202
$encodedMetadata = json_encode($decodedMetadata);
203203

204-
$this->metaDataStorage->updateMetaDataIntoIntermediateFile($ownerId, $id, $encodedMetadata);
204+
$this->metaDataStorage->updateMetaDataIntoIntermediateFile($ownerId, $id, $encodedMetadata, $e2eToken);
205205
} catch (MissingMetaDataException $e) {
206206
throw new OCSNotFoundException($this->l10n->t('Metadata-file does not exist'));
207207
} catch (NotFoundException $e) {

lib/FileService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function revertChanges(Folder $folder): bool {
5656
}
5757

5858
/**
59-
* @return bool Whether this operation changed any files
59+
* @return bool Move and delete temporary files suffixed by .e2e-to-save and .e2e-to-delete
6060
*/
6161
public function finalizeChanges(Folder $folder): bool {
6262
$intermediateFiles = $this->getIntermediateFiles($folder);

lib/IMetaDataStorage.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function setMetaDataIntoIntermediateFile(string $userId, int $id, string
5858
* @throws NotFoundException
5959
* @throws MissingMetaDataException
6060
*/
61-
public function updateMetaDataIntoIntermediateFile(string $userId, int $id, string $fileKey): void;
61+
public function updateMetaDataIntoIntermediateFile(string $userId, int $id, string $fileKey, string $token = null): void;
6262

6363
/**
6464
* Moves intermediate metadata file to final file
@@ -84,4 +84,22 @@ public function deleteIntermediateFile(string $userId, int $id): void;
8484
* @throws NotFoundException
8585
*/
8686
public function deleteMetaData(string $userId, int $id): void;
87+
88+
/**
89+
* Return the list of folders marked as touched.
90+
*
91+
* @return int[]
92+
*
93+
* @throws NotPermittedException
94+
* @throws NotFoundException
95+
*/
96+
public function getTouchedFolders(string $token): array;
97+
98+
/**
99+
* Clear the list of touched folder for a token.
100+
*
101+
* @throws NotPermittedException
102+
* @throws NotFoundException
103+
*/
104+
public function clearTouchedFolders(?string $token): void;
87105
}

lib/MetaDataStorage.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function setMetaDataIntoIntermediateFile(string $userId, int $id, string
106106
/**
107107
* @inheritDoc
108108
*/
109-
public function updateMetaDataIntoIntermediateFile(string $userId, int $id, string $fileKey): void {
109+
public function updateMetaDataIntoIntermediateFile(string $userId, int $id, string $fileKey, string $token = null): void {
110110
// ToDo check signature for race condition
111111
$this->verifyFolderStructure();
112112
$this->verifyOwner($userId, $id);
@@ -136,6 +136,18 @@ public function updateMetaDataIntoIntermediateFile(string $userId, int $id, stri
136136

137137
$intermediateMetaDataFile
138138
->putContent($fileKey);
139+
140+
// To ease the wrap-up process during unlocking,
141+
// we keep track of every folder for which metadata was updated.
142+
// For that we create a file named /tokens/$token/$folderId.
143+
if ($token !== null) {
144+
try {
145+
$tokenFolder = $this->appData->getFolder("/tokens/$token");
146+
} catch (NotFoundException $ex) {
147+
$tokenFolder = $this->appData->newFolder("/tokens/$token");
148+
}
149+
$tokenFolder->newFile("$id", '');
150+
}
139151
}
140152

141153
/**
@@ -308,4 +320,23 @@ protected function getLegacyOwnerPath(string $userId, int $id):string {
308320

309321
return $ownerNodes[0]->getPath();
310322
}
323+
324+
/**
325+
* @inheritDoc
326+
*/
327+
public function getTouchedFolders(string $token): array {
328+
return array_map(
329+
fn (ISimpleFile $file) => (int)$file->getName(),
330+
$this->appData->getFolder("/tokens")->getFolder($token)->getDirectoryListing()
331+
);
332+
}
333+
334+
/**
335+
* @inheritDoc
336+
*/
337+
public function clearTouchedFolders(?string $token): void {
338+
if ($token !== null) {
339+
$this->appData->getFolder("/tokens/$token")->delete();
340+
}
341+
}
311342
}

lib/RollbackService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public function rollbackOlderThan(int $olderThanTimestamp, ?int $limit = null):
117117
continue;
118118
}
119119

120+
$this->metaDataStorage->clearTouchedFolders($lock->getToken());
121+
120122
$this->lockMapper->delete($lock);
121123
}
122124
}

tests/Unit/Controller/LockingControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ public function testUnlockFolder(bool $getUserFolderThrows,
231231
->with($fileId)
232232
->willReturn([$node]);
233233

234-
$this->fileService->expects($this->once())
234+
$this->fileService->expects($this->never())
235235
->method('finalizeChanges')
236236
->with($node);
237-
$this->metaDataStorage->expects($this->once())
237+
$this->metaDataStorage->expects($this->never())
238238
->method('saveIntermediateFile')
239239
->with('john.doe', $fileId);
240240

0 commit comments

Comments
 (0)