Merge pull request #5057 from sbwalker/dev

fix #5044 - improve file part removal logic
This commit is contained in:
Shaun Walker 2025-02-03 11:00:37 -05:00 committed by GitHub
commit 6f588200d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -536,17 +536,23 @@ namespace Oqtane.Controllers
// clean up file parts
foreach (var file in Directory.GetFiles(folder, "*" + token + "*"))
{
// file name matches part or is more than 2 hours old (ie. a prior file upload failed)
if (fileparts.Contains(file) || System.IO.File.GetCreationTime(file).ToUniversalTime() < DateTime.UtcNow.AddHours(-2))
if (fileparts.Contains(file))
{
try
{
System.IO.File.Delete(file);
}
catch
{
// unable to delete part - ignore
}
}
}
// rename temp file
if (success)
{
// remove file if it already exists (as well as any thumbnails)
// remove file if it already exists (as well as any thumbnails which may exist)
foreach (var file in Directory.GetFiles(folder, Path.GetFileNameWithoutExtension(filename) + ".*"))
{
if (Path.GetExtension(file) != ".tmp")