Skip to content

Unix file timestamps only have one-second granularity #18870

Closed
dotnet/corefx
#30996

Description

@mellinoe

Currently, method such as File.GetLastWriteTime and FileInfo.LastWriteTime return timestamps which are only accurate to the nearest second on Unix. On OSX, this seems to be a system-level limitation in HFS+. On most Linux filesystems, however, millisecond-level information does seem to be available, at least via stat. @stephentoub recommended that we could use utimes rather than utime in the native shim in order to retrieve this information.

This also seems to affect files copied by File.Copy, because we copy over some timestamp metadata from the source file (to match Windows).

Activity

  1. TicoDePano commented on Jul 4, 2018

    @TicoDePano

    On .NET Core 2.1 on Linux it gets worst, as it considers the milliseconds part when comparing files, but a copy doesn't set such a resolution.

  2. danmoseley commented on Jul 5, 2018

    @danmoseley
    Contributor

    @TicoDePano can you clarify? I think this original Issue is fixed : milliseconds are now returned on Unix and also on macOS if APFS partition. What change remains to make?

  3. TicoDePano commented on Jul 5, 2018

    @TicoDePano
    Console.WriteLine($"Runtime:`` {RuntimeInformation.FrameworkDescription}");
    for(int x = 0; x < 2; x++) {
    	FileInfo input = new FileInfo(Path.Combine(config.InputDir, config.File));
    	FileInfo output = new FileInfo(Path.Combine(root, config.OutputDir, config.File));
    	Console.WriteLine($"Input: {input.LastWriteTime.Millisecond} ms, {input.LastWriteTime.Ticks} ticks");
    	Console.WriteLine($"Output: {output.LastWriteTime.Millisecond} ms, {output.LastWriteTime.Ticks} ticks");
    	if(!output.Exists || input.LastWriteTime > output.LastWriteTime) {
    		if(!output.Directory.Exists) {
    			output.Directory.Create();
    			Console.WriteLine($"Copying {group}: directory ${output.Directory.Name} created");
    		}
    		input.CopyTo(output.FullName, true);
    		copy = true;
    		Console.WriteLine($"Copying {group}: file {output.Name} copied");
    	}
    }
    

    .NET Core 2.0 results:
    Runtime: .NET Core 4.6.00001.0
    Input: 0 ms, 636662151720000000 ticks
    Output: 0 ms, 504911120400000000 ticks
    Copying images: directory $img created
    Copying images: file banner1.svg copied
    Input: 0 ms, 636662151720000000 ticks
    Output: 0 ms, 636662151720000000 ticks

    .NET Core 2.1 results:
    Runtime: .NET Core 4.6.26606.02
    Input: 205 ms, 636662151722054140 ticks
    Output: 0 ms, 504911120400000000 ticks
    Copying images: directory $img created
    Copying images: file banner1.svg copied
    Input: 205 ms, 636662151722054140 ticks
    Output: 0 ms, 636662151720000000 ticks
    Copying images: file banner1.svg copied

    *** Output file doesn't exist initially.

  4. danmoseley commented on Jul 6, 2018

    @danmoseley
    Contributor

    I repro this on Ubuntu 1604 -- when we copy the file the access and modify times both drop their millisec part. The change time does not, presumably because the file system sets it.

    Certainly we should fix this. @TicoDePano do you have any interest in investigating?

  5. danmoseley commented on Jul 6, 2018

    @danmoseley
    Contributor

    This might be a servicing candidate actually since presumably it breaks up-to-date checks.

  6. danmoseley commented on Jul 10, 2018

    @danmoseley
    Contributor

    @AndyGerlicher @cdmihai this means if someone copies a file on Linux (or macOS with the latest APFS) using .NET Core (any version) then reads the timestamp with .NET Core 2.1+, the "destination" will look older (have older modified time) than the "source". I would definitely expect that to be causing overbuilds in MSBuild. Have you had reports?

  7. danmoseley commented on Jul 10, 2018

    @danmoseley
    Contributor

    @Anipik could you please fix this? It would be great to get a PR up today in case there is still runway for 2.1.3

  8. Anipik commented on Jul 10, 2018

    @Anipik
    Contributor

    I will make it my first priority.

  9. danmoseley commented on Jul 10, 2018

    @danmoseley
    Contributor
  10. danmoseley commented on Jul 13, 2018

    @danmoseley
    Contributor

    @TicoDePano thank you for the report. This is now fixed in master and we will consider servicing 2.1

  11. TicoDePano commented on Jul 13, 2018

    @TicoDePano

    @danmosemsft thanks and sorry for not helping with the code. I'm not working with C/C++ a long time.

  12. danmoseley commented on Jul 13, 2018

    @danmoseley
    Contributor

    @TicoDePano no problem, you are welcome to look at another issue if you like, most of our issues labeled up-for-grabs are c# changes.

  13. 3 remaining items

  14. leecow commented on Jul 17, 2018

    @leecow
    Member

    Good for Master. Recheck CLI build performance.

  15. danmoseley commented on Jul 17, 2018

    @danmoseley
    Contributor

    To take this in servicing we need evidence customers are actually being impacted.

  16. danmoseley commented on Jul 18, 2018

    @danmoseley
    Contributor

    Shiproom -- I updated template with perf numbers from @Anipik .

  17. vivmishra commented on Jul 19, 2018

    @vivmishra
    Contributor

    Approved for 2.1.5

  18. danmoseley commented on Jul 26, 2018

    @danmoseley
    Contributor

    Leaving everything in 2.1.4 until we determine whether it will have generic fixes

  19. joshfree commented on Aug 9, 2018

    @joshfree
    Member

    Moving to 2.1.5 per shiproom today

  20. Anipik commented on Aug 9, 2018

    @Anipik
    Contributor

    So does that mean we can merge the Linked PR ?

  21. joshfree commented on Aug 10, 2018

    @joshfree
    Member

    @Anipik not yet. Likely next week - please wait for @vivmishra to let us know when the branch is open for 2.1.5 commits.

  22. danmoseley commented on Aug 14, 2018

    @danmoseley
    Contributor

    Moving label to PR per new process

  23. Anipik commented on Aug 29, 2018

    @Anipik
    Contributor

    we have merged this change into release so closing this issue

  24. karelz commented on Sep 6, 2018

    @karelz
    Member

    Fixed in release/2.1 branch in PR dotnet/corefx#31046. Will be part of 2.1.5 release.

  25. transferred this issue fromdotnet/corefxon Jan 31, 2020
  26. added this to the 2.1.x milestone on Jan 31, 2020
  27. ghost locked as resolved and limited conversation to collaborators on Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.IOenhancementhelp wanted

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions