Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] az storage copy: Add parameter --follow-symlinks to support symlinks (#12037) #13589

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/azure-cli/azure/cli/command_modules/storage/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
c.argument('include_path', include_path_type)
c.argument('recursive', recursive_type)
c.argument('content_type', arg_group='Additional Flags', help="Specify content type of the file. ")
c.argument('follow_symlinks', arg_group='Additional Flags', action='store_true',
help='Follow symbolic links when uploading from local file system.')

with self.argument_context('storage blob copy') as c:
for item in ['destination', 'source']:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def storage_copy(cmd, source=None,
destination_share=None,
destination_file_path=None,
destination_local_path=None,
exclude_pattern=None, include_pattern=None, exclude_path=None, include_path=None):
exclude_pattern=None, include_pattern=None, exclude_path=None, include_path=None,
follow_symlinks=None):
def get_url_with_sas(source, account_name, container, blob, share, file_path, local_path):
import re
import os
Expand Down Expand Up @@ -106,6 +107,8 @@ def get_url_with_sas(source, account_name, container, blob, share, file_path, lo
flags.append('--exclude-path=' + exclude_path)
if content_type is not None:
flags.append('--content-type=' + content_type)
if follow_symlinks is not None:
flags.append('--follow-symlinks=true')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--follow-symlinks is enough, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For az storage copy, yes

azcopy.copy(full_source, full_destination, flags=flags)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,20 @@ def test_storage_azcopy_blob_account(self, resource_group, first_account, second
self.cmd('storage blob list -c {} --account-name {}'
.format(first_container, first_account), checks=JMESPathCheck('length(@)', 21))

# Upload a single file with a symlink
source_path = os.path.join(test_dir, 'symlink_source')
with open(source_path, 'w') as f:
f.write('This is a data source for symlink.')
symlink = os.path.join(test_dir, 'symlink')
# If the error of "WinError[1314]" occurred during execution in Windows environment,
# please try to execute azdev with administrator privileges
os.symlink(source_path, symlink)

self.cmd('storage copy --source-local-path "{}" --destination-account-name {} --destination-container {} '
'--follow-symlinks'.format(symlink, first_account, first_container))
self.cmd('storage blob list -c {} --account-name {}'
.format(first_container, first_account), checks=JMESPathCheck('length(@)', 22))

local_folder = self.create_temp_dir()
# Download a single file
self.cmd('storage copy --source-account-name {} --source-container {} --source-blob {} --destination-local-path "{}"'
Expand Down Expand Up @@ -384,7 +398,7 @@ def test_storage_azcopy_blob_account(self, resource_group, first_account, second
self.cmd('storage container list --account-name {}'
.format(second_account), checks=JMESPathCheck('length(@)', 2))
self.cmd('storage blob list -c {} --account-name {}'
.format(first_container, second_account), checks=JMESPathCheck('length(@)', 21))
.format(first_container, second_account), checks=JMESPathCheck('length(@)', 22))

@ResourceGroupPreparer()
@StorageAccountPreparer()
Expand Down