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( final ExecutorService executor, final Path path, final Map<Path, FileAttributes> map, final 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( final Path dir, final BasicFileAttributes attrs ) throws IOException {
55 if( dir != null ) {
56 if( dir.endsWith( "$RECYCLE.BIN" ) ||
57 dir.endsWith( "Papierkorb" ) ||
58 attrs.isSymbolicLink() ||
59 attrs.isOther() ) { return FileVisitResult.SKIP_SUBTREE; }
60 }
61 return FileVisitResult.CONTINUE;
62 }
63
64 @Override
65 public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException {
66 if( attrs.isSymbolicLink() || !attrs.isRegularFile() ) {
67 Debug.printDebug( "[File Visit] Skip_VisitFile -> " + file );
68 return FileVisitResult.CONTINUE;
69 }
70 executor.execute( new FileScan( file.normalize(), path.normalize(), map, deepScan, attrs ) );
71 return FileVisitResult.CONTINUE;
72 }
73
74 @Override
75 public FileVisitResult visitFileFailed( final Path file, final IOException exc ) throws IOException {
76 Debug.printDebug( "[File Visit] VisitFileFailed -> " + file );
77 return FileVisitResult.CONTINUE;
78 }
79
80 @Override
81 public FileVisitResult postVisitDirectory( final Path dir, final IOException exc ) throws IOException {
82 return FileVisitResult.CONTINUE;
83 }
84
85 }