Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FileProviders.Physical.GetLastWriteTimeUtc crash #57415

Merged
2 commits merged into from
Aug 15, 2021
Merged
Changes from 1 commit
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 @@ -25,7 +25,7 @@ namespace Microsoft.Extensions.FileProviders.Physical
public class PollingFileChangeToken : IPollingChangeToken
{
private readonly FileInfo _fileInfo;
private DateTime _previousWriteTimeUtc;
private DateTime? _previousWriteTimeUtc;
private DateTime _lastCheckedTimeUtc;
private bool _hasChanged;
private CancellationTokenSource _tokenSource;
Expand All @@ -45,7 +45,7 @@ public PollingFileChangeToken(FileInfo fileInfo)
// Internal for unit testing
internal static TimeSpan PollingInterval { get; set; } = PhysicalFilesWatcher.DefaultPollingInterval;

private DateTime GetLastWriteTimeUtc()
private DateTime? GetLastWriteTimeUtc()
{
_fileInfo.Refresh();

Expand All @@ -65,7 +65,7 @@ private DateTime GetLastWriteTimeUtc()
catch (IOException) { } // https://github.com/dotnet/runtime/issues/57221
}

return lastWriteTimeUtc.Value;
return lastWriteTimeUtc;
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down Expand Up @@ -109,8 +109,8 @@ public bool HasChanged
return _hasChanged;
}

DateTime lastWriteTimeUtc = GetLastWriteTimeUtc();
if (_previousWriteTimeUtc != lastWriteTimeUtc)
DateTime? lastWriteTimeUtc = GetLastWriteTimeUtc();
if (lastWriteTimeUtc != null && _previousWriteTimeUtc != lastWriteTimeUtc)
{
_previousWriteTimeUtc = lastWriteTimeUtc;
_hasChanged = true;
Expand Down