-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Quick fix" for empty folders and folders with only ignored filed
- Loading branch information
1 parent
fa20318
commit 2d4e12b
Showing
5 changed files
with
106 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
package org.roda.rodain.rules.filters; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.roda.rodain.utils.Utils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* @author Andre Pereira [email protected] | ||
* @since 04-01-2016. | ||
*/ | ||
public class IgnoredFilter { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(IgnoredFilter.class.getName()); | ||
|
||
|
||
private static Set<String> rules = new HashSet<>(); | ||
|
||
private IgnoredFilter() { | ||
|
@@ -63,6 +72,12 @@ public static boolean isIgnored(Path path) { | |
break; | ||
} | ||
} | ||
|
||
if(!result){ | ||
if (Files.isDirectory(path)) { | ||
result = !Utils.containsAtLeastOneNotIgnoredFile(path); | ||
} | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/org/roda/rodain/utils/ValidFilesCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.roda.rodain.utils; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.FileVisitor; | ||
import java.nio.file.Path; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
|
||
import org.roda.rodain.rules.filters.IgnoredFilter; | ||
|
||
class ValidFilesCounter implements FileVisitor<Path> { | ||
int validFiles; | ||
|
||
public ValidFilesCounter() { | ||
validFiles = 0; | ||
} | ||
|
||
@Override | ||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { | ||
/*if (IgnoredFilter.isIgnored(dir)) { | ||
return FileVisitResult.SKIP_SUBTREE; | ||
}else{ | ||
return FileVisitResult.CONTINUE; | ||
}*/ | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { | ||
if (!IgnoredFilter.isIgnored(file)) { | ||
validFiles++; | ||
return FileVisitResult.TERMINATE; | ||
} | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
public int getValidFiles() { | ||
return validFiles; | ||
} | ||
|
||
} |