소스 검색

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

pull/111/head
Teknikode 3 년 전
부모
커밋
11af3f2f6b
  1. 10
      Teknik/Areas/Paste/Controllers/PasteController.cs

10
Teknik/Areas/Paste/Controllers/PasteController.cs

@ -333,11 +333,9 @@ namespace Teknik.Areas.Paste.Controllers @@ -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 @@ -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 }));
}
}

불러오는 중...
취소
저장