Bug 40368 - Setting FileInfo.LastWriteTime has different results with mono32 and mono64
Summary: Setting FileInfo.LastWriteTime has different results with mono32 and mono64
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Rodrigo Kumpera
URL:
: 23934 ()
Depends on:
Blocks:
 
Reported: 2016-04-13 22:51 UTC by Ankit Jain
Modified: 2016-04-19 00:09 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Ankit Jain 2016-04-13 22:51:05 UTC
Setting the LastWriteTime for a file via FileInfo:

var info = new FileInfo(file);
var time = new DateTime(2039, 1, 1);
info.LastWriteTime = time;

// reading that time again
info = new FileInfo(file);

// with mono32: info.LastWriteTime: 25-11-1902 17:31:44
// ls -l <file> : Nov 25  1902 /var/folders/3g/27cm3t29301gds8d89pf3xyh0000gp/T/tmp4f9ed2dc.tmp

// with mono64: info.LastWriteTime: 01-01-2039 00:00:00
// ls -l <file> : Jan  1  2039 /var/folders/3g/27cm3t29301gds8d89pf3xyh0000gp/T/tmp3969d9af.tmp

// expected:    info.LastWriteTime: 01-01-2039 00:00:00

It works fine with a "32bit date".

Mono JIT compiler version 4.4.0 (mono-4.4.0-branch/a3fabf1 Fri Apr  8 13:48:29 EDT 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           normal
        SIGSEGV:       altstack
        Notification:  kqueue
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug
        LLVM:          yes(3.6.0svn-mono-master/a173357)
        GC:            sgen

Test program:

using System;
using System.IO;

public class Test
{
        public static void Main ()
        {
                string file = Path.GetTempFileName();
                File.WriteAllText(file, String.Empty);
                Console.WriteLine ($"file: {file}");

                var info = new FileInfo(file);
                Console.WriteLine ($"LastWriteTime: {info.LastWriteTime}");

                var time = new DateTime(2039, 1, 1);
                Console.WriteLine ($"Setting LastWriteTime to {time}");
                info.LastWriteTime = time;

                info = new FileInfo(file);
                Console.WriteLine ($"\tReading with a new instance of FileInfo: info.LastWriteTime: {info.LastWriteTime}, expected to be {time}");
        }
}
Comment 1 Marek Safar 2016-04-14 20:13:35 UTC
This is Mono Year 2038 problem

I/O layer uses wrongly `utimbuf` at https://github.com/mono/mono/blob/255ce320b0da31b6e50cef084a4079039ccb39d6/mono/io-layer/io-portability.c#L117 which is CPU specific in the way that it uses time_t which can be 32-bit only.

I'll leave it to runtime team to decide what's the best fix for this to be CPU agnostic.
Comment 2 Zoltan Varga 2016-04-15 00:28:14 UTC
There is no posix api to set the file times to later that 2038. We can throw an exception instead.
Comment 3 Marek Safar 2016-04-15 07:00:42 UTC
Possibly if there easy way to detect time_t is 32bit, e.g. OpenBSD uses 64bits on 32bits system and some new stuff uses float/double.

Or do what glibc does and have _TIME_BITS=64

Or use something like

https://github.com/evalEmpire/y2038
Comment 4 Rodrigo Kumpera 2016-04-15 22:33:12 UTC
Working on it.
Comment 5 Marek Safar 2016-04-16 07:46:50 UTC
*** Bug 23934 has been marked as a duplicate of this bug. ***
Comment 6 Rodrigo Kumpera 2016-04-19 00:09:04 UTC
Fixed in 7b4a585094187d087c2dd7e55740933663485c84.