Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Added checkout directory parameter to repo command (#922)
Browse files Browse the repository at this point in the history
* Added checkout directory parameter to repo command.

* Fixed failing test. Added test for custom checkout directory.

Co-authored-by: Tim Vinkemeier <tim.vinkemeier@prodot.de>
  • Loading branch information
TimVinkemeier and Tim Vinkemeier committed May 14, 2020
1 parent b5e4b49 commit c12624e
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 220 deletions.
44 changes: 25 additions & 19 deletions NuKeeper.Inspection/Files/FolderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,22 @@
using System.Globalization;
using System.IO;
using System.Linq;

using NuKeeper.Abstractions.Inspections.Files;
using NuKeeper.Abstractions.Logging;

namespace NuKeeper.Inspection.Files
{
public class FolderFactory : IFolderFactory
{
private readonly INuKeeperLogger _logger;
private const string FolderPrefix = "repo-";
private readonly INuKeeperLogger _logger;

public FolderFactory(INuKeeperLogger logger)
{
_logger = logger;
}

public IFolder UniqueTemporaryFolder()
{
var tempDir = new DirectoryInfo(GetUniqueTemporaryPath());
tempDir.Create();
return new Folder(_logger, tempDir);
}

public static string NuKeeperTempFilesPath()
{
return Path.Combine(Path.GetTempPath(), "NuKeeper");
}

private static string GetUniqueTemporaryPath()
{
var uniqueName = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
return Path.Combine(NuKeeperTempFilesPath(), $"{FolderPrefix}{uniqueName}");
}

/// <summary>
/// Select folders to cleanup at startup
/// </summary>
Expand All @@ -50,6 +33,11 @@ public static IEnumerable<DirectoryInfo> GetTempDirsToCleanup(DirectoryInfo nuke
d.LastWriteTime < filterDatetime);
}

public static string NuKeeperTempFilesPath()
{
return Path.Combine(Path.GetTempPath(), "NuKeeper");
}

/// <summary>
/// Cleanup folders that are not automatically have been cleaned.
/// </summary>
Expand All @@ -62,5 +50,23 @@ public void DeleteExistingTempDirs()
folder.TryDelete();
}
}

public IFolder FolderFromPath(string folderPath)
{
return new Folder(_logger, new DirectoryInfo(folderPath));
}

public IFolder UniqueTemporaryFolder()
{
var tempDir = new DirectoryInfo(GetUniqueTemporaryPath());
tempDir.Create();
return new Folder(_logger, tempDir);
}

private static string GetUniqueTemporaryPath()
{
var uniqueName = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
return Path.Combine(NuKeeperTempFilesPath(), $"{FolderPrefix}{uniqueName}");
}
}
}
3 changes: 3 additions & 0 deletions NuKeeper.Inspection/Files/IFolderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace NuKeeper.Inspection.Files
public interface IFolderFactory
{
void DeleteExistingTempDirs();

IFolder FolderFromPath(string folderPath);

IFolder UniqueTemporaryFolder();
}
}
Loading

0 comments on commit c12624e

Please sign in to comment.