-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathFileSystem.cs
92 lines (76 loc) · 2.41 KB
/
FileSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.IO;
using GitReleaseManager.Core.Options;
namespace GitReleaseManager.Core.Helpers
{
public class FileSystem : IFileSystem
{
private readonly BaseSubOptions options;
public FileSystem(BaseSubOptions options)
{
this.options = options;
}
public void Copy(string @source, string destination, bool overwrite)
{
File.Copy(@source, destination, overwrite);
}
public void CreateDirectory(string path)
{
// It is safe to call CreateDirectory, if the directory
// already exists these are no-op.
if (string.IsNullOrEmpty(path))
{
Directory.CreateDirectory(Environment.CurrentDirectory);
}
else
{
Directory.CreateDirectory(path);
}
}
public void Move(string @source, string destination)
{
File.Move(@source, destination);
}
public bool Exists(string file)
{
return File.Exists(file);
}
public void Delete(string path)
{
File.Delete(path);
}
public string ResolvePath(string path)
{
if (Path.IsPathRooted(path))
{
return path;
}
return Path.Combine(options.TargetDirectory ?? Environment.CurrentDirectory, path);
}
public string ReadAllText(string path)
{
return File.ReadAllText(path);
}
public void WriteAllText(string file, string fileContents)
{
File.WriteAllText(file, fileContents);
}
public IEnumerable<string> DirectoryGetFiles(string directory, string searchPattern, SearchOption searchOption)
{
return Directory.GetFiles(directory, searchPattern, searchOption);
}
public Stream OpenRead(string path)
{
return File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
}
public Stream OpenWrite(string path)
{
return OpenWrite(path, overwrite: false);
}
public Stream OpenWrite(string path, bool overwrite)
{
return File.Open(path, overwrite ? FileMode.Create : FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
}
}
}