Skip to content
Snippets Groups Projects
Commit a06887ec authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Move ExpiredDirs to ATXCommon.FsUtils.

parent 89bba097
No related branches found
No related tags found
No related merge requests found
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
...@@ -40,5 +41,40 @@ namespace ATXCommon ...@@ -40,5 +41,40 @@ namespace ATXCommon
} }
return (baseTime - dirTimestamp).Days; return (baseTime - dirTimestamp).Days;
} }
/// <summary>
/// Assemble a dictionary with information about expired directories.
/// </summary>
/// <param name="baseDir">The base directory to scan for subdirectories.</param>
/// <param name="thresh">The number of days used as expiration threshold.</param>
/// <returns>A dictionary having usernames as keys (of those users that actually do have
/// expired directories), where the values are lists of tuples with the DirInfo objects,
/// size and age (in days) of the expired directories.</returns>
public static Dictionary<string, List<Tuple<DirectoryInfo, long, int>>> ExpiredDirs(
DirectoryInfo baseDir,int thresh) {
var collection = new Dictionary<string, List<Tuple<DirectoryInfo, long, int>>>();
var now = DateTime.Now;
foreach (var userdir in baseDir.GetDirectories()) {
var expired = new List<Tuple<DirectoryInfo, long, int>>();
foreach (var subdir in userdir.GetDirectories()) {
var age = DirNameToAge(subdir, now);
if (age < thresh)
continue;
long size = -1;
try {
size = GetDirectorySize(subdir.FullName) / Conv.MegaBytes;
}
catch (Exception ex) {
Log.Error("ERROR getting directory size of [{0}]: {1}",
subdir.FullName, ex.Message);
}
expired.Add(new Tuple<DirectoryInfo, long, int>(subdir, size, age));
}
if (expired.Count > 0)
collection.Add(userdir.Name, expired);
}
return collection;
}
} }
} }
...@@ -961,7 +961,8 @@ namespace AutoTx ...@@ -961,7 +961,8 @@ namespace AutoTx
/// </summary> /// </summary>
/// <param name="threshold">The number of days used as expiration threshold.</param> /// <param name="threshold">The number of days used as expiration threshold.</param>
public string GraceLocationSummary(int threshold) { public string GraceLocationSummary(int threshold) {
var expired = ExpiredDirs(threshold); var doneDir = new DirectoryInfo(Path.Combine(_managedPath, "DONE"));
var expired = FsUtils.ExpiredDirs(doneDir, threshold);
var report = ""; var report = "";
foreach (var userdir in expired.Keys) { foreach (var userdir in expired.Keys) {
report += "\n - user '" + userdir + "'\n"; report += "\n - user '" + userdir + "'\n";
...@@ -983,39 +984,6 @@ namespace AutoTx ...@@ -983,39 +984,6 @@ namespace AutoTx
return report; return report;
} }
/// <summary>
/// Assemble a dictionary with information about expired directories.
/// </summary>
/// <param name="thresh">The number of days used as expiration threshold.</param>
/// <returns>A dictionary having usernames as keys (of those users that actually do have
/// expired directories), where the values are lists of tuples with the DirInfo objects,
/// size and age (in days) of the expired directories.</returns>
private Dictionary<string, List<Tuple<DirectoryInfo, long, int>>> ExpiredDirs(int thresh) {
var collection = new Dictionary<string, List<Tuple<DirectoryInfo, long, int>>>();
var graceDir = new DirectoryInfo(Path.Combine(_managedPath, "DONE"));
var now = DateTime.Now;
foreach (var userdir in graceDir.GetDirectories()) {
var expired = new List<Tuple<DirectoryInfo, long, int>>();
foreach (var subdir in userdir.GetDirectories()) {
var age = FsUtils.DirNameToAge(subdir, now);
if (age < thresh)
continue;
long size = -1;
try {
size = FsUtils.GetDirectorySize(subdir.FullName) / MegaBytes;
}
catch (Exception ex) {
Log.Error("ERROR getting directory size of [{0}]: {1}",
subdir.FullName, ex.Message);
}
expired.Add(new Tuple<DirectoryInfo, long, int>(subdir, size, age));
}
if (expired.Count > 0)
collection.Add(userdir.Name, expired);
}
return collection;
}
#endregion #endregion
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment