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 = () -> { TimerTask cleaner;
(cleaner = new TimerTask() {
@Override
public void run() {
try { try {
if (new File(dir, "Recently Deleted").exists()) { File recycle = new File(dir, "Recently Deleted");
int f = new File(dir, "Recently Deleted").listFiles().length; if (recycle.isDirectory()) {
for (File file : new File(dir, "Recently Deleted").listFiles()) { int kept = 0;
for (File file : recycle.listFiles()) {
try { try {
if (file.isDirectory()) { if (file.isDirectory()) {
if (new File(dir, "Recently Deleted/" + file.getName() + "/info.json").exists()) { if (new File(recycle, file.getName() + "/info.json").exists()) {
FileReader reader = new FileReader(new File(dir, "Recently Deleted/" + file.getName() + "/info.json")); FileReader reader = new FileReader(new File(recycle, file.getName() + "/info.json"));
YAMLSection info = new YAMLSection(new Gson().fromJson(Util.readAll(reader), Map.class)); YAMLSection info = new YAMLSection(new Gson().fromJson(Util.readAll(reader), Map.class));
reader.close(); reader.close();
if (info.contains("Timestamp")) { if (info.contains("Timestamp")) {
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - info.getLong("Timestamp")) >= 7) { if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - info.getLong("Timestamp")) < 7) {
Directories.delete(file); ++kept;
f--; continue;
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());
} }
Directories.delete(file);
} else { } else {
Files.delete(file.toPath()); Files.delete(file.toPath());
f--;
Logger.get("SubServers").info("Removed ./SubServers/Recently Deleted/" + file.getName());
} }
Logger.get("SubServers").info("Removed ./SubServers/Recently Deleted/" + file.getName());
} catch (Exception e) { } catch (Exception e) {
Logger.get("SubServers").info("Problem scanning ./SubServers/Recently Deleted/" + file.getName()); Logger.get("SubServers").warning("Problem scanning ./SubServers/Recently Deleted/" + file.getName());
e.printStackTrace(); e.printStackTrace();
Files.delete(file.toPath()); Files.delete(file.toPath());
} }
} }
if (f <= 0) { if (kept == 0) {
Files.delete(new File(dir, "Recently Deleted").toPath()); Files.delete(recycle.toPath());
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
};
clean.run();
new Timer("SubServers.Bungee::Recycle_Cleaner").scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
clean.run();
} }
}, 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)"); mProxy = new Proxy("(master)");
api.addHostDriver(net.ME1312.SubServers.Bungee.Host.Internal.InternalHost.class, "virtual"); 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 fi
cd ../ cd ../
if [[ $__RETURN -eq 0 ]]; then if [[ $__RETURN -eq 0 ]]; then
echo Copying Finished Jar... echo Copying Finished Jarfile...
if [[ -f "Spigot.jar" ]]; then if [[ -f "Spigot.jar" ]]; then
if [[ -f "Spigot.old.jar" ]]; then if [[ -f "Spigot.old.jar" ]]; then
rm -Rf Spigot.old.jar rm -Rf Spigot.old.jar
@ -71,7 +71,7 @@ if [[ -z "$cache" ]] || [[ ! -f "$cache/Spigot-$version.jar" ]] || [[ "$mode" ==
exit 3 exit 3
fi fi
else else
echo Copying Cached Jar... echo Copying Cached Jarfile...
cp "$cache/Spigot-$version.jar" Spigot.jar cp "$cache/Spigot-$version.jar" Spigot.jar
echo Cleaning Up... echo Cleaning Up...
rm -Rf "$0" rm -Rf "$0"

View File

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

View File

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