Skip to content

Commit b7def8c

Browse files
fix: refactor DeleteStalePointerFileEntries; graceful fail with invalid characters.
1 parent 342c42b commit b7def8c

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/Arius.Core/Features/Commands/Archive/ArchiveCommandHandler.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ await Task.WhenAll(tasks.Values.Select(async t =>
172172
try
173173
{
174174
// 6. Remove PointerFileEntries that do not exist on disk
175-
logger.LogInformation("Cleaning up pointer file entries that no longer exist on disk...");
176-
pointerFileEntriesDeleted = handlerContext.StateRepository.DeletePointerFileEntries(pfe => !handlerContext.FileSystem.FileExists(pfe.RelativeName));
177-
logger.LogInformation("Cleaning up pointer file entries that no longer exist on disk... {count} deleted", pointerFileEntriesDeleted);
175+
DeleteStalePointerFileEntries(handlerContext);
178176

179177
// 7. Upload the new state file to blob storage
180178
string? newStateName = null;
@@ -391,6 +389,25 @@ private Task CreateUploadSmallFilesTarArchiveTask(HandlerContext handlerContext,
391389
}
392390
}); // No cancellation token passed to Task.Run, this allows proper catch/finally execution
393391

392+
private void DeleteStalePointerFileEntries(HandlerContext handlerContext)
393+
{
394+
logger.LogInformation("Cleaning up pointer file entries that no longer exist on disk...");
395+
pointerFileEntriesDeleted = handlerContext.StateRepository.DeletePointerFileEntries(FileDoesNotExist);
396+
logger.LogInformation("Cleaning up pointer file entries that no longer exist on disk... {count} deleted", pointerFileEntriesDeleted);
397+
398+
bool FileDoesNotExist(PointerFileEntry pfe)
399+
{
400+
try
401+
{
402+
return !handlerContext.FileSystem.FileExists(pfe.RelativeName);
403+
}
404+
catch (ArgumentException)
405+
{
406+
logger.LogWarning("Invalid character found in path for pointer file entry {PointerFileEntry}. Assuming the PointerFileEntry is valid/the file exists.", pfe);
407+
return false; // FIX: Zio throws an ArgumentException: Invalid character found \u000D at index 91 (Parameter 'path') for some reason. Assume the file exists in this case.
408+
}
409+
}
410+
}
394411

395412
// --- HELPERS
396413

0 commit comments

Comments
 (0)