From 04d03c5cf9b8debccbc618b2323432bfc86491c2 Mon Sep 17 00:00:00 2001 From: PloughPuff Date: Fri, 18 Jan 2019 10:10:45 +0000 Subject: [PATCH 1/3] Ensure all folders are created before running app --- Jellyfin.Server/Program.cs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index acbe5c7144..4a09645d37 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -45,7 +45,8 @@ namespace Jellyfin.Server Console.WriteLine(version.ToString()); } - ServerApplicationPaths appPaths = createApplicationPaths(options); + ServerApplicationPaths appPaths = CreateApplicationPaths(options); + // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath); await createLogger(appPaths); @@ -130,7 +131,7 @@ namespace Jellyfin.Server } } - private static ServerApplicationPaths createApplicationPaths(StartupOptions options) + private static ServerApplicationPaths CreateApplicationPaths(StartupOptions options) { string programDataPath = Environment.GetEnvironmentVariable("JELLYFIN_DATA_PATH"); if (string.IsNullOrEmpty(programDataPath)) @@ -155,12 +156,21 @@ namespace Jellyfin.Server programDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "share"); } } + programDataPath = Path.Combine(programDataPath, "jellyfin"); - // Ensure the dir exists - Directory.CreateDirectory(programDataPath); } } + if (string.IsNullOrEmpty(programDataPath)) + { + Console.WriteLine("Cannot continue without path to program data folder (try -programdata)"); + Environment.Exit(1); + } + else + { + Directory.CreateDirectory(programDataPath); + } + string configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR"); if (string.IsNullOrEmpty(configDir)) { @@ -175,6 +185,11 @@ namespace Jellyfin.Server } } + if (string.IsNullOrEmpty(configDir)) + { + Directory.CreateDirectory(configDir); + } + string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR"); if (string.IsNullOrEmpty(logDir)) { @@ -189,6 +204,11 @@ namespace Jellyfin.Server } } + if (string.IsNullOrEmpty(logDir)) + { + Directory.CreateDirectory(logDir); + } + string appPath = AppContext.BaseDirectory; return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir, configDir); From 529d8044142415f1a8f0559c057bcf292e6bfc67 Mon Sep 17 00:00:00 2001 From: PloughPuff Date: Fri, 18 Jan 2019 17:19:47 +0000 Subject: [PATCH 2/3] Modify to use correct logic before creating directory Address review comments. --- Jellyfin.Server/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 4a09645d37..343ef0bc32 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -185,7 +185,7 @@ namespace Jellyfin.Server } } - if (string.IsNullOrEmpty(configDir)) + if (!string.IsNullOrEmpty(configDir)) { Directory.CreateDirectory(configDir); } @@ -204,7 +204,7 @@ namespace Jellyfin.Server } } - if (string.IsNullOrEmpty(logDir)) + if (!string.IsNullOrEmpty(logDir)) { Directory.CreateDirectory(logDir); } From 582226c13366a801648e94b421f6a7cb0fe0141b Mon Sep 17 00:00:00 2001 From: PloughPuff Date: Fri, 18 Jan 2019 18:11:42 +0000 Subject: [PATCH 3/3] Cause exception if empty string used for config or log folders --- Jellyfin.Server/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 343ef0bc32..46a80b4926 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -185,7 +185,7 @@ namespace Jellyfin.Server } } - if (!string.IsNullOrEmpty(configDir)) + if (configDir != null) { Directory.CreateDirectory(configDir); } @@ -204,7 +204,7 @@ namespace Jellyfin.Server } } - if (!string.IsNullOrEmpty(logDir)) + if (logDir != null) { Directory.CreateDirectory(logDir); }