@@ -115,34 +115,23 @@ public void clearTmpDir() {
115
115
* @param temporaryDirectory temporary directory
116
116
*/
117
117
private void clearDirectory (String temporaryDirectory ) {
118
- final Path dir = Paths .get (temporaryDirectory );
119
118
final Instant cutoff = Instant .now ().minus (Duration .ofDays (TMP_DIR_AGE_LIMIT_DAYS ));
120
- // TODO: Commons IO 2.12 has a constructor that takes an Instant; drop the Date#from call here when we upgrade.
121
- final AgeFileFilter fileAndDirFilter = new AgeFileFilter (Date .from (cutoff ));
122
- final AccumulatorPathVisitor visitor = AccumulatorPathVisitor .withLongCounters (fileAndDirFilter , fileAndDirFilter );
123
-
124
- // Walk the files.
125
- try {
126
- Files .walkFileTree (dir , Collections .emptySet (), /* maxDepth */ 1 , visitor );
127
- } catch (IOException e ) {
128
- // Really unexpected. walkFileTree should throw an IllegalArgumentException for negative maxDepth (clearly
129
- // not happening here), a SecurityException if the security manager denies access, or this IOException in
130
- // the cases where an I/O error happened (disk error, OS error, file not found, etc.). So just a warning.
131
- logger .warn (String .format ("Unexpected I/O error was thrown walking directory [%s]: %s" , dir , e .getMessage ()), e );
132
- }
133
119
134
- // Delete the directories accumulated by the visitor.
135
- final List <Path > dirList = visitor .getDirList ();
136
- dirList .forEach (tooOldDeleteMe -> {
137
- File fileToDelete = tooOldDeleteMe .toFile ();
138
- try {
139
- FileUtils .forceDelete (fileToDelete );
140
- } catch (IOException e ) {
141
- // Here we probably have a more serious case. Since the Git repository, RO directory, or graphs are
142
- // not expected to be in use, and the application must have access, I/O errors are not expected and
143
- // must be treated as errors.
144
- logger .error (String .format ("Failed to delete old temporary file or directory [%s]: %s" , fileToDelete .getAbsolutePath (), e .getMessage ()), e );
120
+ File temporaryDirectoryFile = new File (temporaryDirectory );
121
+ String [] files = temporaryDirectoryFile .list (new AgeFileFilter (Date .from (cutoff )));
122
+
123
+ if (files != null && files .length > 0 ) {
124
+ for (String fileName : files ) {
125
+ File fileToDelete = new File (temporaryDirectoryFile , fileName );
126
+ try {
127
+ FileUtils .forceDelete (fileToDelete );
128
+ } catch (IOException e ) {
129
+ // Here we probably have a more serious case. Since the Git repository, RO directory, or graphs are
130
+ // not expected to be in use, and the application must have access, I/O errors are not expected and
131
+ // must be treated as errors.
132
+ logger .error (String .format ("Failed to delete old temporary file or directory [%s]: %s" , fileToDelete .getAbsolutePath (), e .getMessage ()), e );
133
+ }
145
134
}
146
- });
135
+ }
147
136
}
148
137
}
0 commit comments