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

Bug Fix Issue #4603 Access problem #4604

Merged
merged 10 commits into from Dec 7, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion mlflow/projects/docker.py
@@ -1,5 +1,6 @@
import logging
import os
import stat
import posixpath
import shutil
import tempfile
Expand Down Expand Up @@ -99,6 +100,30 @@ def _get_docker_image_uri(repository_uri, work_dir):
return repository_uri + version_string


def handle_readonly(func, path, exc_info):
"""
Clear the readonly bit and reattempt the removal.

References:
- https://bugs.python.org/issue19643
- https://bugs.python.org/issue43657
"""
exc_class, exc_instance = exc_info[:2]
should_reattempt = (
func in (os.unlink, os.rmdir)
and issubclass(exc_class, PermissionError)
and (
# Check whether the error code indicates "Permission Denied"
(os.name != "nt" and exc_instance.errno == 13)
or (os.name == "nt" and exc_instance.winerror == 5)
)
)
if not should_reattempt:
raise exc_instance
os.chmod(path, stat.S_IWRITE)
func(path)


def _create_docker_build_ctx(work_dir, dockerfile_contents):
"""
Creates build context tarfile containing Dockerfile and project code, returning path to tarfile
Expand All @@ -114,7 +139,7 @@ def _create_docker_build_ctx(work_dir, dockerfile_contents):
output_filename=result_path, source_dir=dst_path, archive_name=_PROJECT_TAR_ARCHIVE_NAME
)
finally:
shutil.rmtree(directory)
shutil.rmtree(directory, onerror=handle_readonly)
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you add a unit test to verify the handle_readonly works ?

Copy link
Member

Choose a reason for hiding this comment

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

Done!

return result_path


Expand Down