[System.IO.Compression] Fixed Zip entries with unset last write time to return the...
authorJoão Matos <joao@tritao.eu>
Fri, 17 Jun 2016 17:19:19 +0000 (18:19 +0100)
committerJoão Matos <joao@tritao.eu>
Fri, 17 Jun 2016 17:23:05 +0000 (18:23 +0100)
.NET on Windows returns a fixed date for this, replicate the same behaviour in Mono.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=40916.

See also: https://github.com/NuGet/Home/issues/2518

mcs/class/System.IO.Compression/SharpCompress/Common/Zip/ZipEntry.cs
mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs
mcs/class/System.IO.Compression/test.nupkg [new file with mode: 0644]

index 6ed742eeca357f3d356466d2f7e36f4b27cd1ec7..2c0ec07e78426d580f3fcd29f61e4f53e8cb6106 100644 (file)
@@ -16,6 +16,13 @@ namespace SharpCompress.Common.Zip
                 this.filePart = filePart;
                 lastModifiedTime = Utility.DosDateToDateTime(filePart.Header.LastModifiedDate,
                                                              filePart.Header.LastModifiedTime);
+                if (lastModifiedTime == default(DateTime))
+                {
+                    // On .NET on Windows, for zip entries that don't have a last write time,
+                    // the return value for ZipArchiveEntry.LastWriteTime is:
+                    //   1/1/1980 12:00:00 AM, Ticks=624511296000000000
+                    lastModifiedTime = new DateTime(624511296000000000);
+                }
             }
         }
 
index d461600299ffbbb1ee8e883897fd10787bd22ff9..4205a1f40a0b4900be8adf5bfb1127136bfa0961 100644 (file)
@@ -263,6 +263,18 @@ namespace MonoTests.System.IO.Compression
                        File.Delete ("test.zip");
                }               
 
+               [Test]
+               public void ZipEnumerateArchiveDefaultLastWriteTime()
+               {
+                       using (var archive = new ZipArchive(File.Open("test.nupkg", FileMode.Open),
+                               ZipArchiveMode.Read))
+                       {
+                               var entry = archive.GetEntry("_rels/.rels");
+                               Assert.AreEqual(new DateTime(624511296000000000).Ticks, entry.LastWriteTime.Ticks);
+                               Assert.IsNotNull(entry);
+                       }
+               }
+
                [Test]
                public void ZipEnumerateEntriesReadMode()
                {
diff --git a/mcs/class/System.IO.Compression/test.nupkg b/mcs/class/System.IO.Compression/test.nupkg
new file mode 100644 (file)
index 0000000..0a7fe05
Binary files /dev/null and b/mcs/class/System.IO.Compression/test.nupkg differ