You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Description
Hi!
In our build system we copy many
Read-only
files to the workspace for processing. We useFile.Copy()
method withoverwrite=true
and sometimes getUnauthorizedAccessException
, because destination file exist and haveRead-only
attribute.This is looks strange because after each copy to workspace we clear
Read-only
attribute by callingFile.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
Stack trace
Workaround
I added
try/catch
forUnauthorizedAccessException
and removeRead-only
attribute again, after this all work fine.The text was updated successfully, but these errors were encountered: