Added defensive logic to File Indexer for scenarios where file does not exist on disk. Added ability to reset the search index prior to reindexing.

This commit is contained in:
sbwalker
2024-11-07 17:05:28 -05:00
parent 013056a6e5
commit fdbdd0ef4c
9 changed files with 48 additions and 14 deletions

View File

@ -45,10 +45,25 @@ namespace Oqtane.Modules.Admin.Files.Manager
var path = folder.Path + file.Name;
var body = "";
if (DocumentExtensions.Contains(Path.GetExtension(file.Name)))
if (System.IO.File.Exists(_fileRepository.GetFilePath(file)))
{
// get the contents of the file
body = System.IO.File.ReadAllText(_fileRepository.GetFilePath(file));
// only non-binary files can be indexed
if (DocumentExtensions.Contains(Path.GetExtension(file.Name)))
{
// get the contents of the file
try
{
body = System.IO.File.ReadAllText(_fileRepository.GetFilePath(file));
}
catch
{
// could not read the file
}
}
}
else
{
removed = true; // file does not exist on disk
}
var searchContent = new SearchContent