1 package de.spiritscorp.datasync.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.io.IOException;
24 import java.nio.file.FileVisitResult;
25 import java.nio.file.FileVisitor;
26 import java.nio.file.Path;
27 import java.nio.file.attribute.BasicFileAttributes;
28 import java.util.Map;
29 import java.util.concurrent.ExecutorService;
30
31 import de.spiritscorp.datasync.ScanType;
32 import de.spiritscorp.datasync.io.Debug;
33
34 class FileVisit implements FileVisitor<Path> {
35 private final ExecutorService executor;
36 private final Path path;
37 private final Map<Path, FileAttributes> map;
38 private final ScanType deepScan;
39
40
41
42
43
44
45
46 FileVisit( ExecutorService executor, Path path, Map<Path, FileAttributes> map, ScanType deepScan ) {
47 this.executor = executor;
48 this.path = path;
49 this.map = map;
50 this.deepScan = deepScan;
51 }
52
53 @Override
54 public FileVisitResult preVisitDirectory( Path dir, BasicFileAttributes attrs ) throws IOException {
55 if( dir != null ) {
56 if( dir.endsWith( "$RECYCLE.BIN" ) ||
57 dir.endsWith( "Papierkorb" ) ||
58 attrs.isSymbolicLink() ||
59 attrs.isOther() ) {
60
61 return FileVisitResult.SKIP_SUBTREE;
62 }
63 }
64 return FileVisitResult.CONTINUE;
65 }
66
67 @Override
68 public FileVisitResult visitFile( Path file, BasicFileAttributes attrs ) throws IOException {
69 if( attrs.isSymbolicLink() || !attrs.isRegularFile() ) {
70 Debug.printDebug( "[FileVisit] Skip_VisitFile -> " + file );
71 return FileVisitResult.CONTINUE;
72 }
73 executor.execute( new FileScan( file, path, map, deepScan, attrs ) );
74 return FileVisitResult.CONTINUE;
75 }
76
77 @Override
78 public FileVisitResult visitFileFailed( final Path file, final IOException exc ) throws IOException {
79 Debug.printDebug( "[FileVisit] VisitFileFailed -> " + file );
80 return FileVisitResult.CONTINUE;
81 }
82
83 @Override
84 public FileVisitResult postVisitDirectory( Path dir, IOException exc ) throws IOException {
85 return FileVisitResult.CONTINUE;
86 }
87
88 }