Skip to content

Commit

Permalink
Index storage release update
Browse files Browse the repository at this point in the history
  • Loading branch information
Frixs committed May 19, 2021
1 parent 76bd178 commit e56efe9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public interface IIndexStorage : IIndexStorageIndexedSerializable
/// <exception cref="Exception">Unknown error - related to IO.</exception>
string[] GetIndexFiles(string iid);

/// <summary>
/// Find all files related to index.
/// </summary>
/// <param name="iid">The index identifier.</param>
/// <returns>Array of all index files (file paths).</returns>
/// <exception cref="ArgumentNullException">Identifier is not defined.</exception>
/// <exception cref="Exception">Unknown error - related to IO.</exception>
string[] GetFiles(string iid);

/// <summary>
/// Delete files according to index identifier and file timestmap.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,39 @@ public string[] GetIndexFiles(string iid)
return result.ToArray();
}

/// <inheritdoc/>
public string[] GetFiles(string iid)
{
if (iid == null)
throw new ArgumentNullException("Index ID is not defined!");

var result = new List<string>();

try
{
if (Directory.Exists(Constants.IndexDataStorageDir))
{
// Get all index directories...
string[] dirs = Directory.GetDirectories(Constants.IndexDataStorageDir);
for (int i = 0; i < dirs.Length; ++i)
// Find the one specific for the searched index...
if (Path.GetFileName(dirs[i]).Equals(iid))
{
result.AddRange(
Directory.GetFiles(dirs[i])
.Where(o => o.EndsWith(".idx")).ToArray()
);
}
}
}
catch (Exception ex)
{
_logger.LogErrorSource($"{ex.GetType()}: {ex.Message}");
}

return result.ToArray();
}

/// <inheritdoc/>
public void DeleteFiles(string iid, DateTime fileTimestamp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ await RunCommandAsync(() => ConfigurationContext.ProcessingConfigurationUpdateCo
// Find and delete all the index files...
try
{
var filePaths = _indexStorage.GetIndexFiles(_dataInstance.Id.ToString());
var filePaths = _indexStorage.GetFiles(_dataInstance.Id.ToString());
for (int i = 0; i < filePaths.Length; ++i)
File.Delete(filePaths[i]);
}
Expand Down Expand Up @@ -1247,7 +1247,7 @@ await RunCommandAsync(() => ConfigurationContext.DataInstanceDeleteCommandFlag,
var crawlerFilePaths = _crawlerStorage.GetAllDataFiles(_dataInstance.Id.ToString());
for (int i = 0; i < crawlerFilePaths.Length; ++i)
File.Delete(crawlerFilePaths[i]);
var indexFilePaths = _indexStorage.GetIndexFiles(_dataInstance.Id.ToString());
var indexFilePaths = _indexStorage.GetFiles(_dataInstance.Id.ToString());
for (int i = 0; i < indexFilePaths.Length; ++i)
File.Delete(indexFilePaths[i]);
}
Expand Down

0 comments on commit e56efe9

Please sign in to comment.