Skip to content
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

[release/6.0] Fix setting timestamp on Windows on readonly files #62922

Merged
merged 3 commits into from
Jan 7, 2022

Conversation

adamsitnik
Copy link
Member

@adamsitnik adamsitnik commented Dec 16, 2021

Backport of #62638
Fix #62602

Customer Impact

Addresses a DTS bug that has been reported internally. Attempting to modify the timestamp of a read-only file on Windows with an API like File.SetXXTimeXX throws UnauthorizedAccessException.

This is not a regression. The exception is thrown on.NET Framework as well. It’s clearly a bug (we’re passing the wrong flag) and it has always succeeded on Linux. We already fixed it for 7.0. In theory a customer could be depending on the current behavior, but our assumption is that this is unlikely.

Testing

A regression test has been added and it's passing.

Risk

Low, as the fix is about using less restrictive access rights when opening a file handle to modify the file attributes (FILE_WRITE_ATTRIBUTES instead GENERIC_WRITE which combines FILE_WRITE_ATTRIBUTES and many other flags) .

cc @ericstj

@adamsitnik adamsitnik added the Servicing-consider Issue for next servicing release review label Dec 16, 2021
@adamsitnik adamsitnik added this to the 6.0.x milestone Dec 16, 2021
@ghost ghost assigned adamsitnik Dec 16, 2021
@ghost
Copy link

ghost commented Dec 16, 2021

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

Backport of #62638

Customer Impact

Addresses a DTS bug that has been reported internally. File.SetLastAccessTimeUtc was unable to modify the access time of readonly files.

Testing

A regression test has been added and it's passing.

Risk

Low, as the fix is about using less restrictive access rights when opening a file handle to modify the file attributes (FILE_WRITE_ATTRIBUTES instead GENERIC_WRITE which combines FILE_WRITE_ATTRIBUTES and many other flags) .

cc @ericstj

Author: adamsitnik
Assignees: -
Labels:

Servicing-consider, area-System.IO

Milestone: 6.0.x

@danmoseley
Copy link
Member

Hmm, out of an abundance of caution, given this behavior has existed for many years, including on .NET Framework, and some might believe it is expected behavior, would it make sense to add an app context flag, just for the backport? I don't have any concerns about 7.0, but in servicing we don't expect customers to change their code. @marklio thoughts? Note, this brings behavior in line with Linux; any issue would be in some code written for Windows, possibly long ago.

@danmoseley danmoseley changed the base branch from backport/pr-62819-to-release/6.0 to release/6.0 December 30, 2021 19:12
danmoseley and others added 3 commits December 30, 2021 21:11
# Conflicts:
#	src/libraries/System.IO.FileSystem/tests/Base/BaseGetSetTimes.cs
@danmoseley
Copy link
Member

@adamsitnik what are your thoughts about including an app context switch (default to the new behavior)? If there is a customer broken by this, they would still be able to receive the other fixes in the 6.0.2 patch. There is no need for a switch in main/7.0 as that is a voluntary update.

Worst case, nobody uses it (I suspect nobody will)

@leecow leecow added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Jan 4, 2022
@leecow leecow modified the milestones: 6.0.x, 6.0.2 Jan 4, 2022
@ericstj
Copy link
Member

ericstj commented Jan 5, 2022

We don't typically quirk removal of an exception like this. I chatted with @danmoseley and he mentioned he's OK with this as-is.

@danmoseley
Copy link
Member

@dotnet/dnceng there are CI legs here that have been running for 5 days. Should there be some timeout applying here?

I"ll rerun.

@danmoseley danmoseley closed this Jan 6, 2022
@danmoseley danmoseley reopened this Jan 6, 2022
@MattGal
Copy link
Member

MattGal commented Jan 6, 2022

@dotnet/dnceng there are CI legs here that have been running for 5 days. Should there be some timeout applying here?

I"ll rerun.

Should yes, usually anything over a day is a missing call to a web hook or other API. I'll poke around a bit to see if I can find anything more nefarious.

@marklio
Copy link

marklio commented Jan 6, 2022

Just saw this back from vacation. Since I was summoned, I'll weigh in even though I think stakeholders have reached consensus already. It's going to be pretty expensive to try to draw any conclusions based on existing usage (meaningful exception handling comprehension in static analysis tools is very tricky), so I'm not sure it's worth it. On .NET Framework, we would definitely not change this default behavior in servicing. If there was a request with business justification, we'd quirk it for a new release and allow folks to opt-in in a servicing update if we could appropriately manage the risk of the change (we probably could). For the Core model, this seems analogous to changing the behavior in a new release. That said, I don't think the risk is very high that folks are using these calls as last line of defense "is readonly" checks, so I think the value of consistency between OS platforms, and moving to behavior we think is correct likely wins out here. I'd definitely document it as a breaking change though.

@danmoseley
Copy link
Member

Thanks @marklio. Note this is servicing, it's already merged into 7.0. I'm not sure from your comment about major version whether you had noted that.

Good reminder to doc it though

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.IO Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants