-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
TarEntry.ExtractToFile
does not set the last write time of the file to the local time
#73825
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsDescriptionWhen using Reproduction Steps
Expected behaviorThe last write time should have a time that is in the local timezone. Actual behaviorThe last write time is in the UTC timezone e.g. it is ahead of Pacific Time by 8 hours. Regression?No response Known WorkaroundsNo response Configuration7.0.100-preview.6.22352.1 Other informationNo response
|
I am moving it to .NET 8 milestone now (today is the last day to merge .NET 7 changes). If @carlossanlop decides that it's a bug we can always backport the fix to 7.0. |
We have to fix this, we can't set the wrong times on files. I'll fix it. |
Our date and time types are easy to get wrong -- the type system does not help prevent you mixing up UTC and local. Looking at what Zip does first (offset at my home is -7):
vs Tar
Dizzying .. The main gotcha seems to be getting dateTimeOffset.DateTime. The docs say
In the case of zip, it gets away with it because the DateTimeOffset has a zero offset, so it doesn't matter. The constructor of DateTimeOffset over DateTime (or equivalently the implicit conversion) is also potentially lossy
What I conclude from this is
|
@danmoseley - the behaviors with Part of the issue here is that Also not sure if it's relevant here, but keep in mind there are differences in file system behavior. NTFS and most Unix file systems keep file times in terms of UTC, while FAT/FAT32/exFAT systems keep them in local time without offset. This tends to be an issue more with USB thumbdrives and camera SD cards though. Ultimately with this issue, I think the problem must be somewhere in the |
Oh I see your changes now. Yep - that seems right. The real culprit was here:
That should probably be |
Or rather the inverse: File.SetLastWriteTimeUtc(destinationFileName, lastWriteTime.UtcDateTime); |
Thanks @mattjohnsonpint Well established, but is there anything we could/should do to help avoid this kind of error? For example deprecate DateTmeOffset.DateTime. |
That would create too much pain, IMHO. Indeed if you have a One example I can think of is when persisting a I could see it might be valuable to have an analyzer that understands many common targets (like Also worth pointing out here that the inverse operation is another gotcha - specifically, the |
Description
When using
TarEntry.ExtractToFile
method, the last write time of the extracted file is the UTC time, not the local time.Reproduction Steps
Set-ItemProperty -Path "TestDrive:/oldfile.txt" -Name "LastWriteTime" -Value '2003-01-16 14:44'
TarWriter
TarEntry.ExtractToFile
Expected behavior
The last write time should have a time that is in the local timezone.
Actual behavior
The last write time is in the UTC timezone e.g. it is ahead of Pacific Time by 8 hours.
Regression?
No response
Known Workarounds
No response
Configuration
7.0.100-preview.6.22352.1
PowerShell 7.3.0-preview6
Windows 11, x64
Other information
No response
The text was updated successfully, but these errors were encountered: