Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

Make PhysicalFile Watcher and Provider disposable #146

Merged
merged 1 commit into from
Nov 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.AspNet.FileProviders
/// <summary>
/// Looks up files using the on-disk file system
/// </summary>
public class PhysicalFileProvider : IFileProvider
public class PhysicalFileProvider : IFileProvider, IDisposable
{
private readonly PhysicalFilesWatcher _filesWatcher;

Expand All @@ -38,6 +38,11 @@ public PhysicalFileProvider(string root)
_filesWatcher = new PhysicalFilesWatcher(Root);
}

public void Dispose()
{
_filesWatcher.Dispose();
}

/// <summary>
/// The root directory for this instance.
/// </summary>
Expand Down Expand Up @@ -105,7 +110,7 @@ public IFileInfo GetFileInfo(string subpath)
return new NotFoundFileInfo(subpath);
}

return new PhysicalFileInfo(_filesWatcher, fileInfo);
return new PhysicalFileInfo(fileInfo);
}

/// <summary>
Expand Down Expand Up @@ -152,7 +157,7 @@ public IDirectoryContents GetDirectoryContents(string subpath)
var fileInfo = fileSystemInfo as FileInfo;
if (fileInfo != null)
{
virtualInfos.Add(new PhysicalFileInfo(_filesWatcher, fileInfo));
virtualInfos.Add(new PhysicalFileInfo(fileInfo));
}
else
{
Expand Down Expand Up @@ -198,12 +203,9 @@ private class PhysicalFileInfo : IFileInfo
{
private readonly FileInfo _info;

private readonly PhysicalFilesWatcher _filesWatcher;

public PhysicalFileInfo(PhysicalFilesWatcher filesWatcher, FileInfo info)
public PhysicalFileInfo(FileInfo info)
{
_info = info;
_filesWatcher = filesWatcher;
}

public bool Exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Microsoft.AspNet.FileProviders
{
internal class PhysicalFilesWatcher
internal class PhysicalFilesWatcher : IDisposable
{
private readonly ConcurrentDictionary<string, FileChangeToken> _tokenCache =
new ConcurrentDictionary<string, FileChangeToken>(StringComparer.OrdinalIgnoreCase);
Expand Down Expand Up @@ -55,6 +55,11 @@ internal IChangeToken CreateFileChangeToken(string filter)
return changeToken;
}

public void Dispose()
{
_fileWatcher.Dispose();
}

private void OnRenamed(object sender, RenamedEventArgs e)
{
// For a file name change or a directory's name change notify registered tokens.
Expand Down
Loading