Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions lib/Service/ExternalFilesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use OCP\IUserManager;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;
use OCP\Files\NotFoundException;
use OCP\Files\StorageNotAvailableException;

class ExternalFilesService {
use TArrayTools;
Expand Down Expand Up @@ -62,7 +64,20 @@ public function getFileSource(Node $file, string &$source) {
return;
}

$this->getMountPoint($file);
try {
$this->getMountPoint($file);
} catch (FileIsNotIndexableException $e) {
return;
} catch (StorageNotAvailableException|NotFoundException $e) {
$path = '';
try {
$path = $file->getPath();
} catch (\Throwable $_) {
}
$this->logger->warning('External storage not available when getting file source', ['path' => $path, 'exception' => $e]);
return;
}

$source = ConfigLexicon::FILES_EXTERNAL;

throw new KnownFileSourceException();
Expand Down Expand Up @@ -93,7 +108,19 @@ public function updateDocumentAccess(FilesDocument $document, Node $file) {
return;
}

$mount = $this->getMountPoint($file);
try {
$mount = $this->getMountPoint($file);
} catch (FileIsNotIndexableException $e) {
return;
} catch (StorageNotAvailableException|NotFoundException $e) {
$path = '';
try {
$path = $file->getPath();
} catch (\Throwable $_) {
}
$this->logger->warning('External storage not available when updating document access', ['path' => $path, 'exception' => $e]);
return;
}
$access = $document->getAccess();

if ($this->isMountFullGlobal($mount)) {
Expand Down Expand Up @@ -159,6 +186,8 @@ private function getMountPoint(Node $file): MountPoint {
);
} catch (ExternalMountNotFoundException $e) {
throw new FileIsNotIndexableException('issue while getMountPoint');
} catch (NotFoundException|StorageNotAvailableException $e) {
throw new FileIsNotIndexableException('storage not available');
}
}

Expand Down
54 changes: 47 additions & 7 deletions lib/Service/FilesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ public function getFilesFromUser(string $userId, string $chunk): array {
try {
$result[] = $this->generateFilesDocumentFromFile($userId, $files);
} catch (FileIsNotIndexableException $e) {
/** we do nothin' */
// file is not indexable - skip
} catch (NotFoundException|StorageNotAvailableException $e) {
$this->logger->warning('File not available when getting files from user, skipping', ['path' => $files->getPath(), 'exception' => $e]);
} catch (Throwable $e) {
$this->logger->warning('Unexpected error while getting files from user, skipping', ['path' => $files->getPath(), 'exception' => $e]);
}
}

Expand Down Expand Up @@ -254,6 +258,15 @@ public function getFilesFromDirectory(string $userId, Folder $node): array {
$documents[] = $this->generateFilesDocumentFromFile($userId, $file);
$this->sumDocuments++;
} catch (FileIsNotIndexableException $e) {
// file is not indexable - skip
continue;
} catch (NotFoundException|StorageNotAvailableException $e) {
// file not found or storage temporarily not available - skip and continue
$this->logger->warning('File not available while listing directory, skipping', ['path' => $file->getPath(), 'exception' => $e]);
continue;
} catch (Throwable $e) {
// unexpected errors should not stop indexing
$this->logger->warning('Unexpected error while processing file, skipping', ['path' => $file->getPath(), 'exception' => $e]);
continue;
}

Expand Down Expand Up @@ -320,9 +333,10 @@ private function generateFilesDocumentFromFile(string $viewerId, Node $file): Fi
throw new NotFoundException();
}

$this->isNodeIndexable($file);
try {
$this->isNodeIndexable($file);

$source = $this->getFileSource($file);
$source = $this->getFileSource($file);
if ($file->getId() === -1) {
throw new FileIsNotIndexableException();
}
Expand Down Expand Up @@ -357,8 +371,8 @@ private function generateFilesDocumentFromFile(string $viewerId, Node $file): Fi
$document->setMimetype($file->getMimetype());
}

$document->setModifiedTime($file->getMTime())
->setSource($source);
$document->setModifiedTime($file->getMTime())
->setSource($source);

$tagIds = $this->systemTagObjectMapper->getTagIdsForObjects([$file->getId()], 'files');
if (array_key_exists($file->getId(), $tagIds)) {
Expand All @@ -371,7 +385,7 @@ private function generateFilesDocumentFromFile(string $viewerId, Node $file): Fi
}

$document->setModifiedTime($file->getMTime());
$stat = $file->stat();
$stat = $file->stat();

if (is_array($stat)) {
$document->setMore(
Expand All @@ -384,6 +398,11 @@ private function generateFilesDocumentFromFile(string $viewerId, Node $file): Fi
$this->logger->warning('stat() on File #' . $file->getId() . ' is not an array: ' . json_encode($stat));
}

} catch (NotFoundException|StorageNotAvailableException|NotPermittedException|LockedException $e) {
// storage not available or file removed / access issue - mark as not indexable
throw new FileIsNotIndexableException($e->getMessage());
}

return $document;
}

Expand Down Expand Up @@ -523,12 +542,33 @@ private function generateDocumentFromIndex(IIndex $index): FilesDocument {
&& ($file->getMountPoint()->getMountType() === 'external')) {
throw new Exception();
}
} catch (Exception $e) {
} catch (FilesNotFoundException|NotFoundException $e) {
// file removed -> remove from index
$index->setStatus(IIndex::INDEX_REMOVE);
$document = new FilesDocument($index->getProviderId(), $index->getDocumentId());
$document->setIndex($index);
$document->setAccess(new DocumentAccess(''));

return $document;
} catch (StorageNotAvailableException $e) {
// storage temporarily unavailable -> do not remove index, set to ignore and record error
$index->addError('Storage not available', $e->getMessage(), IIndex::ERROR_SEV_3);
$this->updateNewIndexError($index, 'Storage not available', $e->getMessage(), IIndex::ERROR_SEV_3);
$index->setStatus(IIndex::INDEX_IGNORE);
$document = new FilesDocument($index->getProviderId(), $index->getDocumentId());
$document->setIndex($index);
$document->setAccess(new DocumentAccess(''));

return $document;
} catch (Exception $e) {
// unexpected error -> add an error and ignore this index for now
$index->addError('Unexpected error while resolving file for index', $e->getMessage(), IIndex::ERROR_SEV_3);
$this->updateNewIndexError($index, 'Unexpected error while resolving file for index', $e->getMessage(), IIndex::ERROR_SEV_3);
$index->setStatus(IIndex::INDEX_IGNORE);
$document = new FilesDocument($index->getProviderId(), $index->getDocumentId());
$document->setIndex($index);
$document->setAccess(new DocumentAccess(''));

return $document;
}

Expand Down
16 changes: 16 additions & 0 deletions lib/Service/GroupFoldersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public function getFileSource(Node $file, string &$source): void {
$this->getMountPoint($file);
} catch (FileIsNotIndexableException $e) {
return;
} catch (\OCP\Files\StorageNotAvailableException|\OCP\Files\NotFoundException $e) {
$path = '';
try {
$path = $file->getPath();
} catch (\Throwable $_) {
}
$this->logger->warning('Group folder storage not available when getting file source', ['path' => $path, 'exception' => $e]);
return;
}

$source = ConfigLexicon::FILES_GROUP_FOLDERS;
Expand All @@ -99,6 +107,14 @@ public function updateDocumentAccess(FilesDocument $document, Node $file): void
$mount = $this->getMountPoint($file);
} catch (FileIsNotIndexableException $e) {
return;
} catch (\OCP\Files\StorageNotAvailableException|\OCP\Files\NotFoundException $e) {
$path = '';
try {
$path = $file->getPath();
} catch (\Throwable $_) {
}
$this->logger->warning('Group folder storage not available when updating document access', ['path' => $path, 'exception' => $e]);
return;
}

$access = $document->getAccess();
Expand Down
10 changes: 9 additions & 1 deletion lib/Service/LocalFilesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use OCA\Files_FullTextSearch\Model\FilesDocument;
use OCA\Files_FullTextSearch\Model\FileShares;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\StorageNotAvailableException;
use OCP\FullTextSearch\Model\IDocumentAccess;
use OCP\IGroupManager;
use OCP\IUserManager;
Expand Down Expand Up @@ -47,7 +49,13 @@ public function __construct(
* @throws KnownFileSourceException
*/
public function getFileSource(Node $file, string &$source) {
$mountType = $file->getMountPoint()->getMountType();
try {
$mountType = $file->getMountPoint()->getMountType();
} catch (NotFoundException|StorageNotAvailableException $e) {
$this->logger->warning('Local mount not available when getting file source', ['exception' => $e]);
return;
}

if ($mountType !== '' && $mountType !== 'shared') {
return;
}
Expand Down