Skip to content

Commit becdfd7

Browse files
committed
Simplified file interfaces. Directories and Files are now both represented
as IFileInfo.
1 parent 5d0e45c commit becdfd7

File tree

17 files changed

+134
-139
lines changed

17 files changed

+134
-139
lines changed

src/Microsoft.IIS.Administration.Files.Core/DirectoryInfo.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace Microsoft.IIS.Administration.Files
77
using System;
88
using System.IO;
99

10-
class DirectoryInfo : IDirectoryInfo
10+
class DirectoryInfo : IFileInfo
1111
{
1212
private System.IO.DirectoryInfo _info;
13-
private IDirectoryInfo _parent;
13+
private IFileInfo _parent;
1414

1515
public DirectoryInfo(string path)
1616
{
@@ -24,7 +24,7 @@ public FileAttributes Attributes {
2424
}
2525
}
2626

27-
public DateTime Creation {
27+
public DateTime Created {
2828
get {
2929
return _info.CreationTime;
3030
}
@@ -36,7 +36,7 @@ public bool Exists {
3636
}
3737
}
3838

39-
public DateTime LastAccess {
39+
public DateTime LastAccessed {
4040
get {
4141
return _info.LastAccessTime;
4242
}
@@ -54,7 +54,7 @@ public string Name {
5454
}
5555
}
5656

57-
public IDirectoryInfo Parent {
57+
public IFileInfo Parent {
5858
get {
5959
return _parent;
6060
}
@@ -65,5 +65,17 @@ public string Path {
6565
return _info.FullName;
6666
}
6767
}
68+
69+
public long Size {
70+
get {
71+
return 0;
72+
}
73+
}
74+
75+
public FileType Type {
76+
get {
77+
return FileType.Directory;
78+
}
79+
}
6880
}
6981
}

src/Microsoft.IIS.Administration.Files.Core/FileInfo.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.IIS.Administration.Files
1010
class FileInfo : IFileInfo
1111
{
1212
private System.IO.FileInfo _info;
13-
private IDirectoryInfo _parent;
13+
private IFileInfo _parent;
1414

1515
public FileInfo(string path)
1616
{
@@ -24,7 +24,7 @@ public FileAttributes Attributes {
2424
}
2525
}
2626

27-
public DateTime Creation {
27+
public DateTime Created {
2828
get {
2929
return _info.CreationTime;
3030
}
@@ -36,7 +36,7 @@ public bool Exists {
3636
}
3737
}
3838

39-
public DateTime LastAccess {
39+
public DateTime LastAccessed {
4040
get {
4141
return _info.LastAccessTime;
4242
}
@@ -54,7 +54,7 @@ public string Name {
5454
}
5555
}
5656

57-
public IDirectoryInfo Parent {
57+
public IFileInfo Parent {
5858
get {
5959
return _parent;
6060
}
@@ -71,5 +71,11 @@ public long Size {
7171
return _info.Length;
7272
}
7373
}
74+
75+
public FileType Type {
76+
get {
77+
return FileType.File;
78+
}
79+
}
7480
}
7581
}

src/Microsoft.IIS.Administration.Files.Core/FileProvider.cs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,7 @@ public IFileInfo GetFile(string path)
4848
}, path);
4949
}
5050

51-
public FileVersionInfo GetFileVersion(string path)
52-
{
53-
return PerformIO(p => {
54-
55-
var info = new FileInfo(path);
56-
57-
if (!IsAccessAllowed(path, FileAccess.Read) && (info.Parent == null || !IsAccessAllowed(info.Parent.Path, FileAccess.Read))) {
58-
59-
throw new ForbiddenArgumentException(path);
60-
}
61-
62-
return FileVersionInfo.GetVersionInfo(p);
63-
64-
}, path);
65-
}
66-
67-
public IDirectoryInfo GetDirectory(string path)
51+
public IFileInfo GetDirectory(string path)
6852
{
6953
return PerformIO(p => {
7054

@@ -87,7 +71,7 @@ public IEnumerable<IFileInfo> GetFiles(string path, string searchPattern, Search
8771
return PerformIO(p => Directory.GetFiles(p ,searchPattern, searchOption), path).Select(f => new FileInfo(f));
8872
}
8973

90-
public IEnumerable<IDirectoryInfo> GetDirectories(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly)
74+
public IEnumerable<IFileInfo> GetDirectories(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly)
9175
{
9276
this.EnsureAccess(path, FileAccess.Read);
9377

@@ -138,7 +122,7 @@ public IFileInfo CreateFile(string path)
138122
}, path);
139123
}
140124

141-
public IDirectoryInfo CreateDirectory(string path)
125+
public IFileInfo CreateDirectory(string path)
142126
{
143127
this.EnsureAccess(path, FileAccess.ReadWrite);
144128

@@ -218,20 +202,20 @@ private async Task CopyFileInternal(string sourcePath, string destPath)
218202
destFileInfo.CreationTimeUtc = sourceFileInfo.CreationTimeUtc;
219203
}
220204

221-
public void SetFileTime(string path, DateTime? lastAccess, DateTime? lastModified, DateTime? creation)
205+
public void SetFileTime(string path, DateTime? lastAccessed, DateTime? lastModified, DateTime? created)
222206
{
223207
PerformIO(p => {
224208

225-
if (lastAccess != null) {
226-
Directory.SetLastAccessTime(p, lastAccess.Value);
209+
if (lastAccessed != null) {
210+
Directory.SetLastAccessTime(p, lastAccessed.Value);
227211
}
228212

229213
if (lastModified != null) {
230214
Directory.SetLastWriteTime(p, lastModified.Value);
231215
}
232216

233-
if (creation != null) {
234-
Directory.SetCreationTime(p, creation.Value);
217+
if (created != null) {
218+
Directory.SetCreationTime(p, created.Value);
235219
}
236220

237221
}, path);

src/Microsoft.IIS.Administration.Files/Files/FileType.cs renamed to src/Microsoft.IIS.Administration.Files.Core/FileType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Microsoft.IIS.Administration.Files
66
{
7-
enum FileType
7+
public enum FileType
88
{
99
File,
1010
Directory

src/Microsoft.IIS.Administration.Files.Core/IDirectoryInfo.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Microsoft.IIS.Administration.Files.Core/IFileInfo.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@
44

55
namespace Microsoft.IIS.Administration.Files
66
{
7-
public interface IFileInfo : IFileSystemInfo
7+
using System;
8+
using System.IO;
9+
10+
public interface IFileInfo
811
{
12+
string Name { get; }
13+
string Path { get; }
14+
bool Exists { get; }
915
long Size { get; }
10-
IDirectoryInfo Parent { get; }
16+
FileType Type { get; }
17+
IFileInfo Parent { get; }
18+
FileAttributes Attributes { get; }
19+
DateTime LastAccessed { get; }
20+
DateTime LastModified { get; }
21+
DateTime Created { get; }
1122
}
1223
}

src/Microsoft.IIS.Administration.Files.Core/IFileProvider.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Microsoft.IIS.Administration.Files
66
{
77
using System;
88
using System.Collections.Generic;
9-
using System.Diagnostics;
109
using System.IO;
1110
using System.Threading.Tasks;
1211

@@ -16,13 +15,11 @@ public interface IFileProvider
1615

1716
IFileInfo GetFile(string path);
1817

19-
IDirectoryInfo GetDirectory(string path);
20-
21-
FileVersionInfo GetFileVersion(string path);
18+
IFileInfo GetDirectory(string path);
2219

2320
IEnumerable<IFileInfo> GetFiles(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly);
2421

25-
IEnumerable<IDirectoryInfo> GetDirectories(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly);
22+
IEnumerable<IFileInfo> GetDirectories(string path, string searchPattern, SearchOption searchOption = SearchOption.TopDirectoryOnly);
2623

2724
Task Copy(string sourcePath, string destPath);
2825

@@ -32,7 +29,7 @@ public interface IFileProvider
3229

3330
IFileInfo CreateFile(string path);
3431

35-
IDirectoryInfo CreateDirectory(string path);
32+
IFileInfo CreateDirectory(string path);
3633

3734
bool FileExists(string path);
3835

@@ -42,6 +39,6 @@ public interface IFileProvider
4239

4340
bool IsAccessAllowed(string path, FileAccess requestedAccess);
4441

45-
void SetFileTime(string path, DateTime? lastAccess, DateTime? lastModified, DateTime? creation);
42+
void SetFileTime(string path, DateTime? lastAccessed, DateTime? lastModified, DateTime? created);
4643
}
4744
}

src/Microsoft.IIS.Administration.Files.Core/IFileSystemInfo.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Microsoft.IIS.Administration.Files.Core/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
}
1313
},
1414
"dependencies": {
15-
"Microsoft.IIS.Administration.Core": "1.0.0-*"
15+
"Microsoft.IIS.Administration.Core": "1.0.1"
1616
}
1717
}

src/Microsoft.IIS.Administration.Files/Controllers/CopyController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public object Post([FromBody] dynamic model)
5353
throw new NotFoundException("parent");
5454
}
5555

56-
var src = fileType == FileType.File ? _fileService.GetFile(fileId.PhysicalPath) : (IFileSystemInfo)_fileService.GetDirectory(fileId.PhysicalPath);
56+
var src = fileType == FileType.File ? _fileService.GetFile(fileId.PhysicalPath) : _fileService.GetDirectory(fileId.PhysicalPath);
5757

5858
string destPath = Path.Combine(parentId.PhysicalPath, name == null ? src.Name : name);
5959

@@ -85,7 +85,7 @@ public object Get(string id)
8585
return _helper.ToJsonModel(copy);
8686
}
8787

88-
private MoveOperation InitiateCopy(IFileSystemInfo source, string destination)
88+
private MoveOperation InitiateCopy(IFileInfo source, string destination)
8989
{
9090
MoveOperation copy = _helper.Move(source, destination, true);
9191

0 commit comments

Comments
 (0)