[BUG] DataLakeFileClient Upload / UploadAsync fail on readonly files
See original GitHub issueDescribe the bug
There are 3 places in DataLakeFileClient
where a FileStream
is created with unnecessary write access (implicit by the latter’s ctor):
https://github.com/Azure/azure-sdk-for-net/blob/322f6952e4946229949bd3375f5eb6120895fd2f/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs#L3111
https://github.com/Azure/azure-sdk-for-net/blob/322f6952e4946229949bd3375f5eb6120895fd2f/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs#L3227
https://github.com/Azure/azure-sdk-for-net/blob/322f6952e4946229949bd3375f5eb6120895fd2f/sdk/storage/Azure.Storage.Files.DataLake/src/DataLakeFileClient.cs#L3439
This will cause failures when trying to upload readonly files.
Windows sample stack trace:
System.UnauthorizedAccessException: Access to the path 'C:\foo.rnd' is denied.
at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode)
at Azure.Storage.Files.DataLake.DataLakeFileClient.UploadAsync(String path, PathHttpHeaders httpHeaders, DataLakeRequestConditions conditions, IProgress`1 progressHandler, StorageTransferOptions transferOptions, CancellationToken cancellationToken)
OSX sample stack trace:
System.UnauthorizedAccessException: Access to the path '/Users/johndoe/foo.bar' is denied.
---> System.IO.IOException: Operation not permitted
--- End of inner exception stack trace ---
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at Azure.Storage.Files.DataLake.DataLakeFileClient.UploadAsync(String path, PathHttpHeaders httpHeaders, DataLakeRequestConditions conditions, IProgress`1 progressHandler, StorageTransferOptions transferOptions, CancellationToken cancellationToken)
at Microsoft.Azure.DashCamUploader.DataLakeUploader.Upload(String file) in
To Reproduce
Call one of the DataLakeFileClient::UploadAsync
/DataLakeFileClient::Upload
overrides which accepts a file name (string
)
Workaround
Use one of the DataLakeFileClient::UploadAsync
/DataLakeFileClient::Upload
overrides accepting a Stream
, and pass it File.OpenRead(path)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Hi @ohadschn, thanks for the detailed bug report. I’ll work to get this fixed in our next release.
-Sean
Thank you for your feedback. Tagging and routing to the team best able to assist.