forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystemVirtualFile.cs
More file actions
55 lines (44 loc) · 1.72 KB
/
FileSystemVirtualFile.cs
File metadata and controls
55 lines (44 loc) · 1.72 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
using System;
using System.IO;
using ServiceStack.IO;
namespace ServiceStack.VirtualPath
{
public class FileSystemVirtualFile : AbstractVirtualFileBase
{
protected FileInfo BackingFile;
public override string Name => BackingFile.Name;
public override string RealPath => BackingFile.FullName;
public override DateTime LastModified => BackingFile.LastWriteTimeUtc;
public override long Length => BackingFile.Length;
public FileSystemVirtualFile(IVirtualPathProvider owningProvider, IVirtualDirectory directory, FileInfo fInfo)
: base(owningProvider, directory)
{
this.BackingFile = fInfo ?? throw new ArgumentNullException(nameof(fInfo));
}
public override Stream OpenRead()
{
var i = 0;
var firstAttempt = DateTime.UtcNow;
IOException originalEx = null;
while (DateTime.UtcNow - firstAttempt < VirtualPathUtils.MaxRetryOnExceptionTimeout)
{
try
{
i++;
return BackingFile.OpenRead();
}
catch (IOException ex) // catch The process cannot access the file '...' because it is being used by another process.
{
if (originalEx == null)
originalEx = ex;
i.SleepBackOffMultiplier();
}
}
throw new TimeoutException($"Exceeded timeout of {VirtualPathUtils.MaxRetryOnExceptionTimeout}", originalEx);
}
public override void Refresh()
{
BackingFile.Refresh();
}
}
}