Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit c247d74

Browse files
#21 Moved IFileSystem from GitVersion to GitTools.Core
1 parent 9b7da06 commit c247d74

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

src/GitTools.Core/GitTools.Core.Shared/GitTools.Core.Shared.projitems

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<Compile Include="$(MSBuildThisFileDirectory)Git\GitRepository.cs" />
1919
<Compile Include="$(MSBuildThisFileDirectory)Git\RepositoryLoader.cs" />
2020
<Compile Include="$(MSBuildThisFileDirectory)Git\TaggedCommit.cs" />
21+
<Compile Include="$(MSBuildThisFileDirectory)IO\FileSystem.cs" />
22+
<Compile Include="$(MSBuildThisFileDirectory)IO\Helpers\DeleteHelper.cs" />
23+
<Compile Include="$(MSBuildThisFileDirectory)IO\Interfaces\IFileSystem.cs" />
2124
<Compile Include="$(MSBuildThisFileDirectory)IO\TemporaryFilesContext.cs" />
2225
<Compile Include="$(MSBuildThisFileDirectory)Logging\Extensions\LogExtensions.cs" />
2326
</ItemGroup>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace GitVersion.IO
2+
{
3+
using System.Collections.Generic;
4+
using System.IO;
5+
6+
public class FileSystem : IFileSystem
7+
{
8+
public void Copy(string @from, string to, bool overwrite)
9+
{
10+
File.Copy(from, to, overwrite);
11+
}
12+
13+
public void Move(string @from, string to)
14+
{
15+
File.Move(from, to);
16+
}
17+
18+
public bool Exists(string file)
19+
{
20+
return File.Exists(file);
21+
}
22+
23+
public void Delete(string path)
24+
{
25+
File.Delete(path);
26+
}
27+
28+
public string ReadAllText(string path)
29+
{
30+
return File.ReadAllText(path);
31+
}
32+
33+
public void WriteAllText(string file, string fileContents)
34+
{
35+
File.WriteAllText(file, fileContents);
36+
}
37+
38+
public IEnumerable<string> DirectoryGetFiles(string directory, string searchPattern, SearchOption searchOption)
39+
{
40+
return Directory.GetFiles(directory, searchPattern, searchOption);
41+
}
42+
43+
public Stream OpenWrite(string path)
44+
{
45+
return File.OpenWrite(path);
46+
}
47+
}
48+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace GitVersion.IO
2+
{
3+
using System.IO;
4+
5+
public static class DeleteHelper
6+
{
7+
public static void DeleteGitRepository(string directory)
8+
{
9+
if (string.IsNullOrEmpty(directory))
10+
{
11+
return;
12+
}
13+
14+
foreach (var fileName in Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories))
15+
{
16+
var fileInfo = new FileInfo(fileName)
17+
{
18+
IsReadOnly = false
19+
};
20+
21+
fileInfo.Delete();
22+
}
23+
24+
Directory.Delete(directory, true);
25+
}
26+
}
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace GitVersion.IO
2+
{
3+
using System.Collections.Generic;
4+
using System.IO;
5+
6+
public interface IFileSystem
7+
{
8+
void Copy(string from, string to, bool overwrite);
9+
void Move(string from, string to);
10+
bool Exists(string file);
11+
void Delete(string path);
12+
string ReadAllText(string path);
13+
void WriteAllText(string file, string fileContents);
14+
IEnumerable<string> DirectoryGetFiles(string directory, string searchPattern, SearchOption searchOption);
15+
Stream OpenWrite(string path);
16+
}
17+
}

0 commit comments

Comments
 (0)