diff --git a/CHANGELOG.md b/CHANGELOG.md index f28dea05..3098b871 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v2.0.0-beta.29 - 2024-03-18 +- Fixed wrong `users` folder location. + ## v2.0.0-beta.28 - 2024-03-16 - Fixed a bug where applications could not access the `/api/v1/jobs` endpoint using the new personal access tokens. diff --git a/src/Nexus/Core/NexusOptions.cs b/src/Nexus/Core/NexusOptions.cs index 85d9ac21..15ab9ea6 100644 --- a/src/Nexus/Core/NexusOptions.cs +++ b/src/Nexus/Core/NexusOptions.cs @@ -66,7 +66,6 @@ internal record PathsOptions() : NexusOptionsBase public string Cache { get; set; } = Path.Combine(PlatformSpecificRoot, "cache"); public string Catalogs { get; set; } = Path.Combine(PlatformSpecificRoot, "catalogs"); public string Artifacts { get; set; } = Path.Combine(PlatformSpecificRoot, "artifacts"); - public string Users { get; set; } = Path.Combine(PlatformSpecificRoot, "users"); public string Packages { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nexus", "packages"); // GetGlobalPackagesFolder: https://github.com/NuGet/NuGet.Client/blob/0fc58e13683565e7bdf30e706d49e58fc497bbed/src/NuGet.Core/NuGet.Configuration/Utility/SettingsUtility.cs#L225-L254 // GetFolderPath: https://github.com/NuGet/NuGet.Client/blob/1d75910076b2ecfbe5f142227cfb4fb45c093a1e/src/NuGet.Core/NuGet.Common/PathUtil/NuGetEnvironment.cs#L54-L57 diff --git a/src/Nexus/Services/DatabaseService.cs b/src/Nexus/Services/DatabaseService.cs index e18ab825..f75d65f7 100644 --- a/src/Nexus/Services/DatabaseService.cs +++ b/src/Nexus/Services/DatabaseService.cs @@ -15,6 +15,14 @@ internal interface IDatabaseService bool TryReadProject([NotNullWhen(true)] out string? project); Stream WriteProject(); + /* /config/users */ + bool TryReadTokenMap( + string userId, + [NotNullWhen(true)] out string? tokenMap); + + Stream WriteTokenMap( + string userId); + /* /catalogs/catalog_id/... */ bool AttachmentExists(string catalogId, string attachmentId); IEnumerable EnumerateAttachments(string catalogId); @@ -31,14 +39,6 @@ internal interface IDatabaseService bool TryReadCacheEntry(CatalogItem catalogItem, DateTime begin, [NotNullWhen(true)] out Stream? cacheEntry); bool TryWriteCacheEntry(CatalogItem catalogItem, DateTime begin, [NotNullWhen(true)] out Stream? cacheEntry); Task ClearCacheEntriesAsync(string catalogId, DateOnly day, TimeSpan timeout, Predicate predicate); - - /* /users */ - bool TryReadTokenMap( - string userId, - [NotNullWhen(true)] out string? tokenMap); - - Stream WriteTokenMap( - string userId); } internal class DatabaseService(IOptions pathsOptions) @@ -114,6 +114,36 @@ public Stream WriteProject() return File.Open(filePath, FileMode.Create, FileAccess.Write); } + /* /config/users */ + public bool TryReadTokenMap( + string userId, + [NotNullWhen(true)] out string? tokenMap) + { + var folderPath = SafePathCombine(Path.Combine(_pathsOptions.Config, "users"), userId); + var tokenFilePath = Path.Combine(folderPath, "tokens.json"); + + tokenMap = default; + + if (File.Exists(tokenFilePath)) + { + tokenMap = File.ReadAllText(tokenFilePath); + return true; + } + + return false; + } + + public Stream WriteTokenMap( + string userId) + { + var folderPath = SafePathCombine(Path.Combine(_pathsOptions.Config, "users"), userId); + var tokenFilePath = Path.Combine(folderPath, "tokens.json"); + + Directory.CreateDirectory(folderPath); + + return File.Open(tokenFilePath, FileMode.Create, FileAccess.Write); + } + /* /catalogs/catalog_id/... */ public bool AttachmentExists(string catalogId, string attachmentId) @@ -332,36 +362,6 @@ private static async Task DeleteCacheEntryAsync(string cacheEntry, TimeSpan time throw new Exception($"Cannot delete cache entry {cacheEntry}."); } - /* /users */ - public bool TryReadTokenMap( - string userId, - [NotNullWhen(true)] out string? tokenMap) - { - var folderPath = SafePathCombine(_pathsOptions.Users, userId); - var tokenFilePath = Path.Combine(folderPath, "tokens.json"); - - tokenMap = default; - - if (File.Exists(tokenFilePath)) - { - tokenMap = File.ReadAllText(tokenFilePath); - return true; - } - - return false; - } - - public Stream WriteTokenMap( - string userId) - { - var folderPath = SafePathCombine(_pathsOptions.Users, userId); - var tokenFilePath = Path.Combine(folderPath, "tokens.json"); - - Directory.CreateDirectory(folderPath); - - return File.Open(tokenFilePath, FileMode.Create, FileAccess.Write); - } - // private static string SafePathCombine(string basePath, string relativePath) { diff --git a/version.json b/version.json index bad48eba..2a34d2d0 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { "version": "2.0.0", - "suffix": "beta.28" + "suffix": "beta.29" } \ No newline at end of file