aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/helper/Log.java27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/helper/Log.java b/src/main/java/org/traccar/helper/Log.java
index 9aaf1cfd3..37df6a537 100644
--- a/src/main/java/org/traccar/helper/Log.java
+++ b/src/main/java/org/traccar/helper/Log.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2024 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package org.traccar.helper;
import org.traccar.config.Config;
import org.traccar.config.Keys;
+import org.traccar.model.Pair;
import java.io.BufferedWriter;
import java.io.File;
@@ -30,9 +31,9 @@ import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileStore;
import java.nio.file.FileSystems;
-import java.nio.file.Files;
-import java.nio.file.Path;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Comparator;
import java.util.Date;
import java.util.logging.ConsoleHandler;
import java.util.logging.Formatter;
@@ -40,6 +41,7 @@ import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
+import java.util.stream.Stream;
public final class Log {
@@ -278,17 +280,22 @@ public final class Log {
}
public static long[] getStorageSpace() {
- long usable = 0;
- long total = 0;
- for (Path root : FileSystems.getDefault().getRootDirectories()) {
+ var stores = new ArrayList<Pair<Long, Long>>();
+ for (FileStore store : FileSystems.getDefault().getFileStores()) {
try {
- FileStore store = Files.getFileStore(root);
- usable += store.getUsableSpace();
- total += store.getTotalSpace();
+ long totalSpace = store.getTotalSpace();
+ long usableSpace = store.getUsableSpace();
+ if (totalSpace > 1_000_000_000) {
+ stores.add(new Pair<>(usableSpace, totalSpace));
+ }
} catch (IOException ignored) {
}
}
- return new long[]{usable, total};
+ return stores.stream()
+ .sorted(Comparator.comparingDouble(o -> 1 - o.getFirst() / (double) o.getSecond()))
+ .flatMap(p -> Stream.of(p.getFirst(), p.getSecond()))
+ .mapToLong(Long::longValue)
+ .toArray();
}
}