1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Changed paste file deletion to after successful saving of new file.

This commit is contained in:
Uncled1023 2019-02-04 20:45:53 -08:00
parent f42547174a
commit 11af3f2f6b

View File

@ -333,11 +333,9 @@ namespace Teknik.Areas.Paste.Controllers
}
}
// Delete the old file
// get the old file
string subDir = paste.FileName[0].ToString();
string filePath = Path.Combine(_config.PasteConfig.PasteDirectory, subDir, paste.FileName);
if (System.IO.File.Exists(filePath))
System.IO.File.Delete(filePath);
string oldFile = Path.Combine(_config.PasteConfig.PasteDirectory, subDir, paste.FileName);
// Generate a unique file name that does not currently exist
string newFilePath = FileHelper.GenerateRandomFileName(_config.PasteConfig.PasteDirectory, _config.PasteConfig.FileExtension, 10);
@ -363,6 +361,10 @@ namespace Teknik.Areas.Paste.Controllers
_dbContext.Entry(paste).State = EntityState.Modified;
_dbContext.SaveChanges();
// Delete the old file
if (System.IO.File.Exists(oldFile))
System.IO.File.Delete(oldFile);
return Redirect(Url.SubRouteUrl("p", "Paste.View", new { type = "Full", url = paste.Url }));
}
}