diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-05-12 09:46:15 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-05-12 09:46:15 -0500 |
| commit | 5ddef023a9dbaf1ace7e534d5c45bee7094d8f16 (patch) | |
| tree | 2c05dd8b654a340395a8f1649f1585d279cec619 | |
| parent | c12ab7abf3a7591df11ea589e9cb8c16b65aaa3b (diff) | |
| download | slskd-5ddef023a9dbaf1ace7e534d5c45bee7094d8f16.tar.gz | |
ensure app directory exists and is writeable
| -rw-r--r-- | src/slskd/Program.cs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index a3b16af1..e62a3529 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -213,6 +213,37 @@ namespace slskd return; } + // ensure the application directory exists and is writeable. the most comprehensive way to test this is to try + // to write a file to it. + try + { + if (!Directory.Exists(Options.Directories.App)) + { + Directory.CreateDirectory(Options.Directories.App); + } + } + catch (Exception ex) + { + Console.WriteLine($"App directory {Options.Directories.App} does not exist, and could not be created: {ex.Message}"); + } + + try + { + if (!Directory.Exists(Options.Directories.App)) + { + Directory.CreateDirectory(Options.Directories.App); + } + + var probe = Path.Combine(Options.Directories.App, "probe"); + File.WriteAllText(Path.Combine(Options.Directories.App, "probe"), string.Empty); + File.Delete(probe); + } + catch (Exception ex) + { + Console.WriteLine($"App directory {Options.Directories.App} is not writeable: {ex.Message}"); + return; + } + if (!Options.NoLogo) { PrintLogo(Version); |
