From a10f3c6e159c34683dadd6c5d48eae98779afa5c Mon Sep 17 00:00:00 2001 From: "yishiwang@microsoft.com" Date: Tue, 11 Apr 2023 18:45:02 +0800 Subject: [PATCH] `az storage copy`: Stop granting `stat.S_IWUSR` permission for azcopy installation dir --- .../azure/cli/command_modules/storage/azcopy/util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py b/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py index afe475d522c..88d5b4cf6a0 100644 --- a/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py +++ b/src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py @@ -53,10 +53,13 @@ def install_azcopy(self, install_location): else: raise CLIError('Azcopy ({}) does not exist.'.format(self.system)) try: - os.chmod(install_dir, os.stat(install_dir).st_mode | stat.S_IWUSR) _urlretrieve(file_url, install_location) os.chmod(install_location, os.stat(install_location).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) + except PermissionError as err: + raise CLIError(f'Permission error while attempting to download azcopy to {install_dir}. ' + f'You could install the specified azcopy version {AZCOPY_VERSION} manually or ' + f'grant write permission and retry. ({err})') except IOError as err: raise CLIError('Connection error while attempting to download azcopy {}. You could also install the ' 'specified azcopy version to {} manually. ({})'.format(AZCOPY_VERSION, install_dir, err))