Skip to content

Commit 5971306

Browse files
committed
Prefer GetRandomFileName() over NewGuid() for paths
1 parent 27fbde6 commit 5971306

File tree

7 files changed

+9
-11
lines changed

7 files changed

+9
-11
lines changed

LibGit2Sharp.Tests/ArchiveTarFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void CanArchiveACommitWithDirectoryAsTar()
2626
var commit = repo.Lookup<Commit>("4c062a6361ae6959e06292c1fa5e2822d9c96345");
2727

2828
var scd = BuildSelfCleaningDirectory();
29-
var archivePath = Path.Combine(scd.RootedDirectoryPath, Guid.NewGuid() + ".tar");
29+
var archivePath = Path.Combine(scd.RootedDirectoryPath, Path.GetRandomFileName() + ".tar");
3030
Directory.CreateDirectory(scd.RootedDirectoryPath);
3131

3232
repo.ObjectDatabase.Archive(commit, archivePath);

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void CanCloneALocalRepositoryFromAStandardPath()
9292
[Fact]
9393
public void CanCloneALocalRepositoryFromANewlyCreatedTemporaryPath()
9494
{
95-
var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString().Substring(0, 8));
95+
var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
9696
SelfCleaningDirectory scd = BuildSelfCleaningDirectory(path);
9797
Repository.Init(scd.DirectoryPath);
9898
AssertLocalClone(scd.DirectoryPath, isCloningAnEmptyRepository: true);

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ public void CanAmendACommitWithMoreThanOneParent()
831831

832832
private static void CreateAndStageANewFile(IRepository repo)
833833
{
834-
string relativeFilepath = string.Format("new-file-{0}.txt", Guid.NewGuid());
834+
string relativeFilepath = string.Format("new-file-{0}.txt", Path.GetRandomFileName());
835835
Touch(repo.Info.WorkingDirectory, relativeFilepath, "brand new content\n");
836836
repo.Stage(relativeFilepath);
837837
}

LibGit2Sharp.Tests/PushFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Linq;
34
using LibGit2Sharp.Tests.TestHelpers;
45
using Xunit;
@@ -159,7 +160,7 @@ private void UpdateTheRemoteRepositoryWithANewCommit(string remoteRepoPath)
159160
private Commit AddCommitToRepo(IRepository repository)
160161
{
161162

162-
string random = Guid.NewGuid().ToString();
163+
string random = Path.GetRandomFileName();
163164
string filename = random + ".txt";
164165

165166
Touch(repository.Info.WorkingDirectory, filename, random);

LibGit2Sharp.Tests/RepositoryFixture.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,11 @@ public void CanDiscoverAStandardRepoGivenTheWorkingDirPath()
543543
[Fact]
544544
public void DiscoverReturnsNullWhenNoRepoCanBeFound()
545545
{
546-
string path = Path.GetTempFileName();
547-
string suffix = "." + Guid.NewGuid().ToString().Substring(0, 7);
546+
string path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
548547

549-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory(path + suffix);
548+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory(path);
550549
Directory.CreateDirectory(scd.RootedDirectoryPath);
551550
Assert.Null(Repository.Discover(scd.RootedDirectoryPath));
552-
553-
File.Delete(path);
554551
}
555552

556553
[Fact]

LibGit2Sharp.Tests/ShadowCopyFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()
1717
Assembly assembly = type.Assembly;
1818

1919
// Build a new domain which will shadow copy assemblies
20-
string cachePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
20+
string cachePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
2121
Directory.CreateDirectory(cachePath);
2222

2323
var setup = new AppDomainSetup

LibGit2Sharp.Tests/TestHelpers/SelfCleaningDirectory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public SelfCleaningDirectory(IPostTestDirectoryRemover directoryRemover, string
2828

2929
protected static string BuildTempPath()
3030
{
31-
return Path.Combine(Constants.TemporaryReposPath, Guid.NewGuid().ToString().Substring(0, 8));
31+
return Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
3232
}
3333
}
3434
}

0 commit comments

Comments
 (0)