Skip to content

Commit

Permalink
Reduce length of temp directory path
Browse files Browse the repository at this point in the history
  • Loading branch information
FrediKats authored Apr 27, 2024
1 parent ea795f8 commit e51f774
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PropertyGroup>
<RepositoryUrl>https://github.com/kysect/Kysect.CommonLib</RepositoryUrl>
<PackageProjectUrl>https://github.com/kysect/Kysect.CommonLib</PackageProjectUrl>
<Version>0.1.20</Version>
<Version>0.1.21</Version>
</PropertyGroup>

<!-- Code configuration -->
Expand Down
9 changes: 7 additions & 2 deletions Sources/Kysect.CommonLib.Testing/TestTemporaryDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public TestTemporaryDirectory(System.IO.Abstractions.FileSystem fileSystem, stri
_fileSystem = fileSystem.ThrowIfNull();
rootPath.ThrowIfNull();

string path = _fileSystem.Path.Combine(rootPath, "TempDirectory", Guid.NewGuid().ToString());
string path = _fileSystem.Path.Combine(rootPath, "Temp", GetRandomDirectoryName());

if (_fileSystem.Directory.Exists(path))
{
Expand All @@ -28,7 +28,7 @@ public TestTemporaryDirectory(System.IO.Abstractions.FileSystem fileSystem, stri

public string GetTemporaryDirectory()
{
return _fileSystem.Path.Combine(_directoryInfo.FullName, Guid.NewGuid().ToString());
return _fileSystem.Path.Combine(_directoryInfo.FullName, GetRandomDirectoryName());
}

public void Dispose()
Expand Down Expand Up @@ -64,4 +64,9 @@ public static void DeleteRecursive(IDirectoryInfo target)

target.Delete();
}

private string GetRandomDirectoryName()
{
return Guid.NewGuid().ToString().Substring(0, 8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<ItemGroup>
<ProjectReference Include="..\Kysect.CommonLib.DependencyInjection\Kysect.CommonLib.DependencyInjection.csproj" />
<ProjectReference Include="..\Kysect.CommonLib.Testing\Kysect.CommonLib.Testing.csproj" />
<ProjectReference Include="..\Kysect.CommonLib\Kysect.CommonLib.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using FluentAssertions;
using Kysect.CommonLib.Testing;

namespace Kysect.CommonLib.Tests.Testing;

public class TestTemporaryDirectoryTests
{
/// <summary>
/// We use this method during testing of git clone and get VERY LONG path. GitHub may fail with
/// LibGit2Sharp.LibGit2SharpException : path too long: 'D:/a/GithubUtils/GithubUtils/Sources/artifacts/bin/Kysect.GithubUtils.Tests/release/TempDirectory/0d339f96-3146-42ff-84ee-d2534af2c84b/80ec70c9-6afa-413b-b3af-ac6ecc10aa8f/Sources/Kysect.GithubUtils/Contributions/ActivityProviders/GithubActivityProviderExtensions.cs
/// </summary>
[Fact]
public void GetTemporaryDirectory_ReturnStringDoNotLong()
{
var fileSystem = new System.IO.Abstractions.FileSystem();
string baseDirectoryPath = fileSystem.Path.GetFullPath(".");
using var temporaryDirectory = new TestTemporaryDirectory(fileSystem);

string directoryPath = temporaryDirectory.GetTemporaryDirectory();
int additionalLength = directoryPath.Length - baseDirectoryPath.Length;

additionalLength.Should().BeLessThan(25);
}
}

0 comments on commit e51f774

Please sign in to comment.