mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-21 17:56:16 +01:00
Optimize the recycle cleaners #87
This commit is contained in:
parent
f7f42c8ba9
commit
903b8a98d3
@ -186,59 +186,49 @@ public final class SubProxy extends BungeeCommon implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Runnable clean = () -> {
|
TimerTask cleaner;
|
||||||
try {
|
(cleaner = new TimerTask() {
|
||||||
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() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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)");
|
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");
|
||||||
|
@ -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"
|
||||||
|
@ -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"
|
||||||
|
@ -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 {
|
try {
|
||||||
if (file.isDirectory()) {
|
File recycle = new File(engine.getRuntimeDirectory(), "Recently Deleted");
|
||||||
if (new File(engine.getRuntimeDirectory(), "Recently Deleted/" + file.getName() + "/info.json").exists()) {
|
if (recycle.isDirectory()) {
|
||||||
FileReader reader = new FileReader(new File(engine.getRuntimeDirectory(), "Recently Deleted/" + file.getName() + "/info.json"));
|
int kept = 0;
|
||||||
JSONObject json = new JSONObject(Util.readAll(reader));
|
for (File file : recycle.listFiles()) {
|
||||||
reader.close();
|
try {
|
||||||
if (json.keySet().contains("Timestamp")) {
|
if (file.isDirectory()) {
|
||||||
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - json.getLong("Timestamp")) >= 7) {
|
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);
|
Directories.delete(file);
|
||||||
f--;
|
} else {
|
||||||
log.info.println("Removed ./Recently Deleted/" + file.getName());
|
Files.delete(file.toPath());
|
||||||
}
|
}
|
||||||
} else {
|
log.info.println("Removed ./SubServers/Recently Deleted/" + file.getName());
|
||||||
Directories.delete(file);
|
} catch (Exception e) {
|
||||||
f--;
|
log.error.println("Problem scanning ./SubServers/Recently Deleted/" + file.getName());
|
||||||
log.info.println("Removed ./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 {
|
if (kept == 0) {
|
||||||
Files.delete(file.toPath());
|
Files.delete(recycle.toPath());
|
||||||
f--;
|
}
|
||||||
log.info.println("Removed ./Recently Deleted/" + file.getName());
|
|
||||||
}
|
}
|
||||||
} 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));
|
||||||
|
Loading…
Reference in New Issue
Block a user