Skip to content

Commit

Permalink
Merge pull request #307 from Anaconda-Platform/flagged-readonly-2
Browse files Browse the repository at this point in the history
Allow .readonly flag in parent
  • Loading branch information
mcg1969 committed Jan 8, 2021
2 parents 7467407 + 2f53f50 commit bb3b2c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions anaconda_project/internal/conda_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ def clone(prefix, source, stdout_callback=None, stderr_callback=None):

cmd_list = ['create', '-p', prefix, '--clone', source]
_call_conda(cmd_list, stdout_callback=stdout_callback, stderr_callback=stderr_callback)
# If someone is using the .readonly flag-file approach, the clone command is going to copy
# that. So we need to remove it if we find it in the new, copied environment.
readonly_file = os.path.join(prefix, '.readonly')
if os.path.exists(readonly_file):
os.unlink(readonly_file)


def install(prefix, pkgs=None, channels=(), stdout_callback=None, stderr_callback=None):
Expand Down
8 changes: 5 additions & 3 deletions anaconda_project/internal/default_conda_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def _cache_directory(self, prefix):
def _test_writable_file(self, prefix):
return os.path.join(self._cache_directory(prefix), "status")

def _force_readonly_file(self, prefix):
def _force_readonly_file(self, prefix, parent=False):
if parent:
prefix = os.path.dirname(prefix)
return os.path.join(prefix, '.readonly')

def _timestamp_file(self, prefix, spec):
Expand Down Expand Up @@ -196,8 +198,8 @@ def _write_a_file(self, filename):
return False

def _is_environment_writable(self, prefix):
filename = self._force_readonly_file(prefix)
if os.path.exists(filename):
if (os.path.exists(self._force_readonly_file(prefix))
or os.path.exists(self._force_readonly_file(prefix, parent=True))):
return False
filename = self._test_writable_file(prefix)
return self._write_a_file(filename)
Expand Down

0 comments on commit bb3b2c5

Please sign in to comment.