-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFileSystemStrategy.cs
More file actions
61 lines (56 loc) · 2.23 KB
/
FileSystemStrategy.cs
File metadata and controls
61 lines (56 loc) · 2.23 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
namespace LessIO.Strategies
{
/// <summary>
/// See <see cref="FileSystem"/> for documentation of each method of this class.
/// </summary>
internal abstract class FileSystemStrategy
{
public abstract void SetLastWriteTime(Path path, DateTime lastWriteTime);
public abstract void SetAttributes(Path path, FileAttributes fileAttributes);
public abstract FileAttributes GetAttributes(Path path);
public abstract bool Exists(Path path);
public abstract void CreateDirectory(Path path);
public abstract void Copy(Path source, Path dest);
public abstract void RemoveDirectory(Path path, bool recursively);
public abstract void RemoveFile(Path path, bool force);
public abstract System.IO.Stream CreateFile(Path path);
public abstract IEnumerable<Path> ListContents(Path directory);
public virtual IEnumerable<Path> ListContents(Path directory, bool recursive)
{
IEnumerable<Path> children = ListContents(directory);
if (recursive)
{
IEnumerable<Path> grandChildren = children.SelectMany(
p => ListContents(p, recursive)
);
return Enumerable.Concat(children, grandChildren);
}
else
{
return children;
}
}
public virtual bool IsDirectory(Path path)
{
FileAttributes attributes = GetAttributes(path);
return (attributes & FileAttributes.Directory) == FileAttributes.Directory;
}
public virtual bool IsReadOnly(Path path)
{
FileAttributes attributes = GetAttributes(path);
return (attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly;
}
public virtual void SetReadOnly(Path path, bool readOnly)
{
FileAttributes attributes = GetAttributes(path);
if (readOnly)
attributes = attributes | FileAttributes.ReadOnly;
else
attributes = attributes & ~FileAttributes.ReadOnly;
SetAttributes(path, attributes);
}
}
}