diff --git a/ATXCommon/FsUtils.cs b/ATXCommon/FsUtils.cs index c21eaa5b81a5ef9788589ce1aabc6c66fd6b3707..6ddc193ab2cd97f7cfbf5877a23f293bd907e850 100644 --- a/ATXCommon/FsUtils.cs +++ b/ATXCommon/FsUtils.cs @@ -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; + } } } diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index 33707e50d0f9259517b21c09351ba4c8245133b1..243548466484013d1303c4f2357705b8e57dfcd7 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -593,7 +593,7 @@ namespace AutoTx private void CheckIncomingDirectories() { // iterate over all user-subdirectories: foreach (var userDir in new DirectoryInfo(_incomingPath).GetDirectories()) { - if (IncomingDirIsEmpty(userDir)) + if (FsUtils.DirEmptyExcept(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.