Skip to content

Commit 3756ae6

Browse files
authored
Empty file or existing file won't be created/overwritten if the blob to be downloaded doesn't exist. (#3910)
1 parent 221a175 commit 3756ae6

File tree

11 files changed

+383
-4
lines changed

11 files changed

+383
-4
lines changed

sdk/storage/azure-storage-blobs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
- Empty file or existing file won't be created/overwritten if the blob to be downloaded doesn't exist.
12+
1113
### Other Changes
1214

1315
## 12.6.0-beta.1 (2022-08-09)

sdk/storage/azure-storage-blobs/src/blob_client.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,6 @@ namespace Azure { namespace Storage { namespace Blobs {
419419
firstChunkOptions.Range.Value().Length = firstChunkLength;
420420
}
421421

422-
_internal::FileWriter fileWriter(fileName);
423-
424422
auto firstChunk = Download(firstChunkOptions, context);
425423
const Azure::ETag eTag = firstChunk.Value.Details.ETag;
426424

@@ -461,6 +459,7 @@ namespace Azure { namespace Storage { namespace Blobs {
461459
}
462460
};
463461

462+
_internal::FileWriter fileWriter(fileName);
464463
bodyStreamToFile(*(firstChunk.Value.BodyStream), fileWriter, 0, firstChunkLength, context);
465464
firstChunk.Value.BodyStream.reset();
466465

sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,15 @@ namespace Azure { namespace Storage { namespace Test {
13871387
EXPECT_TRUE(exceptionCaught);
13881388
}
13891389

1390+
TEST_F(BlockBlobClientTest, DownloadNonExistingToFile)
1391+
{
1392+
const auto testName(GetTestName());
1393+
auto blockBlobClient = GetBlockBlobClient(testName);
1394+
1395+
EXPECT_THROW(blockBlobClient.DownloadTo(testName), StorageException);
1396+
EXPECT_THROW(ReadFile(testName), std::runtime_error);
1397+
}
1398+
13901399
TEST_F(BlockBlobClientTest, DeleteIfExists)
13911400
{
13921401
auto const testName(GetTestName());
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"networkCallRecords": [
3+
{
4+
"Headers": {
5+
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
6+
"x-ms-client-request-id": "6a753b0a-bcac-4076-6909-4141c56901df",
7+
"x-ms-version": "2021-04-10"
8+
},
9+
"Method": "PUT",
10+
"Response": {
11+
"BODY": "",
12+
"REASON_PHRASE": "Created",
13+
"STATUS_CODE": "201",
14+
"content-length": "0",
15+
"date": "Mon, 29 Aug 2022 10:41:39 GMT",
16+
"etag": "\"0x8DA89AB0E7605FE\"",
17+
"last-modified": "Mon, 29 Aug 2022 10:41:40 GMT",
18+
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
19+
"x-ms-client-request-id": "6a753b0a-bcac-4076-6909-4141c56901df",
20+
"x-ms-request-id": "0a7e509f-001e-0034-4d93-bbe90a000000",
21+
"x-ms-version": "2021-04-10"
22+
},
23+
"Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestdownloadnonexistingtofile?restype=container"
24+
},
25+
{
26+
"Headers": {
27+
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
28+
"x-ms-client-request-id": "3b4bb7fa-3c30-4c2c-5fb9-693daa5a8fa2",
29+
"x-ms-version": "2021-04-10"
30+
},
31+
"Method": "GET",
32+
"Response": {
33+
"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>",
34+
"REASON_PHRASE": "The specified blob does not exist.",
35+
"STATUS_CODE": "404",
36+
"content-length": "215",
37+
"content-type": "application/xml",
38+
"date": "Mon, 29 Aug 2022 10:41:40 GMT",
39+
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
40+
"vary": "Origin",
41+
"x-ms-client-request-id": "3b4bb7fa-3c30-4c2c-5fb9-693daa5a8fa2",
42+
"x-ms-error-code": "BlobNotFound",
43+
"x-ms-request-id": "0a7e5112-001e-0034-2c93-bbe90a000000",
44+
"x-ms-version": "2021-04-10"
45+
},
46+
"Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestdownloadnonexistingtofile/DownloadNonExistingToFile"
47+
},
48+
{
49+
"Headers": {
50+
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
51+
"x-ms-client-request-id": "fbed990d-4365-423a-718f-b1d64df6aa49",
52+
"x-ms-version": "2021-04-10"
53+
},
54+
"Method": "DELETE",
55+
"Response": {
56+
"BODY": "",
57+
"REASON_PHRASE": "Accepted",
58+
"STATUS_CODE": "202",
59+
"content-length": "0",
60+
"date": "Mon, 29 Aug 2022 10:41:40 GMT",
61+
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
62+
"x-ms-client-request-id": "fbed990d-4365-423a-718f-b1d64df6aa49",
63+
"x-ms-request-id": "0a7e52c7-001e-0034-2993-bbe90a000000",
64+
"x-ms-version": "2021-04-10"
65+
},
66+
"Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestdownloadnonexistingtofile?restype=container"
67+
}
68+
]
69+
}

sdk/storage/azure-storage-files-datalake/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Bugs Fixed
1010

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

1314
### Other Changes
1415

sdk/storage/azure-storage-files-datalake/test/ut/datalake_file_client_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,15 @@ namespace Azure { namespace Storage { namespace Test {
349349
fileClient.Delete();
350350
}
351351

352+
TEST_F(DataLakeFileClientTest, DownloadNonExistingToFile)
353+
{
354+
const auto testName(GetTestName());
355+
auto fileClient = m_fileSystemClient->GetFileClient(testName);
356+
357+
EXPECT_THROW(fileClient.DownloadTo(testName), StorageException);
358+
EXPECT_THROW(ReadFile(testName), std::runtime_error);
359+
}
360+
352361
TEST_F(DataLakeFileClientTest, ScheduleForDeletion)
353362
{
354363
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"networkCallRecords": [
3+
{
4+
"Headers": {
5+
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
6+
"x-ms-client-request-id": "22f683cd-fbdf-4223-51dd-a86271428dfc",
7+
"x-ms-version": "2021-04-10"
8+
},
9+
"Method": "PUT",
10+
"Response": {
11+
"BODY": "",
12+
"REASON_PHRASE": "Created",
13+
"STATUS_CODE": "201",
14+
"content-length": "0",
15+
"date": "Mon, 29 Aug 2022 10:40:59 GMT",
16+
"etag": "\"0x8DA89AAF65783FA\"",
17+
"last-modified": "Mon, 29 Aug 2022 10:40:59 GMT",
18+
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
19+
"x-ms-client-request-id": "22f683cd-fbdf-4223-51dd-a86271428dfc",
20+
"x-ms-request-id": "30e6f346-101e-0047-3093-bb26fb000000",
21+
"x-ms-version": "2021-04-10"
22+
},
23+
"Url": "https://REDACTED.blob.core.windows.net/datalakefileclienttestdownloadnonexistingtofile?restype=container"
24+
},
25+
{
26+
"Headers": {
27+
"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)",
28+
"x-ms-client-request-id": "88ef55a1-2b5f-41a6-74eb-54a5bdfe93cf",
29+
"x-ms-version": "2020-02-10"
30+
},
31+
"Method": "PUT",
32+
"Response": {
33+
"BODY": "",
34+
"REASON_PHRASE": "Created",
35+
"STATUS_CODE": "201",
36+
"content-length": "0",
37+
"date": "Mon, 29 Aug 2022 10:41:00 GMT",
38+
"etag": "\"0x8DA89AAF74A9F21\"",
39+
"last-modified": "Mon, 29 Aug 2022 10:41:01 GMT",
40+
"server": "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0",
41+
"x-ms-client-request-id": "88ef55a1-2b5f-41a6-74eb-54a5bdfe93cf",
42+
"x-ms-request-id": "774068d3-e01f-0021-5e93-bb69db000000",
43+
"x-ms-request-server-encrypted": "true",
44+
"x-ms-version": "2020-02-10"
45+
},
46+
"Url": "https://REDACTED.dfs.core.windows.net/datalakefileclienttestdownloadnonexistingtofile/datalakefileclienttestdownloadnonexistingtofile?resource=file"
47+
},
48+
{
49+
"Headers": {
50+
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
51+
"x-ms-client-request-id": "b096b2d7-898d-4e0b-4595-0d12d95f44cb",
52+
"x-ms-version": "2021-04-10"
53+
},
54+
"Method": "GET",
55+
"Response": {
56+
"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>",
57+
"REASON_PHRASE": "The specified blob does not exist.",
58+
"STATUS_CODE": "404",
59+
"content-length": "215",
60+
"content-type": "application/xml",
61+
"date": "Mon, 29 Aug 2022 10:41:01 GMT",
62+
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
63+
"x-ms-client-request-id": "b096b2d7-898d-4e0b-4595-0d12d95f44cb",
64+
"x-ms-error-code": "BlobNotFound",
65+
"x-ms-request-id": "30e6f409-101e-0047-5193-bb26fb000000",
66+
"x-ms-version": "2021-04-10"
67+
},
68+
"Url": "https://REDACTED.blob.core.windows.net/datalakefileclienttestdownloadnonexistingtofile/DownloadNonExistingToFile"
69+
},
70+
{
71+
"Headers": {
72+
"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)",
73+
"x-ms-client-request-id": "b55f5684-ae63-4d44-6556-b675337f7d74",
74+
"x-ms-version": "2020-02-10"
75+
},
76+
"Method": "DELETE",
77+
"Response": {
78+
"BODY": "",
79+
"REASON_PHRASE": "OK",
80+
"STATUS_CODE": "200",
81+
"content-length": "0",
82+
"date": "Mon, 29 Aug 2022 10:41:01 GMT",
83+
"server": "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0",
84+
"x-ms-client-request-id": "b55f5684-ae63-4d44-6556-b675337f7d74",
85+
"x-ms-request-id": "7740698c-e01f-0021-1693-bb69db000000",
86+
"x-ms-version": "2020-02-10"
87+
},
88+
"Url": "https://REDACTED.dfs.core.windows.net/datalakefileclienttestdownloadnonexistingtofile/datalakefileclienttestdownloadnonexistingtofile"
89+
},
90+
{
91+
"Headers": {
92+
"user-agent": "azsdk-cpp-storage-blobs/12.6.0-beta.2 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
93+
"x-ms-client-request-id": "6dae38d5-428b-49c8-6de2-bfea67acb620",
94+
"x-ms-version": "2021-04-10"
95+
},
96+
"Method": "DELETE",
97+
"Response": {
98+
"BODY": "",
99+
"REASON_PHRASE": "Accepted",
100+
"STATUS_CODE": "202",
101+
"content-length": "0",
102+
"date": "Mon, 29 Aug 2022 10:41:01 GMT",
103+
"server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
104+
"x-ms-client-request-id": "6dae38d5-428b-49c8-6de2-bfea67acb620",
105+
"x-ms-request-id": "30e6f436-101e-0047-7c93-bb26fb000000",
106+
"x-ms-version": "2021-04-10"
107+
},
108+
"Url": "https://REDACTED.blob.core.windows.net/datalakefileclienttestdownloadnonexistingtofile?restype=container"
109+
}
110+
]
111+
}

sdk/storage/azure-storage-files-shares/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
### Bugs Fixed
2020

21+
- Empty file or existing file won't be created/overwritten if the file to be downloaded doesn't exist.
22+
2123
### Other Changes
2224

2325
## 12.2.1 (2022-03-09)

sdk/storage/azure-storage-files-shares/src/share_file_client.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,6 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
801801
firstChunkOptions.Range.Value().Length = firstChunkLength;
802802
}
803803

804-
_internal::FileWriter fileWriter(fileName);
805-
806804
auto firstChunk = Download(firstChunkOptions, context);
807805
const Azure::ETag etag = firstChunk.Value.Details.ETag;
808806

@@ -845,6 +843,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
845843
}
846844
};
847845

846+
_internal::FileWriter fileWriter(fileName);
848847
bodyStreamToFile(*(firstChunk.Value.BodyStream), fileWriter, 0, firstChunkLength, context);
849848
firstChunk.Value.BodyStream.reset();
850849

0 commit comments

Comments
 (0)