Skip to content

Commit

Permalink
Empty file or existing file won't be created/overwritten if the blob …
Browse files Browse the repository at this point in the history
…to be downloaded doesn't exist. (#3910)
  • Loading branch information
Jinming-Hu authored Aug 30, 2022
1 parent 221a175 commit 3756ae6
Show file tree
Hide file tree
Showing 11 changed files with 383 additions and 4 deletions.
2 changes: 2 additions & 0 deletions sdk/storage/azure-storage-blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Empty file or existing file won't be created/overwritten if the blob to be downloaded doesn't exist.

### Other Changes

## 12.6.0-beta.1 (2022-08-09)
Expand Down
3 changes: 1 addition & 2 deletions sdk/storage/azure-storage-blobs/src/blob_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,6 @@ namespace Azure { namespace Storage { namespace Blobs {
firstChunkOptions.Range.Value().Length = firstChunkLength;
}

_internal::FileWriter fileWriter(fileName);

auto firstChunk = Download(firstChunkOptions, context);
const Azure::ETag eTag = firstChunk.Value.Details.ETag;

Expand Down Expand Up @@ -461,6 +459,7 @@ namespace Azure { namespace Storage { namespace Blobs {
}
};

_internal::FileWriter fileWriter(fileName);
bodyStreamToFile(*(firstChunk.Value.BodyStream), fileWriter, 0, firstChunkLength, context);
firstChunk.Value.BodyStream.reset();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,15 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_TRUE(exceptionCaught);
}

TEST_F(BlockBlobClientTest, DownloadNonExistingToFile)
{
const auto testName(GetTestName());
auto blockBlobClient = GetBlockBlobClient(testName);

EXPECT_THROW(blockBlobClient.DownloadTo(testName), StorageException);
EXPECT_THROW(ReadFile(testName), std::runtime_error);
}

TEST_F(BlockBlobClientTest, DeleteIfExists)
{
auto const testName(GetTestName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"networkCallRecords": [
{
"Headers": {
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "6a753b0a-bcac-4076-6909-4141c56901df",
"x-ms-version": "2021-04-10"
},
"Method": "PUT",
"Response": {
"BODY": "",
"REASON_PHRASE": "Created",
"STATUS_CODE": "201",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:41:39 GMT",
"etag": "\"0x8DA89AB0E7605FE\"",
"last-modified": "Mon, 29 Aug 2022 10:41:40 GMT",
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "6a753b0a-bcac-4076-6909-4141c56901df",
"x-ms-request-id": "0a7e509f-001e-0034-4d93-bbe90a000000",
"x-ms-version": "2021-04-10"
},
"Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestdownloadnonexistingtofile?restype=container"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "3b4bb7fa-3c30-4c2c-5fb9-693daa5a8fa2",
"x-ms-version": "2021-04-10"
},
"Method": "GET",
"Response": {
"BODY": "<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>BlobNotFound</Code><Message>The specified blob does not exist.\nRequestId:0a7e5112-001e-0034-2c93-bbe90a000000\nTime:2022-08-29T10:41:41.1529398Z</Message></Error>",
"REASON_PHRASE": "The specified blob does not exist.",
"STATUS_CODE": "404",
"content-length": "215",
"content-type": "application/xml",
"date": "Mon, 29 Aug 2022 10:41:40 GMT",
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"vary": "Origin",
"x-ms-client-request-id": "3b4bb7fa-3c30-4c2c-5fb9-693daa5a8fa2",
"x-ms-error-code": "BlobNotFound",
"x-ms-request-id": "0a7e5112-001e-0034-2c93-bbe90a000000",
"x-ms-version": "2021-04-10"
},
"Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestdownloadnonexistingtofile/DownloadNonExistingToFile"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "fbed990d-4365-423a-718f-b1d64df6aa49",
"x-ms-version": "2021-04-10"
},
"Method": "DELETE",
"Response": {
"BODY": "",
"REASON_PHRASE": "Accepted",
"STATUS_CODE": "202",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:41:40 GMT",
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "fbed990d-4365-423a-718f-b1d64df6aa49",
"x-ms-request-id": "0a7e52c7-001e-0034-2993-bbe90a000000",
"x-ms-version": "2021-04-10"
},
"Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestdownloadnonexistingtofile?restype=container"
}
]
}
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-files-datalake/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bugs Fixed

- Fixed a bug where file/directory renaming cannot be authenticated with SAS.
- Empty file or existing file won't be created/overwritten if the file to be downloaded doesn't exist.

### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ namespace Azure { namespace Storage { namespace Test {
fileClient.Delete();
}

TEST_F(DataLakeFileClientTest, DownloadNonExistingToFile)
{
const auto testName(GetTestName());
auto fileClient = m_fileSystemClient->GetFileClient(testName);

EXPECT_THROW(fileClient.DownloadTo(testName), StorageException);
EXPECT_THROW(ReadFile(testName), std::runtime_error);
}

TEST_F(DataLakeFileClientTest, ScheduleForDeletion)
{
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"networkCallRecords": [
{
"Headers": {
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "22f683cd-fbdf-4223-51dd-a86271428dfc",
"x-ms-version": "2021-04-10"
},
"Method": "PUT",
"Response": {
"BODY": "",
"REASON_PHRASE": "Created",
"STATUS_CODE": "201",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:40:59 GMT",
"etag": "\"0x8DA89AAF65783FA\"",
"last-modified": "Mon, 29 Aug 2022 10:40:59 GMT",
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "22f683cd-fbdf-4223-51dd-a86271428dfc",
"x-ms-request-id": "30e6f346-101e-0047-3093-bb26fb000000",
"x-ms-version": "2021-04-10"
},
"Url": "https://REDACTED.blob.core.windows.net/datalakefileclienttestdownloadnonexistingtofile?restype=container"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-files-datalake/12.4.0-beta.1 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "88ef55a1-2b5f-41a6-74eb-54a5bdfe93cf",
"x-ms-version": "2020-02-10"
},
"Method": "PUT",
"Response": {
"BODY": "",
"REASON_PHRASE": "Created",
"STATUS_CODE": "201",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:41:00 GMT",
"etag": "\"0x8DA89AAF74A9F21\"",
"last-modified": "Mon, 29 Aug 2022 10:41:01 GMT",
"server": "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "88ef55a1-2b5f-41a6-74eb-54a5bdfe93cf",
"x-ms-request-id": "774068d3-e01f-0021-5e93-bb69db000000",
"x-ms-request-server-encrypted": "true",
"x-ms-version": "2020-02-10"
},
"Url": "https://REDACTED.dfs.core.windows.net/datalakefileclienttestdownloadnonexistingtofile/datalakefileclienttestdownloadnonexistingtofile?resource=file"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "b096b2d7-898d-4e0b-4595-0d12d95f44cb",
"x-ms-version": "2021-04-10"
},
"Method": "GET",
"Response": {
"BODY": "<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>BlobNotFound</Code><Message>The specified blob does not exist.\nRequestId:30e6f409-101e-0047-5193-bb26fb000000\nTime:2022-08-29T10:41:01.6071578Z</Message></Error>",
"REASON_PHRASE": "The specified blob does not exist.",
"STATUS_CODE": "404",
"content-length": "215",
"content-type": "application/xml",
"date": "Mon, 29 Aug 2022 10:41:01 GMT",
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "b096b2d7-898d-4e0b-4595-0d12d95f44cb",
"x-ms-error-code": "BlobNotFound",
"x-ms-request-id": "30e6f409-101e-0047-5193-bb26fb000000",
"x-ms-version": "2021-04-10"
},
"Url": "https://REDACTED.blob.core.windows.net/datalakefileclienttestdownloadnonexistingtofile/DownloadNonExistingToFile"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-files-datalake/12.4.0-beta.1 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "b55f5684-ae63-4d44-6556-b675337f7d74",
"x-ms-version": "2020-02-10"
},
"Method": "DELETE",
"Response": {
"BODY": "",
"REASON_PHRASE": "OK",
"STATUS_CODE": "200",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:41:01 GMT",
"server": "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "b55f5684-ae63-4d44-6556-b675337f7d74",
"x-ms-request-id": "7740698c-e01f-0021-1693-bb69db000000",
"x-ms-version": "2020-02-10"
},
"Url": "https://REDACTED.dfs.core.windows.net/datalakefileclienttestdownloadnonexistingtofile/datalakefileclienttestdownloadnonexistingtofile"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "6dae38d5-428b-49c8-6de2-bfea67acb620",
"x-ms-version": "2021-04-10"
},
"Method": "DELETE",
"Response": {
"BODY": "",
"REASON_PHRASE": "Accepted",
"STATUS_CODE": "202",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:41:01 GMT",
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "6dae38d5-428b-49c8-6de2-bfea67acb620",
"x-ms-request-id": "30e6f436-101e-0047-7c93-bb26fb000000",
"x-ms-version": "2021-04-10"
},
"Url": "https://REDACTED.blob.core.windows.net/datalakefileclienttestdownloadnonexistingtofile?restype=container"
}
]
}
2 changes: 2 additions & 0 deletions sdk/storage/azure-storage-files-shares/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

### Bugs Fixed

- Empty file or existing file won't be created/overwritten if the file to be downloaded doesn't exist.

### Other Changes

## 12.2.1 (2022-03-09)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,6 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
firstChunkOptions.Range.Value().Length = firstChunkLength;
}

_internal::FileWriter fileWriter(fileName);

auto firstChunk = Download(firstChunkOptions, context);
const Azure::ETag etag = firstChunk.Value.Details.ETag;

Expand Down Expand Up @@ -845,6 +843,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
}
};

_internal::FileWriter fileWriter(fileName);
bodyStreamToFile(*(firstChunk.Value.BodyStream), fileWriter, 0, firstChunkLength, context);
firstChunk.Value.BodyStream.reset();

Expand Down
Loading

0 comments on commit 3756ae6

Please sign in to comment.