From be18ee31be76b10faee1a5d647202eb428e73696 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 27 Jan 2016 16:20:26 -0800 Subject: [PATCH] Switch to using File.LastWriteTimeUtc --- .../ProjectContextCollection.cs | 12 ++++----- .../WorkspaceContext.cs | 18 ++++++------- src/dotnet-build/CompileContext.cs | 15 +++++------ test/E2E/EndToEndTest.cs | 26 ++++++++----------- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectContextCollection.cs b/src/Microsoft.DotNet.ProjectModel/ProjectContextCollection.cs index b65de587a..a8ad3f3ad 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectContextCollection.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectContextCollection.cs @@ -19,9 +19,9 @@ namespace Microsoft.DotNet.ProjectModel public string ProjectFilePath { get; set; } - public DateTime LastProjectFileWriteTime { get; set; } + public DateTime LastProjectFileWriteTimeUtc { get; set; } - public DateTime LastLockFileWriteTime { get; set; } + public DateTime LastLockFileWriteTimeUtc { get; set; } public bool HasChanged { @@ -32,7 +32,7 @@ namespace Microsoft.DotNet.ProjectModel return true; } - if (LastProjectFileWriteTime < File.GetLastWriteTime(ProjectFilePath)) + if (LastProjectFileWriteTimeUtc < File.GetLastWriteTimeUtc(ProjectFilePath)) { return true; } @@ -42,7 +42,7 @@ namespace Microsoft.DotNet.ProjectModel return true; } - if (LastLockFileWriteTime < File.GetLastWriteTime(LockFilePath)) + if (LastLockFileWriteTimeUtc < File.GetLastWriteTimeUtc(LockFilePath)) { return true; } @@ -57,8 +57,8 @@ namespace Microsoft.DotNet.ProjectModel ProjectContexts.Clear(); ProjectFilePath = null; LockFilePath = null; - LastLockFileWriteTime = DateTime.MinValue; - LastProjectFileWriteTime = DateTime.MinValue; + LastLockFileWriteTimeUtc = DateTime.MinValue; + LastProjectFileWriteTimeUtc = DateTime.MinValue; ProjectDiagnostics.Clear(); } } diff --git a/src/Microsoft.DotNet.ProjectModel/WorkspaceContext.cs b/src/Microsoft.DotNet.ProjectModel/WorkspaceContext.cs index 6faabfdc3..f046143f7 100644 --- a/src/Microsoft.DotNet.ProjectModel/WorkspaceContext.cs +++ b/src/Microsoft.DotNet.ProjectModel/WorkspaceContext.cs @@ -180,7 +180,7 @@ namespace Microsoft.DotNet.ProjectModel { currentEntry.Model = project; currentEntry.FilePath = project.ProjectFilePath; - currentEntry.UpdateLastWriteTime(); + currentEntry.UpdateLastWriteTimeUtc(); } } @@ -206,7 +206,7 @@ namespace Microsoft.DotNet.ProjectModel { currentEntry.FilePath = Path.Combine(projectDirectory, LockFile.FileName); currentEntry.Model = LockFileReader.Read(currentEntry.FilePath); - currentEntry.UpdateLastWriteTime(); + currentEntry.UpdateLastWriteTimeUtc(); } } @@ -248,13 +248,13 @@ namespace Microsoft.DotNet.ProjectModel currentEntry.Project = project; currentEntry.ProjectFilePath = project.ProjectFilePath; - currentEntry.LastProjectFileWriteTime = File.GetLastWriteTime(currentEntry.ProjectFilePath); + currentEntry.LastProjectFileWriteTimeUtc = File.GetLastWriteTimeUtc(currentEntry.ProjectFilePath); var lockFilePath = Path.Combine(project.ProjectDirectory, LockFile.FileName); if (File.Exists(lockFilePath)) { currentEntry.LockFilePath = lockFilePath; - currentEntry.LastLockFileWriteTime = File.GetLastWriteTime(lockFilePath); + currentEntry.LastLockFileWriteTimeUtc = File.GetLastWriteTimeUtc(lockFilePath); } currentEntry.ProjectDiagnostics.AddRange(projectEntry.Diagnostics); @@ -265,7 +265,7 @@ namespace Microsoft.DotNet.ProjectModel private class FileModelEntry where TModel : class { - private DateTime _lastWriteTime; + private DateTime _lastWriteTimeUtc; public TModel Model { get; set; } @@ -273,9 +273,9 @@ namespace Microsoft.DotNet.ProjectModel public List Diagnostics { get; } = new List(); - public void UpdateLastWriteTime() + public void UpdateLastWriteTimeUtc() { - _lastWriteTime = File.GetLastWriteTime(FilePath); + _lastWriteTimeUtc = File.GetLastWriteTimeUtc(FilePath); } public bool IsInvalid @@ -292,7 +292,7 @@ namespace Microsoft.DotNet.ProjectModel return true; } - return _lastWriteTime < File.GetLastWriteTime(FilePath); + return _lastWriteTimeUtc < File.GetLastWriteTimeUtc(FilePath); } } @@ -301,7 +301,7 @@ namespace Microsoft.DotNet.ProjectModel Model = null; FilePath = null; Diagnostics.Clear(); - _lastWriteTime = DateTime.MinValue; + _lastWriteTimeUtc = DateTime.MinValue; } } diff --git a/src/dotnet-build/CompileContext.cs b/src/dotnet-build/CompileContext.cs index 1c5451c0a..519a0d012 100644 --- a/src/dotnet-build/CompileContext.cs +++ b/src/dotnet-build/CompileContext.cs @@ -5,12 +5,11 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; - +using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.Tools.Compiler; using Microsoft.DotNet.ProjectModel.Utilities; -using Microsoft.DotNet.Cli.Compiler.Common; +using Microsoft.DotNet.Tools.Compiler; namespace Microsoft.DotNet.Tools.Build { @@ -115,21 +114,21 @@ namespace Microsoft.DotNet.Tools.Build // find the output with the earliest write time var minOutputPath = compilerIO.Outputs.First(); - var minDate = File.GetLastWriteTime(minOutputPath); + var minDateUtc = File.GetLastWriteTimeUtc(minOutputPath); foreach (var outputPath in compilerIO.Outputs) { - if (File.GetLastWriteTime(outputPath) >= minDate) + if (File.GetLastWriteTimeUtc(outputPath) >= minDateUtc) { continue; } - minDate = File.GetLastWriteTime(outputPath); + minDateUtc = File.GetLastWriteTimeUtc(outputPath); minOutputPath = outputPath; } // find inputs that are older than the earliest output - var newInputs = compilerIO.Inputs.FindAll(p => File.GetLastWriteTime(p) > minDate); + var newInputs = compilerIO.Inputs.FindAll(p => File.GetLastWriteTimeUtc(p) > minDateUtc); if (!newInputs.Any()) { @@ -140,7 +139,7 @@ namespace Microsoft.DotNet.Tools.Build Reporter.Output.WriteLine($"Project {project.GetDisplayName()} will be compiled because some of its inputs were newer than its oldest output."); Reporter.Verbose.WriteLine(); Reporter.Verbose.WriteLine($" Oldest output item:"); - Reporter.Verbose.WriteLine($" {minDate}: {minOutputPath}"); + Reporter.Verbose.WriteLine($" {minDateUtc.ToLocalTime()}: {minOutputPath}"); Reporter.Verbose.WriteLine(); Reporter.Verbose.WriteLine($" Inputs newer than the oldest output item:"); diff --git a/test/E2E/EndToEndTest.cs b/test/E2E/EndToEndTest.cs index c5fa7617a..2a4280692 100644 --- a/test/E2E/EndToEndTest.cs +++ b/test/E2E/EndToEndTest.cs @@ -2,16 +2,12 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using Xunit; -using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.Extensions.PlatformAbstractions; +using Xunit; namespace Microsoft.DotNet.Tests.EndToEnd { @@ -57,16 +53,16 @@ namespace Microsoft.DotNet.Tests.EndToEnd TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); var binariesOutputDirectory = GetCompilationOutputPath(OutputDirectory, false); - var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles( + var latestWriteTimeFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles( binariesOutputDirectory); // second build; should get skipped (incremental because no inputs changed) buildCommand.Execute().Should().Pass(); TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); - var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles( + var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles( binariesOutputDirectory); - Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild); + Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeUtcSecondBuild); TouchSourceFileInDirectory(TestDirectory); @@ -74,9 +70,9 @@ namespace Microsoft.DotNet.Tests.EndToEnd buildCommand.Execute().Should().Pass(); TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); - var latestWriteTimeThirdBuild = GetLastWriteTimeOfDirectoryFiles( + var latestWriteTimeUtcThirdBuild = GetLastWriteTimeUtcOfDirectoryFiles( binariesOutputDirectory); - Assert.NotEqual(latestWriteTimeSecondBuild, latestWriteTimeThirdBuild); + Assert.NotEqual(latestWriteTimeUtcSecondBuild, latestWriteTimeUtcThirdBuild); } [Fact] @@ -129,15 +125,15 @@ namespace Microsoft.DotNet.Tests.EndToEnd TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); - var latestWriteTimeFirstBuild = GetLastWriteTimeOfDirectoryFiles(binariesOutputDirectory); + var latestWriteTimeUtcFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory); // second build; should be skipped because nothing changed buildCommand.Execute().Should().Pass(); TestNativeOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); - var latestWriteTimeSecondBuild = GetLastWriteTimeOfDirectoryFiles(binariesOutputDirectory); - Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeSecondBuild); + var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles(binariesOutputDirectory); + Assert.Equal(latestWriteTimeUtcFirstBuild, latestWriteTimeUtcSecondBuild); } [Fact] @@ -206,9 +202,9 @@ namespace Microsoft.DotNet.Tests.EndToEnd return false; } - private static DateTime GetLastWriteTimeOfDirectoryFiles(string outputDirectory) + private static DateTime GetLastWriteTimeUtcOfDirectoryFiles(string outputDirectory) { - return Directory.EnumerateFiles(outputDirectory).Max(f => File.GetLastWriteTime(f)); + return Directory.EnumerateFiles(outputDirectory).Max(f => File.GetLastWriteTimeUtc(f)); } private static void TouchSourceFileInDirectory(string directory)