server icon indicating copy to clipboard operation
server copied to clipboard

`occ preview:repair --delete` should delete whole folders

Open nickvergessen opened this issue 1 year ago • 0 comments

When running in delete mode, we don't have to loop over all the previews, delete them one-by-one and then delete the empty folder. We can delete them directly, if their name is longer than 1 character. Only in 1 character mode we need to check and not delete any folders inside.

Code that could be added (with fixed strings and logging (which I commented out locally)): Before: https://github.com/nextcloud/server/blob/c109ae9437403c5bd17834c2ee53507c1d1f2ad2/core/Command/Preview/Repair.php#L214 Add:

			if (strlen($name) > 2) {
				try {
					$section1->writeln("         Delete yolo folder preview/$name", OutputInterface::VERBOSITY_VERBOSE);
					$oldPreviewFolder->delete();
					$progressBar->advance();
					continue;
				} catch (\Exception $e) {
					$this->logger->error("Failed to delete empty folder preview/$name", [
						'app' => 'core',
						'exception' => $e,
					]);
				}
			}

nickvergessen avatar Oct 11 '24 07:10 nickvergessen