mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-19 19:01:22 +00:00
add cleanup of chunks at startup
This commit is contained in:
parent
517f7b92d5
commit
6145db5357
@ -46,6 +46,7 @@ import org.qortal.utils.*;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
|
||||
import java.awt.TrayIcon.MessageType;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -53,6 +54,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.SecureRandom;
|
||||
@ -70,6 +72,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Controller extends Thread {
|
||||
|
||||
@ -396,6 +399,9 @@ public class Controller extends Thread {
|
||||
|
||||
Controller.newInstance(args);
|
||||
|
||||
|
||||
cleanChunkUploadTempDir(); // cleanup leftover chunks from streaming to disk
|
||||
|
||||
LOGGER.info("Starting NTP");
|
||||
Long ntpOffset = Settings.getInstance().getTestNtpOffset();
|
||||
if (ntpOffset != null)
|
||||
@ -2174,6 +2180,24 @@ public class Controller extends Thread {
|
||||
return now - offset;
|
||||
}
|
||||
|
||||
private static void cleanChunkUploadTempDir() {
|
||||
Path uploadsTemp = Paths.get("uploads-temp");
|
||||
if (!Files.exists(uploadsTemp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try (Stream<Path> paths = Files.walk(uploadsTemp)) {
|
||||
paths.sorted(Comparator.reverseOrder())
|
||||
.map(Path::toFile)
|
||||
.forEach(File::delete);
|
||||
|
||||
LOGGER.info("Cleaned up all temporary uploads in {}", uploadsTemp);
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Failed to clean up uploads-temp directory", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public StatsSnapshot getStatsSnapshot() {
|
||||
return this.stats;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user