Merge pull request #3036 from tritao/windowsbase_zip_datetime
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 25 May 2016 17:28:55 +0000 (19:28 +0200)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 25 May 2016 17:28:55 +0000 (19:28 +0200)
[WindowsBase] Fixed System.IO.Packaging creating Zip archive with wrong date time entries

mcs/class/WindowsBase/Makefile
mcs/class/WindowsBase/Test/System.IO.Packaging/PackageTest.cs
mcs/class/WindowsBase/ZipSharp/ZipFileInfo.cs

index 842c1ed0ebe00b59e48bc1392671abaa8d8fb563..d3eaf78bc820a95b976ea944eaf6115929fe57d1 100644 (file)
@@ -6,7 +6,7 @@ LIBRARY = WindowsBase.dll
 LIB_REFS = System System.Xml
 LIB_MCS_FLAGS = -unsafe
 TEST_MCS_FLAGS = -unsafe
-TEST_LIB_REFS = WindowsBase System System.Xml System.Core
+TEST_LIB_REFS = WindowsBase System System.Xml System.Core System.IO.Compression
 
 ifeq (2.0, $(FRAMEWORK_VERSION))
 LIB_MCS_FLAGS += -d:NET_3_0
index 933449052f315ffeeae6104c5434135423bf1793..808aa468d38c0c57dd66a8e8ed838363444ed153 100644 (file)
@@ -27,6 +27,7 @@
 using System;\r
 using System.Collections.Generic;\r
 using System.IO;\r
+using System.IO.Compression;\r
 using System.IO.Packaging;\r
 using System.Linq;\r
 using System.Text;\r
@@ -116,7 +117,7 @@ namespace MonoTests.System.IO.Packaging {
             package = Package.Open (path);\r
             package.Close ();\r
             package = Package.Open (path);\r
-        }\r
+        } \r
                \r
                [Test]\r
                public void Close_FileStreamNotClosed ()\r
@@ -416,5 +417,23 @@ namespace MonoTests.System.IO.Packaging {
             File.Create (path).Close ();\r
             package = Package.Open (path, FileMode.OpenOrCreate, FileAccess.Write);\r
         }\r
+\r
+        [Test]\r
+        public void Check_ZipDateTime ()\r
+        {\r
+            using (var zipStream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.ReadWrite))\r
+            using (package = Package.Open (zipStream, FileMode.OpenOrCreate)) {\r
+                var part = package.CreatePart (new Uri ("/test", UriKind.Relative), "test/type");\r
+                using (var stream = part.GetStream ())\r
+                    stream.Write (new byte [1024 * 1024], 0, 1024 * 1024);\r
+            }\r
+\r
+            using (var stream = new FileStream (path, FileMode.Open, FileAccess.Read))\r
+            using (var archive = new ZipArchive(stream))\r
+            {                \r
+                foreach (var entry in archive.Entries)\r
+                    Assert.AreEqual (entry.LastWriteTime.Year, DateTime.Now.Year);\r
+            }\r
+        }           \r
     }\r
 }\r
index 2cbea32a40ce4174ddd8a89b55f8975cf11584f9..2a81a73959bba6ddcf3595874bb9651989261160 100644 (file)
@@ -5,9 +5,11 @@
 //
 
 using System;
+using System.Runtime.InteropServices;
 
 namespace zipsharp
 {
+       [StructLayoutAttribute (LayoutKind.Sequential)]
        struct ZipFileInfo
        {
                ZipTime date;
@@ -38,7 +40,7 @@ namespace zipsharp
                public ZipFileInfo (DateTime fileTime)
                {
                        date = new ZipTime (fileTime);
-                       dosDate = new IntPtr ((int)fileTime.ToFileTime ());
+                       dosDate = IntPtr.Zero;
                        internalFileAttributes = IntPtr.Zero;
                        externalFileAttributes = IntPtr.Zero;
                }