diff --git a/Scalar.Common/DiskLayoutUpgrades/DiskLayoutUpgrade.cs b/Scalar.Common/DiskLayoutUpgrades/DiskLayoutUpgrade.cs index b7b642ca57..ee53a97a28 100644 --- a/Scalar.Common/DiskLayoutUpgrades/DiskLayoutUpgrade.cs +++ b/Scalar.Common/DiskLayoutUpgrades/DiskLayoutUpgrade.cs @@ -1,6 +1,4 @@ using Scalar.Common; -using Scalar.Common.FileSystem; -using Scalar.Common.Git; using Scalar.Common.Tracing; using System; using System.Collections.Generic; @@ -118,91 +116,6 @@ public static bool TryCheckDiskLayoutVersion(ITracer tracer, string enlistmentRo public abstract bool TryUpgrade(ITracer tracer, string enlistmentRoot); - protected bool TryDeleteFolder(ITracer tracer, string folderName) - { - try - { - PhysicalFileSystem fileSystem = new PhysicalFileSystem(); - fileSystem.DeleteDirectory(folderName); - } - catch (Exception e) - { - tracer.RelatedError("Failed to delete folder {0}: {1}", folderName, e.ToString()); - return true; - } - - return true; - } - - protected bool TryDeleteFile(ITracer tracer, string fileName) - { - try - { - File.Delete(fileName); - } - catch (Exception e) - { - tracer.RelatedError("Failed to delete file {0}: {1}", fileName, e.ToString()); - return true; - } - - return true; - } - - protected bool TryRenameFolderForDelete(ITracer tracer, string folderName, out string backupFolder) - { - backupFolder = folderName + ".deleteme"; - - tracer.RelatedInfo("Moving " + folderName + " to " + backupFolder); - - try - { - Directory.Move(folderName, backupFolder); - } - catch (Exception e) - { - tracer.RelatedError("Failed to move {0} to {1}: {2}", folderName, backupFolder, e.ToString()); - return false; - } - - return true; - } - - protected bool TrySetGitConfig(ITracer tracer, string enlistmentRoot, Dictionary configSettings) - { - ScalarEnlistment enlistment; - - try - { - enlistment = ScalarEnlistment.CreateFromDirectory( - enlistmentRoot, - ScalarPlatform.Instance.GitInstallation.GetInstalledGitBinPath(), - authentication: null); - } - catch (InvalidRepoException e) - { - EventMetadata metadata = new EventMetadata(); - metadata.Add("Exception", e.ToString()); - metadata.Add(nameof(enlistmentRoot), enlistmentRoot); - tracer.RelatedError(metadata, $"{nameof(this.TrySetGitConfig)}: Failed to create ScalarEnlistment from directory"); - return false; - } - - GitProcess git = enlistment.CreateGitProcess(); - - foreach (string key in configSettings.Keys) - { - GitProcess.Result result = git.SetInLocalConfig(key, configSettings[key]); - if (result.ExitCodeIsFailure) - { - tracer.RelatedError("Could not set git config setting {0}. Error: {1}", key, result.Errors); - return false; - } - } - - return true; - } - private static void RegisterUpgrade(DiskLayoutUpgrade upgrade) { if (upgrade.IsMajorUpgrade) diff --git a/Scalar.Common/FileBasedCollection.cs b/Scalar.Common/FileBasedCollection.cs index ce6d16d30b..d6292648ce 100644 --- a/Scalar.Common/FileBasedCollection.cs +++ b/Scalar.Common/FileBasedCollection.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; -using System.Text; using System.Threading; namespace Scalar.Common @@ -60,18 +59,6 @@ public void Dispose() } } - public void ForceFlush() - { - if (this.dataFileHandle != null) - { - FileStream fs = this.dataFileHandle as FileStream; - if (fs != null) - { - fs.Flush(flushToDisk: true); - } - } - } - protected void WriteAndReplaceDataFile(Func> getDataLines) { lock (this.fileLock) @@ -165,52 +152,6 @@ protected string FormatRemoveLine(string line) return RemoveEntryPrefix + line; } - /// An optional callback to be run as soon as the fileLock is taken. - protected void WriteAddEntry(string value, Action synchronizedAction = null) - { - lock (this.fileLock) - { - string line = this.FormatAddLine(value); - if (synchronizedAction != null) - { - synchronizedAction(); - } - - this.WriteToDisk(line); - } - } - - /// An optional callback to be run as soon as the fileLock is taken. - protected void WriteRemoveEntry(string key, Action synchronizedAction = null) - { - lock (this.fileLock) - { - string line = this.FormatRemoveLine(key); - if (synchronizedAction != null) - { - synchronizedAction(); - } - - this.WriteToDisk(line); - } - } - - protected void DeleteDataFileIfCondition(Func condition) - { - if (!this.collectionAppendsDirectlyToFile) - { - throw new InvalidOperationException(nameof(this.DeleteDataFileIfCondition) + " requires that collectionAppendsDirectlyToFile be true"); - } - - lock (this.fileLock) - { - if (condition()) - { - this.dataFileHandle.SetLength(0); - } - } - } - /// An optional callback to be run as soon as the fileLock is taken protected bool TryLoadFromDisk( TryParseAdd tryParseAdd, @@ -383,24 +324,6 @@ private void OpenOrCreateDataFile(bool retryUntilSuccess) } } - /// - /// Writes data as UTF8 to dataFileHandle. fileLock will be acquired. - /// - private void WriteToDisk(string value) - { - if (!this.collectionAppendsDirectlyToFile) - { - throw new InvalidOperationException(nameof(this.WriteToDisk) + " requires that collectionAppendsDirectlyToFile be true"); - } - - byte[] bytes = Encoding.UTF8.GetBytes(value + NewLine); - lock (this.fileLock) - { - this.dataFileHandle.Write(bytes, 0, bytes.Length); - this.dataFileHandle.Flush(); - } - } - /// /// Reads entries from dataFileHandle, removing any data after the last NewLine ("\r\n"). Requires fileLock. /// diff --git a/Scalar.Common/ScalarConstants.cs b/Scalar.Common/ScalarConstants.cs index 55cbcdd299..248445b752 100644 --- a/Scalar.Common/ScalarConstants.cs +++ b/Scalar.Common/ScalarConstants.cs @@ -185,23 +185,12 @@ public static class Pack public static class Refs { public static readonly string Root = Path.Combine(DotGit.Root, "refs"); - - public static class Heads - { - public static readonly string Root = Path.Combine(DotGit.Refs.Root, "heads"); - public static readonly string RootFolder = Heads.Root + Path.DirectorySeparatorChar; - } } } - public static class InstallationCapabilityFiles - { - public const string OnDiskVersion16CapableInstallation = "OnDiskVersion16CapableInstallation.dat"; - } - public static class VerbParameters { - public const string InternalUseOnly = "internal_use_only"; + public const string InternalUseOnly = "internal_use_only"; public static class Mount {