-
Notifications
You must be signed in to change notification settings - Fork 980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tests and ZipEntry DateTime Kind #502
Conversation
|
||
namespace ICSharpCode.SharpZipLib.Tests.Zip | ||
{ | ||
[TestFixture] | ||
public class WindowsNameTransformHandling : TransformBase | ||
{ | ||
[OneTimeSetUp] | ||
public void TestInit() { | ||
if (Path.DirectorySeparatorChar != '\\') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth using the [Platform] attribute so that the tests only run on Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, I didn't actually know about that one. I just figured feature detection was actually what was important anyway, instead of guessing based on the OS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what's best, just wondered if tests that involve drive letters might have issues as well as things with separators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah maybe, it's kind of hard to test until any OS starts using drive letters and forward slashes though 😁
@@ -742,7 +742,7 @@ public long DosTime | |||
uint mon = Math.Max(1, Math.Min(12, ((uint)(value >> 21) & 0xf))); | |||
uint year = ((dosTime >> 25) & 0x7f) + 1980; | |||
int day = Math.Max(1, Math.Min(DateTime.DaysInMonth((int)year, (int)mon), (int)((value >> 16) & 0x1f))); | |||
DateTime = new DateTime((int)year, (int)mon, day, (int)hrs, (int)min, (int)sec, DateTimeKind.Utc); | |||
DateTime = new DateTime((int)year, (int)mon, day, (int)hrs, (int)min, (int)sec, DateTimeKind.Unspecified); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any mention of timezones in the appnote, so if it's unknown then unspecified seems a reasonable choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And more importantly, if you create a DateTime instance and specify that it is in UTC, then the OS will translate it to local time when using it to set the file attributes. If you use Unspecified
it will not do any such translation.
(If the appnote DID mention it being in UTC, we could of course use the UTC-versions of the attribute setters instead).
TL;DR: The Adding files to archivesWhen adding files to ZIP archives using SharpZipLib/src/ICSharpCode.SharpZipLib/Zip/ZipEntryFactory.cs Lines 221 to 253 in b5898dc
The default value for the SharpZipLib/src/ICSharpCode.SharpZipLib/Zip/ZipEntryFactory.cs Lines 17 to 58 in b5898dc
This means by default the If Extracting files from archivesWhen extracting files from ZIP archives using SharpZipLib/src/ICSharpCode.SharpZipLib/Zip/FastZip.cs Lines 640 to 643 in b5898dc
The following table shows how
Impact of proposed changeThis PR changes the following code to use
Because the default behavior of the library is to capture timestamps as local time and An alternative would be to use |
Great summary! |
This should allow all tests to pass on both *nix and windows.
The current outstanding bug with ZipEntry file names not being automatically cleaned has been moved to it's own test, as this is a known (although unwanted) behaviour of the current state the code base is in.
By doing this we should be able to have failing tests prevent PRs from being merged in a more controlled manner.
Fixes #481
I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the SharpZipLib open source product (the "Contribution"). My Contribution is licensed under the MIT License.