CleanupTask.java
4.86 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.pdfg.common.AESProperties
* com.adobe.pdfg.exception.ConfigException
* com.adobe.pdfg.service.api.PDFGConfigService
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.pdfg.impl;
import com.adobe.pdfg.common.AESProperties;
import com.adobe.pdfg.exception.ConfigException;
import com.adobe.pdfg.service.api.PDFGConfigService;
import java.io.File;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CleanupTask
implements Runnable {
private static volatile boolean IS_TASK_ACTIVE = false;
private List<File> listOfFolders = null;
private long jobExpiration = 1000 * (long)AESProperties.getJobExpirationSeconds();
private static Logger logger = LoggerFactory.getLogger((String)"PDFG Cleanup Daemon");
private static final long MILLISECONDS_PER_SECOND = 1000;
private final PDFGConfigService configService;
public CleanupTask(PDFGConfigService configService) {
if (this.jobExpiration == 0) {
this.jobExpiration = 86400000;
}
this.configService = configService;
logger.debug("Cleanup expiration time is set to " + this.jobExpiration + " ms.");
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void run() {
logger.debug("Woken up at " + new Date());
if (!IS_TASK_ACTIVE) {
try {
IS_TASK_ACTIVE = true;
this.cleanUp();
Object var2_1 = null;
IS_TASK_ACTIVE = false;
}
catch (Throwable var1_3) {
Object var2_2 = null;
IS_TASK_ACTIVE = false;
throw var1_3;
}
} else {
logger.debug("Previous cleanup is still in progress.");
}
}
private void cleanUp() {
logger.info("Performing cleanup of old PDFG files");
this.populateListOfFolders();
long currentTime = System.currentTimeMillis();
for (File folder : this.listOfFolders) {
this.cleanUpFolder(folder, currentTime, 0);
}
}
private boolean cleanUpFolder(File file, long currentTime, int level) {
logger.debug("Cleaning up folder: " + file.getAbsolutePath());
boolean bCleanedAll = true;
File[] files = file.listFiles();
if (files != null && files.length != 0) {
for (int count = 0; count < files.length; ++count) {
File currentFile = files[count];
if (currentFile.isFile()) {
long timeModified = currentFile.lastModified();
if (currentTime - timeModified > this.jobExpiration) {
boolean bCleanedCurrent = currentFile.delete();
if (bCleanedCurrent) {
logger.debug("Successful file deletion: " + currentFile.getAbsolutePath());
} else {
logger.debug("File deletion failure: " + currentFile.getAbsolutePath());
}
bCleanedAll = bCleanedAll && bCleanedCurrent;
continue;
}
logger.debug("File too young to be cleaned up: " + currentFile.getAbsolutePath());
bCleanedAll = false;
continue;
}
boolean bCleanedSubFolder = this.cleanUpFolder(currentFile, currentTime, level + 1);
if (bCleanedSubFolder) {
boolean deleteThisFolder = false;
if (level == 0) {
deleteThisFolder = true;
} else {
long timeModified = currentFile.lastModified();
boolean bl = deleteThisFolder = currentTime - timeModified > this.jobExpiration;
}
if (!deleteThisFolder) continue;
boolean bCleanedCurrent = currentFile.delete();
if (bCleanedCurrent) {
logger.debug("Successful folder deletion: " + currentFile.getAbsolutePath());
} else {
logger.debug("Folder deletion failure: " + currentFile.getAbsolutePath());
}
bCleanedAll = bCleanedAll && bCleanedCurrent;
continue;
}
bCleanedAll = false;
}
}
return bCleanedAll;
}
void populateListOfFolders() {
if (this.listOfFolders == null) {
try {
this.listOfFolders = this.configService.getPDFGTempFolders();
}
catch (ConfigException e) {
throw new RuntimeException((Throwable)e);
}
}
}
}