Browse Source

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

master
Teknikode 7 months ago
parent
commit
11af3f2f6b
1 changed files with 6 additions and 4 deletions
  1. 6
    4
      Teknik/Areas/Paste/Controllers/PasteController.cs

+ 6
- 4
Teknik/Areas/Paste/Controllers/PasteController.cs 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 }));
}
}

Loading…
Cancel
Save