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
30fc2794
Commit
30fc2794
authored
7 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Move IncomingDirIsEmpty to FsUtils.DirEmptyExcept.
parent
66355b47
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
ATXCommon/FsUtils.cs
+33
-0
33 additions, 0 deletions
ATXCommon/FsUtils.cs
AutoTx/AutoTx.cs
+1
-33
1 addition, 33 deletions
AutoTx/AutoTx.cs
with
34 additions
and
33 deletions
ATXCommon/FsUtils.cs
+
33
−
0
View file @
30fc2794
...
...
@@ -76,5 +76,38 @@ namespace ATXCommon
}
return
collection
;
}
/// <summary>
/// Check if a given directory is empty. If a marker file is set in the config a
/// file with this name will be created inside the given directory and will be
/// skipped itself when checking for files and directories.
/// </summary>
/// <param name="dirInfo">The directory to check.</param>
/// <param name="ignoredName">A filename that will be ignored.</param>
/// <returns>True if access is denied or the dir is empty, false otherwise.</returns>
public
static
bool
DirEmptyExcept
(
DirectoryInfo
dirInfo
,
string
ignoredName
)
{
try
{
var
filesInTree
=
dirInfo
.
GetFiles
(
"*"
,
SearchOption
.
AllDirectories
);
if
(
string
.
IsNullOrEmpty
(
ignoredName
))
return
filesInTree
.
Length
==
0
;
// check if there is ONLY the marker file:
if
(
filesInTree
.
Length
==
1
&&
filesInTree
[
0
].
Name
.
Equals
(
ignoredName
))
return
true
;
// make sure the marker file is there:
var
markerFilePath
=
Path
.
Combine
(
dirInfo
.
FullName
,
ignoredName
);
if
(!
File
.
Exists
(
markerFilePath
))
File
.
Create
(
markerFilePath
);
return
filesInTree
.
Length
==
0
;
}
catch
(
Exception
e
)
{
Log
.
Error
(
"Error accessing directories: {0}"
,
e
.
Message
);
}
// if nothing triggered before, we pretend the dir is empty:
return
true
;
}
}
}
This diff is collapsed.
Click to expand it.
AutoTx/AutoTx.cs
+
1
−
33
View file @
30fc2794
...
...
@@ -593,7 +593,7 @@ namespace AutoTx
private
void
CheckIncomingDirectories
()
{
// iterate over all user-subdirectories:
foreach
(
var
userDir
in
new
DirectoryInfo
(
_incomingPath
).
GetDirectories
())
{
if
(
Incoming
Dir
Is
Empty
(
userDir
))
if
(
FsUtils
.
DirEmpty
Except
(
userDir
,
_config
.
MarkerFile
))
continue
;
Log
.
Info
(
"Found new files in [{0}]"
,
userDir
.
FullName
);
...
...
@@ -658,38 +658,6 @@ namespace AutoTx
#
region
filesystem
tasks
(
check
,
move
,
...)
/// <summary>
/// Check if a given directory is empty. If a marker file is set in the config a
/// file with this name will be created inside the given directory and will be
/// skipped itself when checking for files and directories.
/// </summary>
/// <param name="dirInfo">The directory to check.</param>
/// <returns>True if access is denied or the dir is empty, false otherwise.</returns>
private
bool
IncomingDirIsEmpty
(
DirectoryInfo
dirInfo
)
{
try
{
var
filesInTree
=
dirInfo
.
GetFiles
(
"*"
,
SearchOption
.
AllDirectories
);
if
(
string
.
IsNullOrEmpty
(
_config
.
MarkerFile
))
return
filesInTree
.
Length
==
0
;
// check if there is ONLY the marker file:
if
(
filesInTree
.
Length
==
1
&&
filesInTree
[
0
].
Name
.
Equals
(
_config
.
MarkerFile
))
return
true
;
// make sure the marker file is there:
var
markerFilePath
=
Path
.
Combine
(
dirInfo
.
FullName
,
_config
.
MarkerFile
);
if
(!
File
.
Exists
(
markerFilePath
))
File
.
Create
(
markerFilePath
);
return
filesInTree
.
Length
==
0
;
}
catch
(
Exception
e
)
{
Log
.
Error
(
"Error accessing directories: {0}"
,
e
.
Message
);
}
// if nothing triggered before, we pretend the dir is empty:
return
true
;
}
/// <summary>
/// Collect individual files in a user dir in a specific sub-directory. If a marker
/// file is set in the configuration, this will be skipped in the checks.
...
...
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