@@ -103,22 +103,54 @@ public void setFilter(final FileListFilter filter) {
103
103
104
104
private List <File > listEligibleFiles (final Path input ) {
105
105
final List <File > listingLocalFiles = new LinkedList <>();
106
- if (!Files .isReadable (input )) {
107
- LOG .warn ("Cannot get directory listing for '{}'. Input path is not readable." , input );
106
+ if (!isPathReadable (input )) {
108
107
return listingLocalFiles ;
109
108
}
110
109
111
- if (!Files .isDirectory (input )) {
112
- LOG .warn ("Cannot get directory listing for '{}'. Input path is not a directory." , input );
113
- return listingLocalFiles ;
114
- }
115
-
116
- if (isHidden (input )) {
110
+ if (!isPathDirectory (input ) || isHidden (input )) {
117
111
return listingLocalFiles ;
118
112
}
119
113
120
114
final List <Path > decompressedDirs = new LinkedList <>();
121
115
final List <Path > directories = new LinkedList <>();
116
+ processFiles (input , listingLocalFiles , directories , decompressedDirs );
117
+
118
+ if (config .isRecursiveScanEnable () && !directories .isEmpty ()) {
119
+ listingLocalFiles .addAll (scanRecursiveDirectories (directories , decompressedDirs ));
120
+ }
121
+ return listingLocalFiles ;
122
+ }
123
+
124
+ private boolean isPathReadable (Path path ) {
125
+ if (!Files .isReadable (path )) {
126
+ LOG .warn ("Cannot get directory listing for '{}'. Input path is not readable." , path );
127
+ return false ;
128
+ }
129
+ return true ;
130
+ }
131
+
132
+ private boolean isPathDirectory (Path path ) {
133
+ if (!Files .isDirectory (path )) {
134
+ LOG .warn ("Cannot get directory listing for '{}'. Input path is not a directory." , path );
135
+ return false ;
136
+ }
137
+ return true ;
138
+ }
139
+
140
+ private boolean isHidden (final Path input ) {
141
+ try {
142
+ return Files .isHidden (input );
143
+ } catch (IOException e ) {
144
+ LOG .warn (
145
+ "Error while checking if input file is hidden '{}': {}" ,
146
+ input ,
147
+ e .getLocalizedMessage ());
148
+ return false ;
149
+ }
150
+ }
151
+
152
+ private void processFiles (Path input , List <File > listingLocalFiles , List <Path > directories ,
153
+ List <Path > decompressedDirs ) {
122
154
try (DirectoryStream <Path > stream = Files .newDirectoryStream (input )) {
123
155
for (Path path : stream ) {
124
156
if (Files .isDirectory (path )) {
@@ -137,10 +169,8 @@ private List<File> listEligibleFiles(final Path input) {
137
169
final Path decompressed = codec .decompress (file ).toPath ();
138
170
listingLocalFiles .addAll (listEligibleFiles (decompressed ));
139
171
decompressedDirs .add (decompressed );
140
- if (config .isDeleteCompressFileEnable () && decompressed .toFile ().exists ()) {
141
- file .delete ();
142
- }
143
- LOG .debug ("Compressed file deleted successfully : {}" , path );
172
+ LOG .debug ("Compressed file extracted successfully : {}" , path );
173
+ handleFileDeletion (file , path );
144
174
} catch (IOException | SecurityException e ) {
145
175
if (e instanceof IOException ) {
146
176
LOG .warn ("Error while decompressing input file '{}'. Skip and continue." , path , e );
@@ -158,34 +188,29 @@ private List<File> listEligibleFiles(final Path input) {
158
188
}
159
189
}
160
190
} catch (IOException e ) {
161
- LOG .error (
162
- "Error while getting directory listing for {}: {}" ,
163
- input ,
164
- e .getLocalizedMessage ());
191
+ LOG .error ("Error while getting directory listing for {}: {}" , input , e .getLocalizedMessage ());
165
192
throw new ConnectException (e );
166
193
}
167
194
168
- if (config .isRecursiveScanEnable () && !directories .isEmpty ()) {
169
- listingLocalFiles .addAll (directories .stream ()
170
- .filter (f -> !decompressedDirs .contains (f ))
171
- .flatMap (f -> listEligibleFiles (f ).stream ())
172
- .collect (Collectors .toList ()));
173
- }
174
- return listingLocalFiles ;
175
195
}
176
196
177
- private boolean isHidden (final Path input ) {
178
- try {
179
- return Files .isHidden (input );
180
- } catch (IOException e ) {
181
- LOG .warn (
182
- "Error while checking if input file is hidden '{}': {}" ,
183
- input ,
184
- e .getLocalizedMessage ());
185
- return false ;
197
+ private void handleFileDeletion (File file , Path path ) {
198
+ if (config .isDeleteCompressFileEnable () && file .exists ()) {
199
+ if (file .delete ()) {
200
+ LOG .debug ("Compressed file deleted successfully : {}" , path );
201
+ } else {
202
+ LOG .warn ("Error while deleting input file '{}'. Skip and continue." , path );
203
+ }
186
204
}
187
205
}
188
206
207
+ private List <File > scanRecursiveDirectories (List <Path > directories , List <Path > decompressedDirs ) {
208
+ return directories .stream ()
209
+ .filter (f -> !decompressedDirs .contains (f ))
210
+ .flatMap (f -> listEligibleFiles (f ).stream ())
211
+ .collect (Collectors .toList ());
212
+ }
213
+
189
214
/**
190
215
* {@inheritDoc}
191
216
*/
0 commit comments