8000 Prevent `conda remove --all` from deleting non-environments by chenghlee · Pull Request #10086 · conda/conda · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Prevent conda remove --all from deleting non-environments #10086

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

Merged
merged 2 commits into from
Jul 20, 2020
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
5 changes: 4 additions & 1 deletion conda/cli/main_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import logging
from os.path import isfile, join
import sys

from .common import check_non_admin, specs_from_args
Expand All @@ -13,7 +14,7 @@
from ..core.link import PrefixSetup, UnlinkLinkTransaction
from ..core.prefix_data import PrefixData
from ..core.solve import Solver
from ..exceptions import CondaEnvironmentError, CondaValueError
from ..exceptions import CondaEnvironmentError, CondaValueError, DirectoryNotACondaEnvironmentError
from ..gateways.disk.delete import rm_rf, path_is_clean
from ..models.match_spec import MatchSpec
from ..exceptions import PackagesNotFoundError
Expand Down Expand Up @@ -54,6 +55,8 @@ def execute(args, parser):
if prefix == context.root_prefix:
raise CondaEnvironmentError('cannot remove root environment,\n'
' add -n NAME or -p PREFIX option')
if not isfile(join(prefix, 'conda-meta', 'history')):
raise DirectoryNotACondaEnvironmentError(prefix)
print("\nRemove all packages in environment %s:\n" % prefix, file=sys.stderr)

if 'package_names' in args:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2878,6 +2878,22 @@ def test_remove_empty_env(self):
run_command(Commands.CREATE, prefix)
run_command(Commands.REMOVE, prefix, '--all')

def test_remove_ignore_nonenv(self):
with tempdir() as test_root:
prefix = join(test_root, "not-an-env")
filename = join(prefix, "file.dat")

os.mkdir(prefix)
with open(filename, "wb") as empty:
pass

with pytest.raises(DirectoryNotACondaEnvironmentError):
run_command(Commands.REMOVE, prefix, "--all")

assert(exists(filename))
assert(exists(prefix))


@pytest.mark.skipif(True, reason="get the rest of Solve API worked out first")
@pytest.mark.integration
class PrivateEnvIntegrationTests(TestCase):
Expand Down
0