예제 #1
0
파일: File.cs 프로젝트: bangush/LongPath
        public static unsafe void SetLastAccessTimeUtc(String path, DateTime lastAccessTimeUtc)
        {
            if (Common.IsRunningOnMono() && Common.IsPlatformUnix())
            {
                SysFile.SetLastAccessTimeUtc(path, lastAccessTimeUtc);
                return;
            }
            string normalizedPath = Path.NormalizeLongPath(path);

            using (SafeFileHandle handle = GetFileHandle(normalizedPath,
                                                         FileMode.Open, FileAccess.Write, FileShare.ReadWrite, FileOptions.None))
            {
                var  fileTime = new NativeMethods.FILE_TIME(lastAccessTimeUtc.ToFileTimeUtc());
                bool r        = NativeMethods.SetFileTime(handle, null, &fileTime, null);
                if (!r)
                {
                    int errorCode = Marshal.GetLastWin32Error();
                    Common.ThrowIOError(errorCode, path);
                }
            }
        }