-
Notifications
You must be signed in to change notification settings - Fork 258
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
Timestamps of file of packed package is shifted by the timezone #7395
Comments
What is the impact of our current behavior? |
I include source code etc in package. |
We are moving away from .symbols.nupkg files towards .snupkg files in the VS 15.9 timeframe. |
I never used the source link, but I will check if it is available in the future. |
…ple issues with timestamps in NuGet packages, but they should not be important, because in practice all compared file versions should be extracted from same NuGet package. Btw, issues are: 1. Old version of NuGet overwrite LastModifiedTime to time when the package is created (still used for Rhetos.CommonConcepts, for backward compatibility with DeployPackages) 2. New NuGet pack/unpack can shift last modified time zone: NuGet/Home#7395 3. Zip entry timestamps in NuGet package are recorded only to 2 second precision.
Note, that this behavior causes MSBuild to consider files up-to-date and skip running targets if they are dependent on files within NuGet package. For instance, I'd expect MSBuild task assembly I've just modified+built+packed+restored to be considered an out-of-date input. But instead, I have a newer input being considered older (due to UTC), than actually older files (UTC+6). Cross-referencing my SharpGen branch. |
I have the same issue. One additional thing I noticed is that only the timestamps of the DLL/PDB files are shifted. Other files inside the nupkg zip file (e.g. the "nuspec" file or the "[Content_Types].xml" or the "_rels") all have correct timestamps. @rrelyea Regarding the impact, other than that I don't like that there's incorrect and misleading information in the package, this is also causing issues with up-to-date checks same as @andrew-boyarshin mentioned. Incorrectly working up-to-date checks on my solution is also how I discovered the issue in the first place... |
I want to fix this along with my fix for Issue#7001 in PR#3793. Just one reminder is if I pack package in PST timezone then unpack it in Samao timezone then they'll get exact same timestamp. But caveat is 1/1/1980 12:00:00AM in Samao is not same as 1/1/1980 12:00:00AM in PST, but it's very easy to reason and maybe good for repeatable build scenarios. Is it ok? |
@erdembayar In my opnion, we should always convert to UTC before setting the timestamp in the nupkg. I don't know if zip files store timezone in addition to date and time. If not, it's critical to store times as UTC, always. But, if it is, we should make sure we do the right conversion to local time when saving the file on the local file system (extracting the nupkg), because not all nupkgs are created with official tools, so we can't trust the data in a nupkg (to always use UTC time). |
@zivkan Can you elaborate more on |
@erdembayar I'll explain the issue I'm experiencing. I'm in the Prague timezone (UTC+1). I build some DLLs, and their LastModified timestamp will be 19:47 in UTC+1 Prague, or, in other words, 18:47 UTC. Then I pack the NuGet and then restore it, and the DLLs in the NuGet cache have LastModified timestamp of 18:47 in UTC+1 Prague, or in other words, 17:47 UTC. Just by packing the NuGet, the timestamps shifted by 1 hour. The timestamps are already wrong inside the ZIP package, so it's an issue with the "pack" command, not the "restore" command. And also it only affects DLL or PDB files, other files inside the package have their timestamps working correctly as expected. |
I spent entirely too much time on this, but what I found was: First, Wikipedia's article on the zip file format say
Therefore, the best we can do is assume that the time stamp in the file is in the UTC (+0) time zone, which also means we need to make sure when we save a nupkg, that the time is adjusted to UTC. Consider the following code: using (var memoryStream = new MemoryStream())
{
using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
{
var entry = zip.CreateEntry("file.ext");
var now = DateTimeOffset.UtcNow;
entry.LastWriteTime = now;
var when = entry.LastWriteTime;
var diff = when - now;
}
memoryStream.Position = 0;
using (var zip = new ZipArchive(memoryStream, ZipArchiveMode.Read))
{
var entry = zip.Entries.Single();
var timestamp = entry.LastWriteTime;
var expected = DateTimeOffset.Now;
var diff = expected - timestamp;
if (diff.TotalMinutes > 1.0 || diff.TotalMinutes < -1.0)
{
Console.WriteLine("Did not round trip the time successfully");
}
else
{
Console.WriteLine("Time stamp is good");
}
}
} We see this results in a message saying the time did not round trip! If you change the first line to an actual file instead of a memory stream, and open the zip in whatever program you like, you see the time written is the value specified in the However, in the second half of the code, where it reads the last write time, .NET assumes the time is local. So, if we write the UTC time to the zip file, when we read it it's offset by whatever time zone our computer is in. One issue is that the .NET type already thinks it's in local time, meaning that From a 10 second test, it seems that Therefore, I have two suggestions:
|
@zivkan Fascinating, thanks for sharing your findings. One thing that was strange to me is that the DLLs and PDBs inside the NuGet were the only shifted files. The other files (like the |
@tompazourek, when we pack files off the disk, we use |
@zivkan That explains it, thanks. In addition to your suggestions how to fix this that all make sense to me (like if we adjust to UTC during packing, we should adjust from UTC when restoring), I'd also suggest handling all files the same way. I don't see why some files should be treated differently than other. |
@zivkan For example in file in Newtonsoft nupkg(zip) package: After extraction on PST timezone. Timestamp difference is 8 hours. Same package after extraction on Samao timezone. |
I'm using nuget 4.7.1 .
When I pack with nuget then extract on included files, the extracted files last modified times are -9 hours. (I'm in a +9:00 timezone.)
The problem of Last Modified time for included files, seems fixed in #5240, But LastWriteTime is set UTC time.
ZipArchiveEntry.LastWriteTime(in .NET) seems not supported extended timestamp of Zip.
Therefore, I think that it is better to set local time to LastWriteTime.
Or is there a way to set local time correctly?
Details about Problem
NuGet.exe version = 4.7.1.5393(also tried 4.6.2.5055 and 4.8.1.5435)
.NET version = 4.7.03062
OS version = Windows 7 Professional (build 7601 : Service Pack 1)
Detailed repro steps so we can see the same problem
nuget.exe pack xxxx.nuspec
The text was updated successfully, but these errors were encountered: