This commit is contained in:
@@ -244,7 +244,7 @@ namespace AyaNova.Util
|
||||
}
|
||||
|
||||
//final cleanup step is to erase user uploaded files
|
||||
FileUtil.EraseEntireContentsOfUserFilesFolder();
|
||||
FileUtil.EraseEntireContentsOfAttachmentFilesFolder();
|
||||
}
|
||||
|
||||
|
||||
@@ -354,7 +354,7 @@ namespace AyaNova.Util
|
||||
}
|
||||
|
||||
//If we got here then it's safe to erase the attachment files
|
||||
FileUtil.EraseEntireContentsOfUserFilesFolder();
|
||||
FileUtil.EraseEntireContentsOfAttachmentFilesFolder();
|
||||
|
||||
apiServerState.ResumePriorState();
|
||||
|
||||
|
||||
@@ -61,16 +61,16 @@ namespace AyaNova.Util
|
||||
}
|
||||
#endregion folder ensurance
|
||||
|
||||
#region Utility file handling
|
||||
#region Utility (BACKUP) file handling
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a path combining supplied file name and backup files folder
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static string GetFullPathForUtilityFile(string fileName)
|
||||
internal static string GetFullPathForBackupFile(string fileName)
|
||||
{
|
||||
return Path.Combine(UtilityFilesFolder, fileName);
|
||||
return Path.Combine(BackupFilesFolder, fileName);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace AyaNova.Util
|
||||
/// Get backup folder
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static string UtilityFilesFolder
|
||||
internal static string BackupFilesFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -116,7 +116,7 @@ namespace AyaNova.Util
|
||||
BackupStatus statusReport = new BackupStatus();
|
||||
try
|
||||
{
|
||||
statusReport.AvailableFreeSpace = GetBytesReadable(new System.IO.DriveInfo(Path.GetPathRoot(UtilityFilesFolder)).AvailableFreeSpace);
|
||||
statusReport.AvailableFreeSpace = GetBytesReadable(new System.IO.DriveInfo(Path.GetPathRoot(BackupFilesFolder)).AvailableFreeSpace);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -125,7 +125,7 @@ namespace AyaNova.Util
|
||||
log.LogError(ex, "FileUtil::BackupStatusReport error getting available space");
|
||||
}
|
||||
|
||||
var backupFiles = Directory.EnumerateFiles(UtilityFilesFolder, "*");
|
||||
var backupFiles = Directory.EnumerateFiles(BackupFilesFolder, "*");
|
||||
|
||||
foreach (string file in backupFiles.OrderByDescending(z => z))
|
||||
{
|
||||
@@ -165,8 +165,8 @@ namespace AyaNova.Util
|
||||
internal static DateTime MostRecentAutomatedBackupFileDate()
|
||||
{
|
||||
DateTime LastBackup = DateTime.MinValue;
|
||||
var BackupPath = UtilityFilesFolder;
|
||||
foreach (string file in Directory.EnumerateFiles(UtilityFilesFolder, "db-*.backup"))
|
||||
var BackupPath = BackupFilesFolder;
|
||||
foreach (string file in Directory.EnumerateFiles(BackupFilesFolder, "db-*.backup"))
|
||||
{
|
||||
var ThisFileTime = File.GetCreationTimeUtc(file);
|
||||
if (ThisFileTime > LastBackup)
|
||||
@@ -183,12 +183,12 @@ namespace AyaNova.Util
|
||||
/// </summary>
|
||||
/// <param name="fileName">name of utility file </param>
|
||||
/// <returns>duh!</returns>
|
||||
internal static bool UtilityFileExists(string fileName)
|
||||
internal static bool BackupFileExists(string fileName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
return false;
|
||||
|
||||
var utilityFilePath = GetFullPathForUtilityFile(fileName);
|
||||
var utilityFilePath = GetFullPathForBackupFile(fileName);
|
||||
return File.Exists(utilityFilePath);
|
||||
|
||||
}
|
||||
@@ -196,9 +196,9 @@ namespace AyaNova.Util
|
||||
/// <summary>
|
||||
/// DANGER: Erases all Utility files including backups etc
|
||||
/// </summary>
|
||||
internal static void EraseEntireContentsOfUtilityFilesFolder()
|
||||
internal static void EraseEntireContentsOfBackupFilesFolder()
|
||||
{
|
||||
System.IO.DirectoryInfo di = new DirectoryInfo(UtilityFilesFolder);
|
||||
System.IO.DirectoryInfo di = new DirectoryInfo(BackupFilesFolder);
|
||||
foreach (FileInfo file in di.EnumerateFiles())
|
||||
{
|
||||
file.Delete();
|
||||
@@ -220,7 +220,7 @@ namespace AyaNova.Util
|
||||
if (keepCount < 1) keepCount = 1;
|
||||
|
||||
//Database backups
|
||||
var BackupFileList = Directory.EnumerateFiles(UtilityFilesFolder, "db-*.backup");
|
||||
var BackupFileList = Directory.EnumerateFiles(BackupFilesFolder, "db-*.backup");
|
||||
if (BackupFileList.Count() > keepCount)
|
||||
{
|
||||
//sort, skip newest x (keepcount) delete the rest
|
||||
@@ -233,7 +233,7 @@ namespace AyaNova.Util
|
||||
}
|
||||
|
||||
//Attachment backups
|
||||
BackupFileList = Directory.EnumerateFiles(UtilityFilesFolder, "at-*.zip");
|
||||
BackupFileList = Directory.EnumerateFiles(BackupFilesFolder, "at-*.zip");
|
||||
if (BackupFileList.Count() > keepCount)
|
||||
{
|
||||
//sort, skip newest x (keepcount) delete the rest
|
||||
@@ -247,11 +247,11 @@ namespace AyaNova.Util
|
||||
|
||||
}
|
||||
|
||||
internal static long UtilityFilesDriveAvailableSpace()
|
||||
internal static long BackupFilesDriveAvailableSpace()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new System.IO.DriveInfo(Path.GetPathRoot(UtilityFilesFolder)).AvailableFreeSpace;
|
||||
return new System.IO.DriveInfo(Path.GetPathRoot(BackupFilesFolder)).AvailableFreeSpace;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -275,7 +275,7 @@ namespace AyaNova.Util
|
||||
/// <returns></returns>
|
||||
internal static List<string> ZipGetUtilityFileEntries(string zipFileName)
|
||||
{
|
||||
return ZipGetEntries(GetFullPathForUtilityFile(zipFileName));
|
||||
return ZipGetEntries(GetFullPathForBackupFile(zipFileName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -306,7 +306,7 @@ namespace AyaNova.Util
|
||||
/// Get user folder
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static string UserFilesFolder
|
||||
internal static string AttachmentFilesFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -331,11 +331,11 @@ namespace AyaNova.Util
|
||||
/// Get a random file name with path to attachments folder
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal static string NewRandomUserFilesFolderFileName
|
||||
internal static string NewRandomAttachmentFilesFolderFileName
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.Combine(UserFilesFolder, NewRandomFileName);
|
||||
return Path.Combine(AttachmentFilesFolder, NewRandomFileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ namespace AyaNova.Util
|
||||
/// <returns>Path without the file</returns>
|
||||
internal static string GetPermanentAttachmentPath(string hash)
|
||||
{
|
||||
return Path.Combine(UserFilesFolder, hash[0].ToString(), hash[1].ToString(), hash[2].ToString());
|
||||
return Path.Combine(AttachmentFilesFolder, hash[0].ToString(), hash[1].ToString(), hash[2].ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -412,7 +412,7 @@ namespace AyaNova.Util
|
||||
/// <returns></returns>
|
||||
internal static string GetPermanentAttachmentFilePath(string hash)
|
||||
{
|
||||
return Path.Combine(UserFilesFolder, hash[0].ToString(), hash[1].ToString(), hash[2].ToString(), hash);
|
||||
return Path.Combine(AttachmentFilesFolder, hash[0].ToString(), hash[1].ToString(), hash[2].ToString(), hash);
|
||||
}
|
||||
|
||||
|
||||
@@ -455,9 +455,9 @@ namespace AyaNova.Util
|
||||
/// <summary>
|
||||
/// DANGER: Erases all user files
|
||||
/// </summary>
|
||||
internal static void EraseEntireContentsOfUserFilesFolder()
|
||||
internal static void EraseEntireContentsOfAttachmentFilesFolder()
|
||||
{
|
||||
System.IO.DirectoryInfo di = new DirectoryInfo(UserFilesFolder);
|
||||
System.IO.DirectoryInfo di = new DirectoryInfo(AttachmentFilesFolder);
|
||||
foreach (FileInfo file in di.EnumerateFiles())
|
||||
{
|
||||
file.Delete();
|
||||
@@ -474,9 +474,9 @@ namespace AyaNova.Util
|
||||
try
|
||||
{
|
||||
var AttachmentsBackupFile = $"{demandFileNamePrepend}at-{FileUtil.GetSafeDateFileName()}.zip";//presentation issue so don't use UTC for this one
|
||||
AttachmentsBackupFile = GetFullPathForUtilityFile(AttachmentsBackupFile);
|
||||
AttachmentsBackupFile = GetFullPathForBackupFile(AttachmentsBackupFile);
|
||||
|
||||
System.IO.Compression.ZipFile.CreateFromDirectory(UserFilesFolder, AttachmentsBackupFile);
|
||||
System.IO.Compression.ZipFile.CreateFromDirectory(AttachmentFilesFolder, AttachmentsBackupFile);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -492,7 +492,7 @@ namespace AyaNova.Util
|
||||
{
|
||||
try
|
||||
{
|
||||
return new System.IO.DriveInfo(Path.GetPathRoot(UserFilesFolder)).AvailableFreeSpace;
|
||||
return new System.IO.DriveInfo(Path.GetPathRoot(AttachmentFilesFolder)).AvailableFreeSpace;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -502,6 +502,27 @@ namespace AyaNova.Util
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
internal static IEnumerable<string> GetAllAttachmentFilePaths()
|
||||
{
|
||||
return Directory.EnumerateFiles(AttachmentFilesFolder, "*", SearchOption.AllDirectories);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Confirm if a file exists in the attachment folder
|
||||
/// </summary>
|
||||
/// <param name="fileName">name of attachment file </param>
|
||||
/// <returns>duh!</returns>
|
||||
internal static bool AttachmentFileExists(string fileName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
return false;
|
||||
|
||||
// var utilityFilePath = GetFullPathForBackupFile(fileName);
|
||||
return File.Exists(GetPermanentAttachmentFilePath(fileName));
|
||||
|
||||
}
|
||||
#endregion attachment stuff
|
||||
|
||||
#region General utilities
|
||||
@@ -563,7 +584,7 @@ namespace AyaNova.Util
|
||||
/// <returns></returns>
|
||||
internal static FolderSizeInfo GetAttachmentFolderSizeInfo()
|
||||
{
|
||||
return GetDirectorySize(new DirectoryInfo(UserFilesFolder));
|
||||
return GetDirectorySize(new DirectoryInfo(AttachmentFilesFolder));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -572,7 +593,7 @@ namespace AyaNova.Util
|
||||
/// <returns></returns>
|
||||
internal static FolderSizeInfo GetUtilityFolderSizeInfo()
|
||||
{
|
||||
return GetDirectorySize(new DirectoryInfo(UtilityFilesFolder));
|
||||
return GetDirectorySize(new DirectoryInfo(BackupFilesFolder));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user