diff --git a/Scalar.Common/RepoRegistry/IScalarRepoRegistry.cs b/Scalar.Common/RepoRegistry/IScalarRepoRegistry.cs index 7ee688fab3..0a12a851a9 100644 --- a/Scalar.Common/RepoRegistry/IScalarRepoRegistry.cs +++ b/Scalar.Common/RepoRegistry/IScalarRepoRegistry.cs @@ -4,8 +4,8 @@ namespace Scalar.Common.RepoRegistry { public interface IScalarRepoRegistry { - bool TryRegisterRepo(string repoRoot, string ownerSID, out string errorMessage); - bool TryRemoveRepo(string repoRoot, out string errorMessage); + bool TryRegisterRepo(string normalizedRepoRoot, string userId, out string errorMessage); + bool TryRemoveRepo(string normalizedRepoRoot, out string errorMessage); IEnumerable GetRegisteredRepos(); } } diff --git a/Scalar.Common/RepoRegistry/IScalarRepoRegistryExtensions.cs b/Scalar.Common/RepoRegistry/IScalarRepoRegistryExtensions.cs index 6fa95d452a..dd82390c76 100644 --- a/Scalar.Common/RepoRegistry/IScalarRepoRegistryExtensions.cs +++ b/Scalar.Common/RepoRegistry/IScalarRepoRegistryExtensions.cs @@ -6,9 +6,9 @@ namespace Scalar.Common.RepoRegistry { public static class IScalarRepoRegistryExtensions { - public static IEnumerable GetRegisteredReposForUser(this IScalarRepoRegistry registry, string ownerSID) + public static IEnumerable GetRegisteredReposForUser(this IScalarRepoRegistry registry, string userId) { - return registry.GetRegisteredRepos().Where(x => x.OwnerSID.Equals(ownerSID, StringComparison.CurrentCultureIgnoreCase)); + return registry.GetRegisteredRepos().Where(x => x.UserId.Equals(userId, StringComparison.CurrentCultureIgnoreCase)); } } } diff --git a/Scalar.Common/RepoRegistry/ScalarRepoRegistration.cs b/Scalar.Common/RepoRegistry/ScalarRepoRegistration.cs index 2d329d3a22..123e468a3d 100644 --- a/Scalar.Common/RepoRegistry/ScalarRepoRegistration.cs +++ b/Scalar.Common/RepoRegistry/ScalarRepoRegistration.cs @@ -8,14 +8,14 @@ public ScalarRepoRegistration() { } - public ScalarRepoRegistration(string enlistmentRoot, string ownerSID) + public ScalarRepoRegistration(string normalizedRepoRoot, string userId) { - this.EnlistmentRoot = enlistmentRoot; - this.OwnerSID = ownerSID; + this.NormalizedRepoRoot = normalizedRepoRoot; + this.UserId = userId; } - public string EnlistmentRoot { get; set; } - public string OwnerSID { get; set; } + public string NormalizedRepoRoot { get; set; } + public string UserId { get; set; } public static ScalarRepoRegistration FromJson(string json) { @@ -29,7 +29,7 @@ public static ScalarRepoRegistration FromJson(string json) public override string ToString() { - return $"({this.OwnerSID}) {this.EnlistmentRoot}"; + return $"({this.UserId}) {this.NormalizedRepoRoot}"; } public string ToJson() diff --git a/Scalar.Common/RepoRegistry/ScalarRepoRegistry.cs b/Scalar.Common/RepoRegistry/ScalarRepoRegistry.cs index a4814c4501..f2153b4997 100644 --- a/Scalar.Common/RepoRegistry/ScalarRepoRegistry.cs +++ b/Scalar.Common/RepoRegistry/ScalarRepoRegistry.cs @@ -27,7 +27,7 @@ public ScalarRepoRegistry( this.registryFolderPath = repoRegistryLocation; } - public bool TryRegisterRepo(string repoRoot, string ownerSID, out string errorMessage) + public bool TryRegisterRepo(string normalizedRepoRoot, string userId, out string errorMessage) { try { @@ -49,17 +49,17 @@ public bool TryRegisterRepo(string repoRoot, string ownerSID, out string errorMe errorMessage = $"Error while ensuring registry directory '{this.registryFolderPath}' exists: {e.Message}"; EventMetadata metadata = CreateEventMetadata(e); - metadata.Add(nameof(repoRoot), repoRoot); + metadata.Add(nameof(normalizedRepoRoot), normalizedRepoRoot); metadata.Add(nameof(this.registryFolderPath), this.registryFolderPath); this.tracer.RelatedError(metadata, $"{nameof(this.TryRegisterRepo)}: Exception while ensuring registry directory exists"); return false; } - string tempRegistryPath = this.GetRepoRegistryTempFilePath(repoRoot); + string tempRegistryPath = this.GetRepoRegistryTempFilePath(normalizedRepoRoot); try { - ScalarRepoRegistration repoRegistration = new ScalarRepoRegistration(repoRoot, ownerSID); + ScalarRepoRegistration repoRegistration = new ScalarRepoRegistration(normalizedRepoRoot, userId); string registryFileContents = repoRegistration.ToJson(); using (Stream tempFile = this.fileSystem.OpenFileStream( @@ -76,26 +76,26 @@ public bool TryRegisterRepo(string repoRoot, string ownerSID, out string errorMe } catch (Exception e) { - errorMessage = $"Error while registering repo {repoRoot}: {e.Message}"; + errorMessage = $"Error while registering repo {normalizedRepoRoot}: {e.Message}"; EventMetadata metadata = CreateEventMetadata(e); - metadata.Add(nameof(repoRoot), repoRoot); + metadata.Add(nameof(normalizedRepoRoot), normalizedRepoRoot); metadata.Add(nameof(tempRegistryPath), tempRegistryPath); this.tracer.RelatedError(metadata, $"{nameof(this.TryRegisterRepo)}: Exception while writing temp registry file"); return false; } - string registryFilePath = this.GetRepoRegistryFilePath(repoRoot); + string registryFilePath = this.GetRepoRegistryFilePath(normalizedRepoRoot); try { this.fileSystem.MoveAndOverwriteFile(tempRegistryPath, registryFilePath); } catch (Win32Exception e) { - errorMessage = $"Error while registering repo {repoRoot}: {e.Message}"; + errorMessage = $"Error while registering repo {normalizedRepoRoot}: {e.Message}"; EventMetadata metadata = CreateEventMetadata(e); - metadata.Add(nameof(repoRoot), repoRoot); + metadata.Add(nameof(normalizedRepoRoot), normalizedRepoRoot); metadata.Add(nameof(tempRegistryPath), tempRegistryPath); metadata.Add(nameof(registryFilePath), registryFilePath); this.tracer.RelatedError(metadata, $"{nameof(this.TryRegisterRepo)}: Exception while renaming temp registry file"); @@ -106,15 +106,15 @@ public bool TryRegisterRepo(string repoRoot, string ownerSID, out string errorMe return true; } - public bool TryRemoveRepo(string repoRoot, out string errorMessage) + public bool TryRemoveRepo(string normalizedRepoRoot, out string errorMessage) { - string registryPath = this.GetRepoRegistryFilePath(repoRoot); + string registryPath = this.GetRepoRegistryFilePath(normalizedRepoRoot); if (!this.fileSystem.FileExists(registryPath)) { - errorMessage = $"Attempted to remove non-existent repo '{repoRoot}'"; + errorMessage = $"Attempted to remove non-existent repo '{normalizedRepoRoot}'"; EventMetadata metadata = CreateEventMetadata(); - metadata.Add(nameof(repoRoot), repoRoot); + metadata.Add(nameof(normalizedRepoRoot), normalizedRepoRoot); metadata.Add(nameof(registryPath), registryPath); this.tracer.RelatedWarning( metadata, @@ -129,10 +129,10 @@ public bool TryRemoveRepo(string repoRoot, out string errorMessage) } catch (Exception e) { - errorMessage = $"Error while removing repo {repoRoot}: {e.Message}"; + errorMessage = $"Error while removing repo {normalizedRepoRoot}: {e.Message}"; EventMetadata metadata = CreateEventMetadata(e); - metadata.Add(nameof(repoRoot), repoRoot); + metadata.Add(nameof(normalizedRepoRoot), normalizedRepoRoot); metadata.Add(nameof(registryPath), registryPath); this.tracer.RelatedWarning( metadata, @@ -175,20 +175,20 @@ public IEnumerable GetRegisteredRepos() } } - internal static string GetRepoRootSha(string repoRoot) + internal static string GetRepoRootSha(string normalizedRepoRoot) { - return SHA1Util.SHA1HashStringForUTF8String(repoRoot.ToLowerInvariant()); + return SHA1Util.SHA1HashStringForUTF8String(normalizedRepoRoot.ToLowerInvariant()); } - internal string GetRepoRegistryTempFilePath(string repoRoot) + internal string GetRepoRegistryTempFilePath(string normalizedRepoRoot) { - string repoTempFilename = $"{GetRepoRootSha(repoRoot)}{RegistryTempFileExtension}"; + string repoTempFilename = $"{GetRepoRootSha(normalizedRepoRoot)}{RegistryTempFileExtension}"; return Path.Combine(this.registryFolderPath, repoTempFilename); } - internal string GetRepoRegistryFilePath(string repoRoot) + internal string GetRepoRegistryFilePath(string normalizedRepoRoot) { - string repoFilename = $"{GetRepoRootSha(repoRoot)}{RegistryFileExtension}"; + string repoFilename = $"{GetRepoRootSha(normalizedRepoRoot)}{RegistryFileExtension}"; return Path.Combine(this.registryFolderPath, repoFilename); } diff --git a/Scalar.Platform.POSIX/POSIXFileSystem.Shared.cs b/Scalar.Platform.POSIX/POSIXFileSystem.Shared.cs index f6eb6c75dd..c8ff350073 100644 --- a/Scalar.Platform.POSIX/POSIXFileSystem.Shared.cs +++ b/Scalar.Platform.POSIX/POSIXFileSystem.Shared.cs @@ -4,7 +4,7 @@ public partial class POSIXFileSystem { public static bool TryGetNormalizedPathImplementation(string path, out string normalizedPath, out string errorMessage) { - // TODO(#1358): Properly determine normalized paths (e.g. across links) + // TODO(#217): Properly determine normalized paths (e.g. across links) errorMessage = null; normalizedPath = path; return true; diff --git a/Scalar.Service/MaintenanceTaskScheduler.cs b/Scalar.Service/MaintenanceTaskScheduler.cs index 6385ec69be..11be8033d9 100644 --- a/Scalar.Service/MaintenanceTaskScheduler.cs +++ b/Scalar.Service/MaintenanceTaskScheduler.cs @@ -212,9 +212,9 @@ public void RunMaintenanceTaskForRepos( { ++reposForUserCount; - rootPath = Path.GetPathRoot(repoRegistration.EnlistmentRoot); + rootPath = Path.GetPathRoot(repoRegistration.NormalizedRepoRoot); - metadata[nameof(repoRegistration.EnlistmentRoot)] = repoRegistration.EnlistmentRoot; + metadata[nameof(repoRegistration.NormalizedRepoRoot)] = repoRegistration.NormalizedRepoRoot; metadata[nameof(task)] = task; metadata[nameof(rootPath)] = rootPath; metadata.Remove(nameof(errorMessage)); @@ -231,11 +231,11 @@ public void RunMaintenanceTaskForRepos( continue; } - if (!this.fileSystem.DirectoryExists(repoRegistration.EnlistmentRoot)) + if (!this.fileSystem.DirectoryExists(repoRegistration.NormalizedRepoRoot)) { // The repo is no longer on disk (but its volume is present) // Unregister the repo - if (repoRegistry.TryRemoveRepo(repoRegistration.EnlistmentRoot, out errorMessage)) + if (repoRegistry.TryRemoveRepo(repoRegistration.NormalizedRepoRoot, out errorMessage)) { this.tracer.RelatedEvent( EventLevel.Informational, @@ -259,12 +259,12 @@ public void RunMaintenanceTaskForRepos( $"{nameof(this.RunMaintenanceTaskForRepos)}_CallingMaintenance", metadata); - this.scalarVerb.CallMaintenance(task, repoRegistration.EnlistmentRoot, sessionId); + this.scalarVerb.CallMaintenance(task, repoRegistration.NormalizedRepoRoot, sessionId); } if (reposForUserCount == 0) { - metadata.Add(TracingConstants.MessageKey.InfoMessage, "No active repos for user"); + metadata.Add(TracingConstants.MessageKey.InfoMessage, "No registered repos for user"); this.tracer.RelatedEvent( EventLevel.Informational, $"{nameof(this.RunMaintenanceTaskForRepos)}_NoRepos", diff --git a/Scalar.UnitTests/Common/RepoRegistry/ScalarRepoRegistryTests.cs b/Scalar.UnitTests/Common/RepoRegistry/ScalarRepoRegistryTests.cs index 61ea224be8..4d8a760d3b 100644 --- a/Scalar.UnitTests/Common/RepoRegistry/ScalarRepoRegistryTests.cs +++ b/Scalar.UnitTests/Common/RepoRegistry/ScalarRepoRegistryTests.cs @@ -45,10 +45,10 @@ public void TearDown() //// this.VerifyRepo(verifiableRegistry[repoRoot], ownerSID); ////} - private void VerifyRepo(ScalarRepoRegistration repo, string expectedOwnerSID) + private void VerifyRepo(ScalarRepoRegistration repo, string expectedUserId) { repo.ShouldNotBeNull(); - repo.OwnerSID.ShouldEqual(expectedOwnerSID); + repo.UserId.ShouldEqual(expectedUserId); } } } diff --git a/Scalar/CommandLine/ServiceVerb.cs b/Scalar/CommandLine/ServiceVerb.cs index b08f56bc17..06178d6823 100644 --- a/Scalar/CommandLine/ServiceVerb.cs +++ b/Scalar/CommandLine/ServiceVerb.cs @@ -53,7 +53,7 @@ private IEnumerable GetRepoList() new PhysicalFileSystem(), repoRegistryLocation); - return repoRegistry.GetRegisteredRepos().Select(x => x.EnlistmentRoot); + return repoRegistry.GetRegisteredRepos().Select(x => x.NormalizedRepoRoot); } } }