Skip to content

Commit 1e6bad9

Browse files
Merge pull request #4336 from nextcloud/backport/4275/stable31
[stable31] feat: scan trashbin and versions with groupfolders:scan command
2 parents 44221b0 + ae9ee0f commit 1e6bad9

File tree

2 files changed

+85
-43
lines changed

2 files changed

+85
-43
lines changed

lib/Command/Scan.php

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -82,49 +82,61 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8282
$stats = [];
8383
foreach ($folders as $folder) {
8484
$folderId = $folder['id'];
85-
$statsRow = [$folderId, 0, 0, 0, 0];
86-
$mount = $this->mountProvider->getMount($folder['id'], '/' . $folder['mount_point'], Constants::PERMISSION_ALL, $folder['quota']);
87-
/** @var IScanner&\OC\Hooks\BasicEmitter $scanner */
88-
$scanner = $mount->getStorage()->getScanner();
89-
90-
$output->writeln("Scanning Team folder with id\t<info>{$folder['id']}</info>", OutputInterface::VERBOSITY_VERBOSE);
91-
if ($scanner instanceof ObjectStoreScanner) {
92-
$output->writeln('Scanning Team folders using an object store as primary storage is not supported.');
93-
return -1;
85+
if ($inputPath === '') {
86+
$mounts = [
87+
'files' => $this->mountProvider->getMount($folder['id'], '/' . $folder['mount_point'], Constants::PERMISSION_ALL, $folder['quota']),
88+
'trashbin' => $this->mountProvider->getTrashMount($folder['id'], '/' . $folder['mount_point'], $folder['quota']),
89+
'version' => $this->mountProvider->getVersionsMount($folder['id'], '/' . $folder['mount_point'], $folder['quota']),
90+
];
91+
} else {
92+
$mounts = [
93+
'files' => $this->mountProvider->getMount($folder['id'], '/' . $folder['mount_point'], Constants::PERMISSION_ALL, $folder['quota'])
94+
];
9495
}
95-
96-
$scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function (string $path) use ($output, &$statsRow): void {
97-
$output->writeln("\tFile\t<info>/$path</info>", OutputInterface::VERBOSITY_VERBOSE);
98-
$statsRow[2]++;
99-
// abortIfInterrupted doesn't exist in nc14
100-
if (method_exists($this, 'abortIfInterrupted')) {
101-
$this->abortIfInterrupted();
96+
foreach ($mounts as $type => $mount) {
97+
$statsRow = ["$folderId - $type", 0, 0, 0, 0];
98+
/** @var IScanner&\OC\Hooks\BasicEmitter $scanner */
99+
$scanner = $mount->getStorage()->getScanner();
100+
101+
$output->writeln("Scanning Team folder with id\t<info>$folderId - $type</info>", OutputInterface::VERBOSITY_VERBOSE);
102+
if ($scanner instanceof ObjectStoreScanner) {
103+
$output->writeln('Scanning Team folders using an object store as primary storage is not supported.');
104+
return -1;
102105
}
103-
});
104-
105-
$scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function (string $path) use ($output, &$statsRow): void {
106-
$output->writeln("\tFolder\t<info>/$path</info>", OutputInterface::VERBOSITY_VERBOSE);
107-
$statsRow[1]++;
108-
// abortIfInterrupted doesn't exist in nc14
109-
if (method_exists($this, 'abortIfInterrupted')) {
110-
$this->abortIfInterrupted();
111-
}
112-
});
113-
114-
$scanner->listen('\OC\Files\Cache\Scanner', 'normalizedNameMismatch', function ($fullPath) use ($output, &$statsRow): void {
115-
$output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>');
116-
$statsRow[3]++;
117-
});
118106

119-
$start = microtime(true);
120-
121-
$scanner->setUseTransactions(false);
122-
$scanner->scan($inputPath, $recursive);
123-
124-
$end = microtime(true);
125-
$statsRow[4] = date('H:i:s', (int)($end - $start));
126-
$output->writeln('', OutputInterface::VERBOSITY_VERBOSE);
127-
$stats[] = $statsRow;
107+
$scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function (string $path) use ($output, &$statsRow): void {
108+
$output->writeln("\tFile\t<info>/$path</info>", OutputInterface::VERBOSITY_VERBOSE);
109+
$statsRow[2]++;
110+
// abortIfInterrupted doesn't exist in nc14
111+
if (method_exists($this, 'abortIfInterrupted')) {
112+
$this->abortIfInterrupted();
113+
}
114+
});
115+
116+
$scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function (string $path) use ($output, &$statsRow): void {
117+
$output->writeln("\tFolder\t<info>/$path</info>", OutputInterface::VERBOSITY_VERBOSE);
118+
$statsRow[1]++;
119+
// abortIfInterrupted doesn't exist in nc14
120+
if (method_exists($this, 'abortIfInterrupted')) {
121+
$this->abortIfInterrupted();
122+
}
123+
});
124+
125+
$scanner->listen('\OC\Files\Cache\Scanner', 'normalizedNameMismatch', function ($fullPath) use ($output, &$statsRow): void {
126+
$output->writeln("\t<error>Entry \"" . $fullPath . '" will not be accessible due to incompatible encoding</error>');
127+
$statsRow[3]++;
128+
});
129+
130+
$start = microtime(true);
131+
132+
$scanner->setUseTransactions(false);
133+
$scanner->scan($inputPath, $recursive);
134+
135+
$end = microtime(true);
136+
$statsRow[4] = date('H:i:s', (int)($end - $start));
137+
$output->writeln('', OutputInterface::VERBOSITY_VERBOSE);
138+
$stats[] = $statsRow;
139+
}
128140
}
129141

130142
$headers = [

lib/Mount/MountProvider.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,16 @@ public function getTrashMount(
207207
int $id,
208208
string $mountPoint,
209209
int $quota,
210-
IStorageFactory $loader,
211-
IUser $user,
210+
?IStorageFactory $loader = null,
211+
?IUser $user = null,
212212
?ICacheEntry $cacheEntry = null,
213213
): IMountPoint {
214214

215215
$storage = $this->getRootFolder()->getStorage();
216216

217-
$storage->setOwner($user->getUID());
217+
if ($user) {
218+
$storage->setOwner($user->getUID());
219+
}
218220

219221
$trashPath = $this->getRootFolder()->getInternalPath() . '/trash/' . $id;
220222

@@ -229,6 +231,34 @@ public function getTrashMount(
229231
);
230232
}
231233

234+
public function getVersionsMount(
235+
int $id,
236+
string $mountPoint,
237+
int $quota,
238+
?IStorageFactory $loader = null,
239+
?IUser $user = null,
240+
?ICacheEntry $cacheEntry = null,
241+
): IMountPoint {
242+
243+
$storage = $this->getRootFolder()->getStorage();
244+
245+
if ($user) {
246+
$storage->setOwner($user->getUID());
247+
}
248+
249+
$trashPath = $this->getRootFolder()->getInternalPath() . '/versions/' . $id;
250+
251+
$trashStorage = $this->getGroupFolderStorage($id, $storage, $user, $trashPath, $quota, $cacheEntry);
252+
253+
return new GroupMountPoint(
254+
$id,
255+
$trashStorage,
256+
$mountPoint,
257+
null,
258+
$loader
259+
);
260+
}
261+
232262
public function getGroupFolderStorage(
233263
int $id,
234264
IStorage $rootStorage,

0 commit comments

Comments
 (0)