Skip to content
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
22 changes: 21 additions & 1 deletion package/cloudshell/iac/terraform/services/local_dir_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@
from cloudshell.iac.terraform.services.sandox_data import SandboxDataHandler


def handle_remove_readonly(func, path, exc_info):
"""
Error handler for ``shutil.rmtree``.

If the error is due to an access error (read only file)
it attempts to add write permission and then retries.

If the error is for another reason it re-raises the error.

Usage : ``shutil.rmtree(path, onerror=onerror)``
"""
import stat
# Is the error an access error?
if not os.access(path, os.W_OK):
os.chmod(path, stat.S_IWUSR)
func(path)
else:
raise


class LocalDir:
@staticmethod
def delete_local_temp_dir(sandbox_data_handler: SandboxDataHandler, tf_working_dir: str):
Expand All @@ -20,7 +40,7 @@ def delete_local_temp_dir(sandbox_data_handler: SandboxDataHandler, tf_working_d
tmp_folder_found = True
tf_path = Path(tf_path.parent.absolute())
tf_path_str = str(tf_path)
shutil.rmtree(tf_path_str)
shutil.rmtree(tf_path_str, onerror=handle_remove_readonly)
sandbox_data_handler.set_tf_working_dir("")

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion package/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ cloudshell-shell-core==5.0.5
requests==2.25.1
cloudshell-automation-api==2021.1.0.181140
retry==0.9.2
python-hcl2==2.0.1
python-hcl2==3.0.5
2 changes: 1 addition & 1 deletion package/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.2
1.2.3