mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Assume empty channels dir means no channels
This commit is contained in:
1 file changed
+12
-1
@@ -26,6 +26,7 @@ import com.google.inject.Injector;
|
|||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -96,7 +97,7 @@ public class CarbonChannelRegistry extends RegistryImpl<Key, ChatChannel> implem
|
|||||||
this.basicChannel = this.injector.getInstance(BasicChatChannel.class);
|
this.basicChannel = this.injector.getInstance(BasicChatChannel.class);
|
||||||
this.defaultKey = this.configFactory.primaryConfig().defaultChannel();
|
this.defaultKey = this.configFactory.primaryConfig().defaultChannel();
|
||||||
|
|
||||||
if (!Files.exists(channelDirectory)) {
|
if (!Files.exists(channelDirectory) || isPathEmpty(channelDirectory)) {
|
||||||
// folder doesn't exist, no channels setup
|
// folder doesn't exist, no channels setup
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(channelDirectory);
|
Files.createDirectories(channelDirectory);
|
||||||
@@ -225,4 +226,14 @@ public class CarbonChannelRegistry extends RegistryImpl<Key, ChatChannel> implem
|
|||||||
return this.defaultValue();
|
return this.defaultValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPathEmpty(final Path path) {
|
||||||
|
try (DirectoryStream<Path> directory = Files.newDirectoryStream(path)) {
|
||||||
|
return !directory.iterator().hasNext();
|
||||||
|
} catch (final IOException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user