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

System.IO.File.SetAttributes() not clear Read-only attribute on a file #37010

Open
ggaller opened this issue May 26, 2020 · 0 comments
Open

System.IO.File.SetAttributes() not clear Read-only attribute on a file #37010

ggaller opened this issue May 26, 2020 · 0 comments
Milestone

Comments

@ggaller
Copy link

ggaller commented May 26, 2020

Description

Hi!

In our build system we copy many Read-only files to the workspace for processing. We use File.Copy() method with overwrite=true and sometimes get UnauthorizedAccessException, because destination file exist and have Read-only attribute.

This is looks strange because after each copy to workspace we clear Read-only attribute by calling File.SetAttributes() method.

I started investigate this problem and wrote simple app CopyReadonlyFile.zip that stable reproduce this bug (after 20-40 sec of work).

Configuration

.Net Core:
   Version: 3.1.3
   Commit:  4a9f85e9f8

OS:
   OS Name: Microsoft Windows 10 Pro
   OS Version: 10.0.18363 N/A Build 18363
   System Type: x64-based PC

Stack trace

System.UnauthorizedAccessException: Access to the path '<some path to the file>' is denied.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
    at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
    at FilesCopy.<>c__DisplayClass0_0.<Copy>b__0(FileObject f) in FilesCopy.cs:line 32

Workaround

I added try/catch for UnauthorizedAccessException and remove Read-only attribute again, after this all work fine.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.IO untriaged New issue has not been triaged by the area owner labels May 26, 2020
@carlossanlop carlossanlop added this to the Future milestone Jun 29, 2020
@Jozkee Jozkee removed the untriaged New issue has not been triaged by the area owner label Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants