aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-07-28 08:11:40 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-07-28 08:11:40 -0500
commit6e0867604f1fd571f4ab3307c0522fe5f11df76b (patch)
tree7e8c8f45d6f5e03af68c739ac9948a07435f13e5 /src
parent06852f180bc4bdf2c9ef14ba774347e2da8949da (diff)
downloadslskd-6e0867604f1fd571f4ab3307c0522fe5f11df76b.tar.gz
tweak directory validation to log warnings for missing shares
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Program.cs58
1 files changed, 37 insertions, 21 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index b5275756..fa1be786 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -212,19 +212,6 @@ namespace slskd
return;
}
- try
- {
- VerifyOrCreateDirectory(OptionsAtStartup.Directories.App);
- VerifyOrCreateDirectory(OptionsAtStartup.Directories.Incomplete);
- VerifyOrCreateDirectory(OptionsAtStartup.Directories.Downloads);
- VerifyOrCreateDirectory(OptionsAtStartup.Directories.Shared, verifyWriteable: false);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Filesystem exception: {ex.Message}");
- return;
- }
-
Log.Logger = (OptionsAtStartup.Debug ? new LoggerConfiguration().MinimumLevel.Debug() : new LoggerConfiguration().MinimumLevel.Information())
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("slskd.API.Authentication.PassthroughAuthenticationHandler", LogEventLevel.Information)
@@ -249,6 +236,26 @@ namespace slskd
var logger = Log.ForContext(typeof(Program));
+ try
+ {
+ VerifyDirectory(OptionsAtStartup.Directories.App, createIfMissing: true, verifyWriteable: true);
+ VerifyDirectory(OptionsAtStartup.Directories.Incomplete, createIfMissing: true, verifyWriteable: true);
+ VerifyDirectory(OptionsAtStartup.Directories.Downloads, createIfMissing: true, verifyWriteable: true);
+
+ foreach (var share in OptionsAtStartup.Directories.Shared)
+ {
+ if (!VerifyDirectory(share, createIfMissing: false, verifyWriteable: false))
+ {
+ logger.Warning("Shared directory {Directory} does not exist", share);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ logger.Error(ex, "Filesystem exception: {Message}", ex.Message);
+ return;
+ }
+
if (!OptionsAtStartup.NoLogo)
{
PrintLogo(Version);
@@ -505,19 +512,26 @@ namespace slskd
Console.WriteLine(banner);
}
- private static void VerifyOrCreateDirectory(string directory, bool verifyWriteable = true)
+ private static bool VerifyDirectory(string directory, bool createIfMissing = true, bool verifyWriteable = true)
{
- try
+ if (!Directory.Exists(directory))
{
- if (!Directory.Exists(directory))
+ if (createIfMissing)
+ {
+ try
+ {
+ Directory.CreateDirectory(directory);
+ }
+ catch (Exception ex)
+ {
+ throw new IOException($"Directory {directory} does not exist, and could not be created: {ex.Message}", ex);
+ }
+ }
+ else
{
- Directory.CreateDirectory(directory);
+ return false;
}
}
- catch (Exception ex)
- {
- throw new IOException($"Directory {directory} does not exist, and could not be created: {ex.Message}", ex);
- }
if (verifyWriteable)
{
@@ -533,6 +547,8 @@ namespace slskd
throw new IOException($"Directory {directory} is not writeable: {ex.Message}", ex);
}
}
+
+ return true;
}
}
} \ No newline at end of file