Skip to content

Commit

Permalink
tested and improved the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ImUrX committed Nov 6, 2024
1 parent d121973 commit 8eaa59f
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions server/core/src/main/java/dev/slimevr/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.*;
import java.util.Comparator;
import java.util.stream.Stream;


public class ConfigManager {
Expand Down Expand Up @@ -118,17 +120,25 @@ public synchronized void saveConfig() {
// delete accidental folder caused by PR
// https://github.com/SlimeVR/SlimeVR-Server/pull/1176
var cfgFileMaybeFolder = cfgFile.toFile();
if (cfgFileMaybeFolder.isDirectory() && cfgFileMaybeFolder.delete()) {
LogManager
.severe(
"Unable to delete folder that has same name as the config file on path \""
+ cfgFile
+ "\""
);
return;
if (cfgFileMaybeFolder.isDirectory()) {
try (Stream<Path> pathStream = Files.walk(cfgFile)) {
var list = pathStream.sorted(Comparator.reverseOrder()).toList();
for (var path : list) {
Files.delete(path);
}
} catch (IOException e) {
LogManager
.severe(
"Unable to delete folder that has same name as the config file on path \""
+ cfgFile
+ "\""
);
return;
}

}
var cfgFolder = cfgFile.getParent().toFile();
if (!cfgFolder.getAbsoluteFile().exists() && !cfgFolder.mkdirs()) {
var cfgFolder = cfgFile.toAbsolutePath().getParent().toFile();
if (!cfgFolder.exists() && !cfgFolder.mkdirs()) {
LogManager
.severe("Unable to create folders for config on path \"" + cfgFile + "\"");
return;
Expand Down

0 comments on commit 8eaa59f

Please sign in to comment.