From b9beb6ec16ac849ece68e4abb337c328e2bc0eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Domeradzki?= Date: Wed, 10 Jul 2024 00:18:44 +0200 Subject: [PATCH] Fix ASF trying to create www folder if it doesn't exist yet It seems that ASP.NET is trying to create initialized WebRootPath if it doesn't exist yet. This might be unwanted, as user might want to explicitly disable www directory while still having interest in IPC. On top of that, ASF will outright crash if creating such directory will be impossible, e.g. because of insufficient permission. It makes sense for us to check first if the directory exists - if not, we can omit it entirely, so ASP.NET will default to NullFileProvider and simply respond 404 to everything unhandled from the code perspective. @SuperSandro2000 will resolve https://github.com/NixOS/nixpkgs/issues/312242 without a need of disabling IPC. In other words, you can use IPC with no www folder attached in order to still have ASF API and /swagger available. ASF will no longer crash in this scenario, it also won't try to create a directory on read-only filesystem. --- ArchiSteamFarm/IPC/ArchiKestrel.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ArchiSteamFarm/IPC/ArchiKestrel.cs b/ArchiSteamFarm/IPC/ArchiKestrel.cs index 8c6d06d07..a2c8c664f 100644 --- a/ArchiSteamFarm/IPC/ArchiKestrel.cs +++ b/ArchiSteamFarm/IPC/ArchiKestrel.cs @@ -435,15 +435,22 @@ internal static class ArchiKestrel { } private static async Task CreateWebApplication() { - string customDirectory = Path.Combine(Directory.GetCurrentDirectory(), SharedInfo.WebsiteDirectory); - string websiteDirectory = Directory.Exists(customDirectory) ? customDirectory : Path.Combine(AppContext.BaseDirectory, SharedInfo.WebsiteDirectory); + string? webRootPath = Path.Combine(Directory.GetCurrentDirectory(), SharedInfo.WebsiteDirectory); + + if (!Directory.Exists(webRootPath)) { + webRootPath = Path.Combine(AppContext.BaseDirectory, SharedInfo.WebsiteDirectory); + + if (!Directory.Exists(webRootPath)) { + webRootPath = null; + } + } // The order of dependency injection matters, pay attention to it WebApplicationBuilder builder = WebApplication.CreateEmptyBuilder( new WebApplicationOptions { ApplicationName = SharedInfo.AssemblyName, ContentRootPath = SharedInfo.HomeDirectory, - WebRootPath = websiteDirectory + WebRootPath = webRootPath } );