Skip to content

Commit

Permalink
Cleanup: more unused classes and methods
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <stolee@gmail.com>
  • Loading branch information
derrickstolee committed Aug 13, 2019
1 parent 7d8aa61 commit 66f0582
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 176 deletions.
87 changes: 0 additions & 87 deletions Scalar.Common/DiskLayoutUpgrades/DiskLayoutUpgrade.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<string, string> 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)
Expand Down
77 changes: 0 additions & 77 deletions Scalar.Common/FileBasedCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Threading;

namespace Scalar.Common
Expand Down Expand Up @@ -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<IEnumerable<string>> getDataLines)
{
lock (this.fileLock)
Expand Down Expand Up @@ -165,52 +152,6 @@ protected string FormatRemoveLine(string line)
return RemoveEntryPrefix + line;
}

/// <param name="synchronizedAction">An optional callback to be run as soon as the fileLock is taken.</param>
protected void WriteAddEntry(string value, Action synchronizedAction = null)
{
lock (this.fileLock)
{
string line = this.FormatAddLine(value);
if (synchronizedAction != null)
{
synchronizedAction();
}

this.WriteToDisk(line);
}
}

/// <param name="synchronizedAction">An optional callback to be run as soon as the fileLock is taken.</param>
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<bool> condition)
{
if (!this.collectionAppendsDirectlyToFile)
{
throw new InvalidOperationException(nameof(this.DeleteDataFileIfCondition) + " requires that collectionAppendsDirectlyToFile be true");
}

lock (this.fileLock)
{
if (condition())
{
this.dataFileHandle.SetLength(0);
}
}
}

/// <param name="synchronizedAction">An optional callback to be run as soon as the fileLock is taken</param>
protected bool TryLoadFromDisk<TKey, TValue>(
TryParseAdd<TKey, TValue> tryParseAdd,
Expand Down Expand Up @@ -383,24 +324,6 @@ private void OpenOrCreateDataFile(bool retryUntilSuccess)
}
}

/// <summary>
/// Writes data as UTF8 to dataFileHandle. fileLock will be acquired.
/// </summary>
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();
}
}

/// <summary>
/// Reads entries from dataFileHandle, removing any data after the last NewLine ("\r\n"). Requires fileLock.
/// </summary>
Expand Down
13 changes: 1 addition & 12 deletions Scalar.Common/ScalarConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 66f0582

Please sign in to comment.