1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.cache.setup; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.Path; |
37 |
|
import info.magnolia.module.InstallContext; |
38 |
|
import info.magnolia.module.cache.filter.CacheResponseWrapper; |
39 |
|
import info.magnolia.module.delta.AbstractTask; |
40 |
|
import info.magnolia.module.delta.TaskExecutionException; |
41 |
|
|
42 |
|
import java.io.File; |
43 |
|
import java.io.FileFilter; |
44 |
|
|
45 |
|
import org.slf4j.Logger; |
46 |
|
import org.slf4j.LoggerFactory; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 4 |
Complexity Density: 0.44 |
|
51 |
|
public class RemoveCacheTempFilesTask extends AbstractTask { |
52 |
|
|
53 |
|
private static final Logger log = LoggerFactory.getLogger(RemoveCacheTempFilesTask.class); |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
4 |
public RemoveCacheTempFilesTask() {... |
56 |
4 |
super("Delete cache temp files", "Delete cache temp files if presented in temp directory [" + Path.getTempDirectory().getPath() +"]"); |
57 |
|
} |
58 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
59 |
4 |
@Override... |
60 |
|
public void execute(InstallContext installContext) throws TaskExecutionException { |
61 |
4 |
File tempDirectory = Path.getTempDirectory(); |
62 |
|
|
63 |
4 |
File[] tempFiles = tempDirectory.listFiles(new FileFilter() { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
6 |
@Override... |
65 |
|
public boolean accept(File file) { |
66 |
6 |
return !file.isDirectory() && file.getName().startsWith(CacheResponseWrapper.CACHE_TEMP_FILE_PREFIX); |
67 |
|
} |
68 |
|
}); |
69 |
|
|
70 |
4 |
for(File tempFile : tempFiles) { |
71 |
4 |
log.warn("Deleting obsolete cache temp file: " + tempFile); |
72 |
4 |
if(!tempFile.delete()){ |
73 |
0 |
log.error("Can't remove cache temp file: " + tempFile); |
74 |
4 |
}; |
75 |
|
} |
76 |
|
} |
77 |
|
} |