aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-11-09 08:52:59 -0600
committerJP Dillingham <jpdillingham@gmail.com>2021-11-09 08:52:59 -0600
commit86f5e46c2dfe595d8a970cc2f9e49d2520f14b55 (patch)
tree4499b75e43e9a3395a7d02ea75d959a40447ff46 /src
parent1f296c3a87f01a9b68cef0842fe8d2ec05c65126 (diff)
downloadslskd-86f5e46c2dfe595d8a970cc2f9e49d2520f14b55.tar.gz
verify directories before config
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Program.cs76
1 files changed, 38 insertions, 38 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 3aba9ec3..2403dbbf 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -198,8 +198,23 @@ namespace slskd
return;
}
- // the application isn't being run in command mode. load all configuration values and proceed
- // with bootstrapping.
+ // the application isn't being run in command mode. verify (create if needed) default application
+ // directories. if the downloads or complete directories are overridden in config, those will be
+ // validated after the config is loaded.
+ try
+ {
+ VerifyDirectory(AppDirectory, createIfMissing: true, verifyWriteable: true);
+ VerifyDirectory(Path.Combine(AppDirectory, "data"), createIfMissing: true, verifyWriteable: true);
+ VerifyDirectory(DefaultDownloadsDirectory, createIfMissing: true, verifyWriteable: true);
+ VerifyDirectory(DefaultIncompleteDirectory, createIfMissing: true, verifyWriteable: true);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Filesystem exception: {ex.Message}");
+ return;
+ }
+
+ // load and validate the configuration
try
{
Configuration = new ConfigurationBuilder()
@@ -226,36 +241,6 @@ namespace slskd
return;
}
- try
- {
- VerifyDirectory(AppDirectory, createIfMissing: true, verifyWriteable: true);
- VerifyDirectory(Path.Combine(AppDirectory, "data"), createIfMissing: true, verifyWriteable: true);
-
- VerifyDirectory(OptionsAtStartup.Directories.Incomplete, createIfMissing: true, verifyWriteable: true);
- VerifyDirectory(OptionsAtStartup.Directories.Downloads, createIfMissing: true, verifyWriteable: true);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Filesystem exception: {ex.Message}");
- return;
- }
-
- // for convenience, try to copy the example configuration file to the application directory if no configuration
- // file exists. if any part fails, just move on silently.
- if (!IOFile.Exists(ConfigurationFile))
- {
- try
- {
- var source = Path.Combine(AppContext.BaseDirectory, "config", $"{AppName}.example.yml");
- var destination = ConfigurationFile;
- IOFile.Copy(source, destination);
- }
- catch
- {
- // no-op
- }
- }
-
Log.Logger = (OptionsAtStartup.Debug ? new LoggerConfiguration().MinimumLevel.Debug() : new LoggerConfiguration().MinimumLevel.Information())
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("System.Net.Http.HttpClient", OptionsAtStartup.Debug ? LogEventLevel.Warning : LogEventLevel.Fatal)
@@ -299,11 +284,6 @@ namespace slskd
PrintLogo(Version);
}
- if (!IOFile.Exists(ConfigurationFile))
- {
- logger.Warning($"Configuration file '{ConfigurationFile}' could not be found and was not loaded.");
- }
-
logger.Information("Version: {Version}", Version);
if (IsCanary)
@@ -313,9 +293,29 @@ namespace slskd
logger.Warning($"Please report any issues here: {IssuesUrl}");
}
- logger.Information("Instance Name: {InstanceName}", OptionsAtStartup.InstanceName);
logger.Information("Invocation ID: {InvocationId}", InvocationId);
logger.Information("Process ID: {ProcessId}", ProcessId);
+ logger.Information("Instance Name: {InstanceName}", OptionsAtStartup.InstanceName);
+
+ logger.Information("Using application directory {AppDirectory}", AppDirectory);
+ logger.Information("Using configuration file {ConfigurationFile}", ConfigurationFile);
+
+ // for convenience, try to copy the example configuration file to the application directory if no configuration
+ // file exists. if any part fails, just move on silently.
+ if (!IOFile.Exists(ConfigurationFile))
+ {
+ try
+ {
+ logger.Warning("Configuration file {ConfigurationFile} does not exist; creating from example", ConfigurationFile);
+ var source = Path.Combine(AppContext.BaseDirectory, "config", $"{AppName}.example.yml");
+ var destination = ConfigurationFile;
+ IOFile.Copy(source, destination);
+ }
+ catch (Exception ex)
+ {
+ logger.Error("Failed to create configuration file {ConfigurationFile}: {Message}", ConfigurationFile, ex.Message);
+ }
+ }
if (!string.IsNullOrEmpty(OptionsAtStartup.Logger.Loki))
{