Skip to content

Commit

Permalink
Fix the problem that the directory fails to move (Azure#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoxing-ms authored Jun 19, 2020
1 parent 0994adc commit 2e1e476
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/storage-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Release History
===============

0.2.11 (2020-06-04)
* Fix the bug for command `az storage blob directory move`

0.2.10 (2019-11-25)
++++++++++++++++
* Fix bugs for ADLS Gen2
Expand Down
5 changes: 5 additions & 0 deletions src/storage-preview/azext_storage_preview/operations/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import print_function

from urllib.parse import quote
from knack.util import CLIError
from knack.log import get_logger

Expand Down Expand Up @@ -177,6 +178,10 @@ def rename_directory(client, container_name, new_path, source_path,
The timeout parameter is expressed in seconds.
"""

# In order to find the required blob, `x-ms-rename-source` in header needs to encode the special character in URL.
source_path = quote(source_path)

marker = client.rename_path(container_name, new_path, source_path,
mode=mode, lease_id=lease_id, source_lease_id=source_lease_id,
source_if_modified_since=source_if_modified_since,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def test_storage_adls_blob_directory_move(self, resource_group, test_dir):
'sc': storage_account,
'rg': resource_group
})
self.cmd('storage account create -n {sc} -g {rg} -l centralus --kind StorageV2 --hierarchical-namespace true')
self.cmd('storage account create -n {sc} -g {rg} -l centralus --kind StorageV2 --hierarchical-namespace true '
' --https-only')
account_info = self.get_account_info(resource_group, storage_account)
container = self.create_container(account_info)
directory = 'dir'
Expand All @@ -120,6 +121,27 @@ def test_storage_adls_blob_directory_move(self, resource_group, test_dir):
self.storage_cmd('storage blob directory list -c {} -d {}', account_info, container, des_directory) \
.assert_with_checks(JMESPathCheck('length(@)', 11))

# Test directory name contains Spaces
contain_space_dir = 'test move directory'
# Move directory to contain_space_dir
self.storage_cmd('storage blob directory exists -c "{}" -d "{}"', account_info, container, des_directory) \
.assert_with_checks(JMESPathCheck('exists', True))
self.storage_cmd('storage blob directory exists -c "{}" -d "{}"', account_info, container, contain_space_dir) \
.assert_with_checks(JMESPathCheck('exists', False))
self.storage_cmd('storage blob directory move -c "{}" -d "{}" -s "{}"', account_info, container,
contain_space_dir, des_directory)
self.storage_cmd('storage blob directory exists -c "{}" -d "{}"', account_info, container, contain_space_dir) \
.assert_with_checks(JMESPathCheck('exists', True))
self.storage_cmd('storage blob directory exists -c "{}" -d "{}"', account_info, container, des_directory) \
.assert_with_checks(JMESPathCheck('exists', False))
# Move contain_space_dir back to directory
self.storage_cmd('storage blob directory move -c "{}" -d "{}" -s "{}"', account_info, container,
des_directory, contain_space_dir)
self.storage_cmd('storage blob directory exists -c "{}" -d "{}"', account_info, container, des_directory) \
.assert_with_checks(JMESPathCheck('exists', True))
self.storage_cmd('storage blob directory exists -c "{}" -d "{}"', account_info, container, contain_space_dir) \
.assert_with_checks(JMESPathCheck('exists', False))

# Move from a directory to a existing empty directory
directory2 = 'dir2'
self.storage_cmd('storage blob directory create -c {} -d {}', account_info, container, directory2)
Expand Down

0 comments on commit 2e1e476

Please sign in to comment.