diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-07-05 17:51:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-05 17:51:23 -0500 |
| commit | 8551ea1930b6639007d18fdca35bfb4073b16914 (patch) | |
| tree | 2430f701f8359e602f4c16847331c588cb473cca /src/slskd/Program.cs | |
| parent | 8ab0cda52fda8b7e4f0353065c6f0dc5caeeb1f1 (diff) | |
| parent | 4914c3832358218d28f977baed2ddfb1e7e92723 (diff) | |
| download | slskd-8551ea1930b6639007d18fdca35bfb4073b16914.tar.gz | |
Merge branch 'master' into dependabot/npm_and_yarn/src/web/http-proxy-middleware-2.0.9
Diffstat (limited to 'src/slskd/Program.cs')
| -rw-r--r-- | src/slskd/Program.cs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index b7fa47d2..dd85bc21 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -188,6 +188,11 @@ namespace slskd public static string DataDirectory { get; private set; } = null; /// <summary> + /// Gets the path where backups of persistent data saved. + /// </summary> + public static string DataBackupDirectory { get; private set; } = null; + + /// <summary> /// Gets the default fully qualified path to the configuration file. /// </summary> public static string DefaultConfigurationFile { get; private set; } @@ -336,6 +341,7 @@ namespace slskd // derive the application directory value and defaults that are dependent upon it AppDirectory ??= DefaultAppDirectory; DataDirectory = Path.Combine(AppDirectory, "data"); + DataBackupDirectory = Path.Combine(DataDirectory, "backups"); LogDirectory = Path.Combine(AppDirectory, "logs"); ScriptDirectory = Path.Combine(AppDirectory, "scripts"); @@ -353,6 +359,7 @@ namespace slskd { VerifyDirectory(AppDirectory, createIfMissing: true, verifyWriteable: true); VerifyDirectory(DataDirectory, createIfMissing: true, verifyWriteable: true); + VerifyDirectory(DataBackupDirectory, createIfMissing: true, verifyWriteable: true); VerifyDirectory(ScriptDirectory, createIfMissing: true, verifyWriteable: false); VerifyDirectory(DefaultDownloadsDirectory, createIfMissing: true, verifyWriteable: true); VerifyDirectory(DefaultIncompleteDirectory, createIfMissing: true, verifyWriteable: true); @@ -494,6 +501,14 @@ namespace slskd var app = builder.Build(); + if (!OptionsAtStartup.Flags.Volatile) + { + Log.Debug($"Running Migrate()..."); + + // note: if this ever throws, we've forgotten to register a Migrator following database DI config + app.Services.GetService<Migrator>().Migrate(force: OptionsAtStartup.Flags.ForceMigrations); + } + // hack: services that exist only to subscribe to the event bus are not referenced by anything else // and are thus never instantiated. force a reference here so they are created. _ = app.Services.GetService<ScriptService>(); @@ -596,6 +611,12 @@ namespace slskd services.AddDbContext<TransfersDbContext>(DiskConnectionString("transfers")); services.AddDbContext<MessagingDbContext>(DiskConnectionString("messaging")); services.AddDbContext<EventsDbContext>(DiskConnectionString("events")); + + // we're working with non-volatile database files, so register a Migrator to be used later in the + // bootup process. the presence of a Migrator instance in DI determines whether a migration is needed. + // it's important that we keep this list of databases in sync with those used by the application; anything + // not in this list will not be able to be migrated. + services.AddSingleton<Migrator>(_ => new Migrator(databases: ["search", "transfers", "messaging", "events"])); } services.AddSingleton<EventService>(); @@ -653,7 +674,7 @@ namespace slskd if (SQLitePCL.raw.sqlite3_config(SQLitePCL.raw.SQLITE_CONFIG_SERIALIZED) != SQLitePCL.raw.SQLITE_OK) { - throw new InvalidOperationException($"SQLite threading mode could not be set to . Please create a GitHub issue to report this and include details about your environment."); + throw new InvalidOperationException($"SQLite threading mode could not be set to SERIALIZED ({SQLitePCL.raw.SQLITE_CONFIG_SERIALIZED}). Please create a GitHub issue to report this and include details about your environment."); } Log.Debug("SQLite threading mode set to {Mode} ({Number})", "SERIALIZED", SQLitePCL.raw.SQLITE_CONFIG_SERIALIZED); |
