Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auto-tx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vamp
auto-tx
Commits
a06887ec
Commit
a06887ec
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Move ExpiredDirs to ATXCommon.FsUtils.
parent
89bba097
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ATXSerializables/FsUtils.cs
+36
-0
36 additions, 0 deletions
ATXSerializables/FsUtils.cs
AutoTx/AutoTx.cs
+2
-34
2 additions, 34 deletions
AutoTx/AutoTx.cs
with
38 additions
and
34 deletions
ATXSerializables/FsUtils.cs
+
36
−
0
View file @
a06887ec
using
System
;
using
System.Collections.Generic
;
using
System.Globalization
;
using
System.IO
;
using
System.Linq
;
...
...
@@ -40,5 +41,40 @@ namespace ATXCommon
}
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
;
}
}
}
This diff is collapsed.
Click to expand it.
AutoTx/AutoTx.cs
+
2
−
34
View file @
a06887ec
...
...
@@ -961,7 +961,8 @@ namespace AutoTx
/// </summary>
/// <param name="threshold">The number of days used as expiration threshold.</param>
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
=
""
;
foreach
(
var
userdir
in
expired
.
Keys
)
{
report
+=
"\n - user '"
+
userdir
+
"'\n"
;
...
...
@@ -983,39 +984,6 @@ namespace AutoTx
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
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment