Optimize the recycle cleaners #87

This commit is contained in:
ME1312 2023-12-24 18:46:25 -05:00
parent f7f42c8ba9
commit 903b8a98d3
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
4 changed files with 78 additions and 83 deletions

View File

@ -186,59 +186,49 @@ public final class SubProxy extends BungeeCommon implements Listener {
}
}
Runnable clean = () -> {
try {
if (new File(dir, "Recently Deleted").exists()) {
int f = new File(dir, "Recently Deleted").listFiles().length;
for (File file : new File(dir, "Recently Deleted").listFiles()) {
try {
if (file.isDirectory()) {
if (new File(dir, "Recently Deleted/" + file.getName() + "/info.json").exists()) {
FileReader reader = new FileReader(new File(dir, "Recently Deleted/" + file.getName() + "/info.json"));
YAMLSection info = new YAMLSection(new Gson().fromJson(Util.readAll(reader), Map.class));
reader.close();
if (info.contains("Timestamp")) {
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - info.getLong("Timestamp")) >= 7) {
Directories.delete(file);
f--;
Logger.get("SubServers").info("Removed ./SubServers/Recently Deleted/" + file.getName());
}
} else {
Directories.delete(file);
f--;
Logger.get("SubServers").info("Removed ./SubServers/Recently Deleted/" + file.getName());
}
} else {
Directories.delete(file);
f--;
Logger.get("SubServers").info("Removed ./SubServers/Recently Deleted/" + file.getName());
}
} else {
Files.delete(file.toPath());
f--;
Logger.get("SubServers").info("Removed ./SubServers/Recently Deleted/" + file.getName());
}
} catch (Exception e) {
Logger.get("SubServers").info("Problem scanning ./SubServers/Recently Deleted/" + file.getName());
e.printStackTrace();
Files.delete(file.toPath());
}
}
if (f <= 0) {
Files.delete(new File(dir, "Recently Deleted").toPath());
}
}
} catch (Exception e) {
e.printStackTrace();
}
};
clean.run();
new Timer("SubServers.Bungee::Recycle_Cleaner").scheduleAtFixedRate(new TimerTask() {
TimerTask cleaner;
(cleaner = new TimerTask() {
@Override
public void run() {
clean.run();
try {
File recycle = new File(dir, "Recently Deleted");
if (recycle.isDirectory()) {
int kept = 0;
for (File file : recycle.listFiles()) {
try {
if (file.isDirectory()) {
if (new File(recycle, file.getName() + "/info.json").exists()) {
FileReader reader = new FileReader(new File(recycle, file.getName() + "/info.json"));
YAMLSection info = new YAMLSection(new Gson().fromJson(Util.readAll(reader), Map.class));
reader.close();
if (info.contains("Timestamp")) {
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - info.getLong("Timestamp")) < 7) {
++kept;
continue;
}
}
}
Directories.delete(file);
} else {
Files.delete(file.toPath());
}
Logger.get("SubServers").info("Removed ./SubServers/Recently Deleted/" + file.getName());
} catch (Exception e) {
Logger.get("SubServers").warning("Problem scanning ./SubServers/Recently Deleted/" + file.getName());
e.printStackTrace();
Files.delete(file.toPath());
}
}
if (kept == 0) {
Files.delete(recycle.toPath());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, TimeUnit.DAYS.toMillis(7), TimeUnit.DAYS.toMillis(7));
}).run();
new Timer("SubServers.Bungee::Recycle_Cleaner").scheduleAtFixedRate(cleaner, TimeUnit.DAYS.toMillis(7), TimeUnit.DAYS.toMillis(7));
mProxy = new Proxy("(master)");
api.addHostDriver(net.ME1312.SubServers.Bungee.Host.Internal.InternalHost.class, "virtual");

View File

@ -39,7 +39,7 @@ if [[ -z "$cache" ]] || [[ ! -f "$cache/Spigot-$version.jar" ]] || [[ "$mode" ==
fi
cd ../
if [[ $__RETURN -eq 0 ]]; then
echo Copying Finished Jar...
echo Copying Finished Jarfile...
if [[ -f "Spigot.jar" ]]; then
if [[ -f "Spigot.old.jar" ]]; then
rm -Rf Spigot.old.jar
@ -71,7 +71,7 @@ if [[ -z "$cache" ]] || [[ ! -f "$cache/Spigot-$version.jar" ]] || [[ "$mode" ==
exit 3
fi
else
echo Copying Cached Jar...
echo Copying Cached Jarfile...
cp "$cache/Spigot-$version.jar" Spigot.jar
echo Cleaning Up...
rm -Rf "$0"

View File

@ -23,14 +23,14 @@ if [[ -z "$cache" ]] || [[ ! -f "$cache/Vanilla-$version.jar" ]]; then
rm -Rf VanillaCord
fi
mkdir VanillaCord
echo Downloading the VanillaCord Launcher...
echo Downloading VanillaCord...
__DL VanillaCord/VanillaCord.jar https://dev.me1312.net/jenkins/job/VanillaCord/lastSuccessfulBuild/artifact/artifacts/VanillaCord.jar; __RETURN=$?
if [[ $__RETURN -eq 0 ]]; then
cd VanillaCord
echo Launching VanillaCord
"$java" -jar VanillaCord.jar "$version"; __RETURN=$?;
if [[ $__RETURN -eq 0 ]]; then
echo Copying Finished Jar...
echo Copying Finished Jarfile...
cd ../
if [[ -f "Vanilla.jar" ]]; then
if [[ -f "Vanilla.old.jar" ]]; then
@ -59,7 +59,7 @@ if [[ -z "$cache" ]] || [[ ! -f "$cache/Vanilla-$version.jar" ]]; then
exit 3
fi
else
echo Copying Cached Jar...
echo Copying Cached Jarfile...
cp "$cache/Vanilla-$version.jar" Vanilla.jar
echo Cleaning Up...
rm -Rf "$0"

View File

@ -127,44 +127,49 @@ public final class ExHost {
log.info.println("Created ./Templates/");
}
if (new File(engine.getRuntimeDirectory(), "Recently Deleted").exists()) {
int f = new File(engine.getRuntimeDirectory(), "Recently Deleted").listFiles().length;
for (File file : new File(engine.getRuntimeDirectory(), "Recently Deleted").listFiles()) {
TimerTask cleaner;
(cleaner = new TimerTask() {
@Override
public void run() {
try {
if (file.isDirectory()) {
if (new File(engine.getRuntimeDirectory(), "Recently Deleted/" + file.getName() + "/info.json").exists()) {
FileReader reader = new FileReader(new File(engine.getRuntimeDirectory(), "Recently Deleted/" + file.getName() + "/info.json"));
JSONObject json = new JSONObject(Util.readAll(reader));
reader.close();
if (json.keySet().contains("Timestamp")) {
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - json.getLong("Timestamp")) >= 7) {
File recycle = new File(engine.getRuntimeDirectory(), "Recently Deleted");
if (recycle.isDirectory()) {
int kept = 0;
for (File file : recycle.listFiles()) {
try {
if (file.isDirectory()) {
if (new File(recycle, file.getName() + "/info.json").exists()) {
FileReader reader = new FileReader(new File(recycle, file.getName() + "/info.json"));
JSONObject info = new JSONObject(Util.readAll(reader));
reader.close();
if (info.keySet().contains("Timestamp")) {
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - info.getLong("Timestamp")) < 7) {
++kept;
continue;
}
}
}
Directories.delete(file);
f--;
log.info.println("Removed ./Recently Deleted/" + file.getName());
} else {
Files.delete(file.toPath());
}
} else {
Directories.delete(file);
f--;
log.info.println("Removed ./Recently Deleted/" + file.getName());
log.info.println("Removed ./SubServers/Recently Deleted/" + file.getName());
} catch (Exception e) {
log.error.println("Problem scanning ./SubServers/Recently Deleted/" + file.getName());
log.error.println(e);
Files.delete(file.toPath());
}
} else {
Directories.delete(file);
f--;
log.info.println("Removed ./Recently Deleted/" + file.getName());
}
} else {
Files.delete(file.toPath());
f--;
log.info.println("Removed ./Recently Deleted/" + file.getName());
if (kept == 0) {
Files.delete(recycle.toPath());
}
}
} catch (Exception e) {
log.error.println(e);
}
}
if (f <= 0) {
Files.delete(new File(engine.getRuntimeDirectory(), "Recently Deleted").toPath());
}
}
}).run();
new Timer("SubServers.Bungee::Recycle_Cleaner").scheduleAtFixedRate(cleaner, TimeUnit.DAYS.toMillis(7), TimeUnit.DAYS.toMillis(7));
Util.reflect(SubLoggerImpl.class.getDeclaredField("logn"), null, config.get().getMap("Settings").getBoolean("Network-Log", true));
Util.reflect(SubLoggerImpl.class.getDeclaredField("logc"), null, config.get().getMap("Settings").getBoolean("Console-Log", true));