Empty file or existing file won't be created/overwritten if the blob to be downloaded doesn't exist. (#3910)

This commit is contained in:
JinmingHu 2022-08-30 12:52:47 +08:00 committed by GitHub
parent 221a175099
commit 3756ae66a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 383 additions and 4 deletions

View File

@ -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)

View File

@ -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;
@ -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();

View File

@ -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());

View File

@ -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"
}
]
}

View File

@ -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

View File

@ -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)
{
{

View File

@ -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"
}
]
}

View File

@ -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)

View File

@ -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;
@ -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();

View File

@ -0,0 +1,169 @@
{
"networkCallRecords": [
{
"Headers": {
"user-agent": "azsdk-cpp-storage-files-shares/12.3.0-beta.1 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "6edfef4b-894f-4b59-40b3-8207f3ba4b4c",
"x-ms-version": "2021-06-08"
},
"Method": "PUT",
"Response": {
"BODY": "",
"REASON_PHRASE": "Created",
"STATUS_CODE": "201",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:40:09 GMT",
"etag": "\"0x8DA89AAD8AFFAF7\"",
"last-modified": "Mon, 29 Aug 2022 10:40:09 GMT",
"server": "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "6edfef4b-894f-4b59-40b3-8207f3ba4b4c",
"x-ms-request-id": "2c18eab3-401a-0078-5593-bb793a000000",
"x-ms-version": "2021-06-08"
},
"Url": "https://REDACTED.file.core.windows.net/filesharefileclienttestdownloadnonexistingtofile?restype=share"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-files-shares/12.3.0-beta.1 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "9ad657f0-6082-467c-4455-e9b75aa48941",
"x-ms-version": "2021-06-08"
},
"Method": "PUT",
"Response": {
"BODY": "",
"REASON_PHRASE": "Created",
"STATUS_CODE": "201",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:40:09 GMT",
"etag": "\"0x8DA89AAD8E06427\"",
"last-modified": "Mon, 29 Aug 2022 10:40:10 GMT",
"server": "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "9ad657f0-6082-467c-4455-e9b75aa48941",
"x-ms-file-attributes": "Directory",
"x-ms-file-change-time": "2022-08-29T10:40:10.2376487Z",
"x-ms-file-creation-time": "2022-08-29T10:40:10.2376487Z",
"x-ms-file-id": "13835128424026341376",
"x-ms-file-last-write-time": "2022-08-29T10:40:10.2376487Z",
"x-ms-file-parent-id": "0",
"x-ms-file-permission-key": "14799134079974362488*11941910252504767217",
"x-ms-request-id": "2c18eaca-401a-0078-6993-bb793a000000",
"x-ms-request-server-encrypted": "true",
"x-ms-version": "2021-06-08"
},
"Url": "https://REDACTED.file.core.windows.net/filesharefileclienttestdownloadnonexistingtofile/DownloadNonExistingToFilebase?restype=directory"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-files-shares/12.3.0-beta.1 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "f062410c-713f-470d-426f-990d3f03ff74",
"x-ms-version": "2021-06-08"
},
"Method": "PUT",
"Response": {
"BODY": "",
"REASON_PHRASE": "Created",
"STATUS_CODE": "201",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:40:10 GMT",
"etag": "\"0x8DA89AAD90D6101\"",
"last-modified": "Mon, 29 Aug 2022 10:40:10 GMT",
"server": "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "f062410c-713f-470d-426f-990d3f03ff74",
"x-ms-file-attributes": "Archive",
"x-ms-file-change-time": "2022-08-29T10:40:10.5324801Z",
"x-ms-file-creation-time": "2022-08-29T10:40:10.5324801Z",
"x-ms-file-id": "11529285414812647424",
"x-ms-file-last-write-time": "2022-08-29T10:40:10.5324801Z",
"x-ms-file-parent-id": "13835128424026341376",
"x-ms-file-permission-key": "944304957241799295*11941910252504767217",
"x-ms-request-id": "2c18eade-401a-0078-7c93-bb793a000000",
"x-ms-request-server-encrypted": "true",
"x-ms-version": "2021-06-08"
},
"Url": "https://REDACTED.file.core.windows.net/filesharefileclienttestdownloadnonexistingtofile/DownloadNonExistingToFilebase/DownloadNonExistingToFilebasefile"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-files-shares/12.3.0-beta.1 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "92d10ba7-5cce-4bf5-4ec3-f2242990b412",
"x-ms-version": "2021-06-08"
},
"Method": "GET",
"Response": {
"BODY": "<?xml version=\"1.0\" encoding=\"utf-8\"?><Error><Code>ResourceNotFound</Code><Message>The specified resource does not exist.\nRequestId:2c18eae2-401a-0078-8093-bb793a000000\nTime:2022-08-29T10:40:10.7988819Z</Message></Error>",
"REASON_PHRASE": "The specified resource does not exist.",
"STATUS_CODE": "404",
"content-length": "223",
"content-type": "application/xml",
"date": "Mon, 29 Aug 2022 10:40:10 GMT",
"server": "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"vary": "Origin",
"x-ms-client-request-id": "92d10ba7-5cce-4bf5-4ec3-f2242990b412",
"x-ms-error-code": "ResourceNotFound",
"x-ms-request-id": "2c18eae2-401a-0078-8093-bb793a000000",
"x-ms-version": "2021-06-08"
},
"Url": "https://REDACTED.file.core.windows.net/filesharefileclienttestdownloadnonexistingtofile/DownloadNonExistingToFilebase/DownloadNonExistingToFile"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-files-shares/12.3.0-beta.1 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "b9b912c5-3a77-4008-4ef4-daedeafc4f8a",
"x-ms-version": "2021-06-08"
},
"Method": "DELETE",
"Response": {
"BODY": "",
"REASON_PHRASE": "Accepted",
"STATUS_CODE": "202",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:40:10 GMT",
"server": "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "b9b912c5-3a77-4008-4ef4-daedeafc4f8a",
"x-ms-request-id": "2c18eae5-401a-0078-0393-bb793a000000",
"x-ms-version": "2021-06-08"
},
"Url": "https://REDACTED.file.core.windows.net/filesharefileclienttestdownloadnonexistingtofile?restype=share"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-files-shares/12.3.0-beta.1 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "3996664f-a9c3-4e5d-5cd7-25f8cfa58215",
"x-ms-version": "2021-06-08"
},
"Method": "DELETE",
"Response": {
"BODY": "",
"REASON_PHRASE": "Accepted",
"STATUS_CODE": "202",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:40:10 GMT",
"server": "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "3996664f-a9c3-4e5d-5cd7-25f8cfa58215",
"x-ms-request-id": "2c18eae9-401a-0078-0693-bb793a000000",
"x-ms-version": "2021-06-08"
},
"Url": "https://REDACTED.file.core.windows.net/filesharefileclienttestdownloadnonexistingtofile?restype=share"
},
{
"Headers": {
"user-agent": "azsdk-cpp-storage-files-shares/12.3.0-beta.1 (Windows 10 Enterprise 6.3 19044 19041.1.amd64fre.vb_release.191206-1406)",
"x-ms-client-request-id": "b4aa936b-5d9e-445c-4a86-914acb77413b",
"x-ms-version": "2021-06-08"
},
"Method": "DELETE",
"Response": {
"BODY": "",
"REASON_PHRASE": "Accepted",
"STATUS_CODE": "202",
"content-length": "0",
"date": "Mon, 29 Aug 2022 10:40:11 GMT",
"server": "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-client-request-id": "b4aa936b-5d9e-445c-4a86-914acb77413b",
"x-ms-request-id": "2c18eaec-401a-0078-0893-bb793a000000",
"x-ms-version": "2021-06-08"
},
"Url": "https://REDACTED.file.core.windows.net/filesharefileclienttestdownloadnonexistingtofile?restype=share"
}
]
}

View File

@ -111,6 +111,15 @@ namespace Azure { namespace Storage { namespace Test {
EXPECT_NO_THROW(fileClient.DownloadTo(buff.data(), 0));
}
TEST_F(FileShareFileClientTest, DownloadNonExistingToFile)
{
const auto testName(GetTestName());
auto fileClient = m_fileShareDirectoryClient->GetFileClient(m_testName);
EXPECT_THROW(fileClient.DownloadTo(testName), StorageException);
EXPECT_THROW(ReadFile(testName), std::runtime_error);
}
TEST_F(FileShareFileClientTest, FileMetadata)
{
auto metadata1 = GetMetadata();