We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`conda env remove --dry-run` actually deletes the env
## Current Behavior
Using the `--dry-run` flag doesn't do a dry-run at all.


### Steps to Reproduce
```
$ conda env list
# conda environments:
#
base                  *  /usr

$ conda create -n foo
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/eric/.conda/envs/foo



Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate foo
#
# To deactivate an active environment, use
#
#     $ conda deactivate

$ conda env list
# conda environments:
#
foo                      /home/eric/.conda/envs/foo
base                  *  /usr

~ $ conda env remove --dry-run -n foo

Remove all packages in environment /home/eric/.conda/envs/foo:

$ conda env list
# conda environments:
#
base                  *  /usr

$ 
```


## Expected Behavior
`--dry-run` is documented as `Only display what would have been done.`, but clearly that's not true :upside_down_face: 

The expected behaviour here is obviously that the environment is **not** removed :slightly_smiling_face: 


## Environment Information
<details open><summary><code>`conda info`</code></summary><p>

```
     active environment : None
            shell level : 0
       user config file : /home/eric/.condarc
 populated config files : /usr/share/conda/condarc.d/defaults.yaml
                          /home/eric/.condarc
          conda version : 4.8.2
    conda-build version : not installed
         python version : 3.8.5.final.0
       virtual packages : __glibc=2.31
       base environment : /usr  (read only)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /var/cache/conda/pkgs
                          /home/eric/.conda/pkgs
       envs directories : /home/eric/.conda/envs
                          /usr/envs
               platform : linux-64
             user-agent : conda/4.8.2 requests/2.22.0 CPython/3.8.5 Linux/5.8.6-201.fc32.x86_64 fedora/32 glibc/2.31
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
```
</p></details>


<details open><summary><code>`conda config --show-sources`</code></summary><p>

```
==> /usr/share/conda/condarc.d/defaults.yaml <==
pkgs_dirs:
  - /var/cache/conda/pkgs
  - ~/.conda/pkgs

==> /home/eric/.condarc <==
channels:
  - conda-forge
  - defaults
```
</p></details>


<details><summary><code>`conda list --show-channel-urls`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda list --show-channel-urls' -->

```
EnvironmentLocationNotFound: Not a conda environment: /usr
```
(I expect that might also be a bug, conda shouldn't crash like that here.)
</p></details>


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `conda/cli/main_remove.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2012 Anaconda, Inc
3 # SPDX-License-Identifier: BSD-3-Clause
4 from __future__ import absolute_import, division, print_function, unicode_literals
5 
6 import logging
7 from os.path import isfile, join
8 import sys
9 
10 from .common import check_non_admin, specs_from_args
11 from .install import handle_txn
12 from ..base.context import context
13 from ..core.envs_manager import unregister_env
14 from ..core.link import PrefixSetup, UnlinkLinkTransaction
15 from ..core.prefix_data import PrefixData
16 from ..core.solve import Solver
17 from ..exceptions import CondaEnvironmentError, CondaValueError, DirectoryNotACondaEnvironmentError
18 from ..gateways.disk.delete import rm_rf, path_is_clean
19 from ..models.match_spec import MatchSpec
20 from ..exceptions import PackagesNotFoundError
21 
22 log = logging.getLogger(__name__)
23 
24 
25 def execute(args, parser):
26 
27     if not (args.all or args.package_names):
28         raise CondaValueError('no package names supplied,\n'
29                               '       try "conda remove -h" for more details')
30 
31     prefix = context.target_prefix
32     check_non_admin()
33 
34     if args.all and prefix == context.default_prefix:
35         msg = "cannot remove current environment. deactivate and run conda remove again"
36         raise CondaEnvironmentError(msg)
37 
38     if args.all and path_is_clean(prefix):
39         # full environment removal was requested, but environment doesn't exist anyway
40 
41         # .. but you know what? If you call `conda remove --all` you'd expect the dir
42         # not to exist afterwards, would you not? If not (fine, I can see the argument
43         # about deleting people's work in envs being a very bad thing indeed), but if
44         # being careful is the goal it would still be nice if after `conda remove --all`
45         # to be able to do `conda create` on the same environment name.
46         #
47         # try:
48         #     rm_rf(prefix, clean_empty_parents=True)
49         # except:
50         #     log.warning("Failed rm_rf() of partially existent env {}".format(prefix))
51 
52         return 0
53 
54     if args.all:
55         if prefix == context.root_prefix:
56             raise CondaEnvironmentError('cannot remove root environment,\n'
57                                         '       add -n NAME or -p PREFIX option')
58         if not isfile(join(prefix, 'conda-meta', 'history')):
59             raise DirectoryNotACondaEnvironmentError(prefix)
60         print("\nRemove all packages in environment %s:\n" % prefix, file=sys.stderr)
61 
62         if 'package_names' in args:
63             stp = PrefixSetup(
64                 target_prefix=prefix,
65                 unlink_precs=tuple(PrefixData(prefix).iter_records()),
66                 link_precs=(),
67                 remove_specs=(),
68                 update_specs=(),
69                 neutered_specs={},
70             )
71             txn = UnlinkLinkTransaction(stp)
72             try:
73                 handle_txn(txn, prefix, args, False, True)
74             except PackagesNotFoundError:
75                 print("No packages found in %s. Continuing environment removal" % prefix)
76         rm_rf(prefix, clean_empty_parents=True)
77         unregister_env(prefix)
78 
79         return
80 
81     else:
82         if args.features:
83             specs = tuple(MatchSpec(track_features=f) for f in set(args.package_names))
84         else:
85             specs = specs_from_args(args.package_names)
86         channel_urls = ()
87         subdirs = ()
88         solver = Solver(prefix, channel_urls, subdirs, specs_to_remove=specs)
89         txn = solver.solve_for_transaction()
90         handle_txn(txn, prefix, args, False, True)
91 
92     # Keep this code for dev reference until private envs can be re-enabled in
93     # Solver.solve_for_transaction
94 
95     # specs = None
96     # if args.features:
97     #     specs = [MatchSpec(track_features=f) for f in set(args.package_names)]
98     #     actions = remove_actions(prefix, specs, index, pinned=not context.ignore_pinned)
99     #     actions['ACTION'] = 'REMOVE_FEATURE'
100     #     action_groups = (actions, index),
101     # elif args.all:
102     #     if prefix == context.root_prefix:
103     #         raise CondaEnvironmentError('cannot remove root environment,\n'
104     #                                     '       add -n NAME or -p PREFIX option')
105     #     actions = defaultdict(list)
106     #     actions[PREFIX] = prefix
107     #     for dist in sorted(iterkeys(index)):
108     #         add_unlink(actions, dist)
109     #     actions['ACTION'] = 'REMOVE_ALL'
110     #     action_groups = (actions, index),
111     # elif prefix == context.root_prefix and not context.prefix_specified:
112     #     from ..core.envs_manager import EnvsDirectory
113     #     ed = EnvsDirectory(join(context.root_prefix, 'envs'))
114     #     get_env = lambda s: ed.get_registered_preferred_env(MatchSpec(s).name)
115     #     specs = specs_from_args(args.package_names)
116     #     env_spec_map = groupby(get_env, specs)
117     #     action_groups = []
118     #     for env_name, spcs in iteritems(env_spec_map):
119     #         pfx = ed.to_prefix(env_name)
120     #         r = get_resolve_object(index.copy(), pfx)
121     #         specs_to_remove = tuple(MatchSpec(s) for s in spcs)
122     #         prune = pfx != context.root_prefix
123     #         dists_for_unlinking, dists_for_linking = solve_for_actions(
124     #             pfx, r,
125     #             specs_to_remove=specs_to_remove, prune=prune,
126     #         )
127     #         actions = get_blank_actions(pfx)
128     #         actions['UNLINK'].extend(dists_for_unlinking)
129     #         actions['LINK'].extend(dists_for_linking)
130     #         actions['SPECS'].extend(text_type(s) for s in specs_to_remove)
131     #         actions['ACTION'] = 'REMOVE'
132     #         action_groups.append((actions, r.index))
133     #     action_groups = tuple(action_groups)
134     # else:
135     #     specs = specs_from_args(args.package_names)
136     #     if sys.prefix == abspath(prefix) and names_in_specs(ROOT_NO_RM, specs) and not args.force:  # NOQA
137     #         raise CondaEnvironmentError('cannot remove %s from root environment' %
138     #                                     ', '.join(ROOT_NO_RM))
139     #     action_groups = (remove_actions(prefix, list(specs), index=index,
140     #                                     force=args.force,
141     #                                     pinned=not context.ignore_pinned,
142     #                                     ), index),
143     #
144     #
145     # delete_trash()
146     # if any(nothing_to_do(x[0]) for x in action_groups):
147     #     if args.all:
148     #         print("\nRemove all packages in environment %s:\n" % prefix, file=sys.stderr)
149     #         if not context.json:
150     #             confirm_yn(args)
151     #         rm_rf(prefix)
152     #
153     #         if context.json:
154     #             stdout_json({
155     #                 'success': True,
156     #                 'actions': tuple(x[0] for x in action_groups)
157     #             })
158     #         return
159     #
160     #     pkg = str(args.package_names).replace("['", "")
161     #     pkg = pkg.replace("']", "")
162     #
163     #     error_message = "No packages named '%s' found to remove from environment." % pkg
164     #     raise PackageNotFoundError(error_message)
165     # if not context.json:
166     #     for actions, ndx in action_groups:
167     #         print()
168     #         print("Package plan for package removal in environment %s:" % actions["PREFIX"])
169     #         display_actions(actions, ndx)
170     # elif context.json and args.dry_run:
171     #     stdout_json({
172     #         'success': True,
173     #         'dry_run': True,
174     #         'actions': tuple(x[0] for x in action_groups),
175     #     })
176     #     return
177     #
178     # if not context.json:
179     #     confirm_yn(args)
180     #
181     # for actions, ndx in action_groups:
182     #     if context.json and not context.quiet:
183     #         with json_progress_bars():
184     #             execute_actions(actions, ndx, verbose=not context.quiet)
185     #     else:
186     #         execute_actions(actions, ndx, verbose=not context.quiet)
187     #
188     #     target_prefix = actions["PREFIX"]
189     #     if is_private_env_path(target_prefix) and linked_data(target_prefix) == {}:
190     #         rm_rf(target_prefix)
191     #
192     # if args.all:
193     #     rm_rf(prefix)
194     #
195     # if context.json:
196     #     stdout_json({
197     #         'success': True,
198     #         'actions': tuple(x[0] for x in action_groups),
199     #     })
200
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/conda/cli/main_remove.py b/conda/cli/main_remove.py
--- a/conda/cli/main_remove.py
+++ b/conda/cli/main_remove.py
@@ -73,8 +73,9 @@
                 handle_txn(txn, prefix, args, False, True)
             except PackagesNotFoundError:
                 print("No packages found in %s. Continuing environment removal" % prefix)
-        rm_rf(prefix, clean_empty_parents=True)
-        unregister_env(prefix)
+        if not context.dry_run:
+            rm_rf(prefix, clean_empty_parents=True)
+            unregister_env(prefix)
 
         return

{"golden_diff": "diff --git a/conda/cli/main_remove.py b/conda/cli/main_remove.py\n--- a/conda/cli/main_remove.py\n+++ b/conda/cli/main_remove.py\n@@ -73,8 +73,9 @@\n                 handle_txn(txn, prefix, args, False, True)\n             except PackagesNotFoundError:\n                 print(\"No packages found in %s. Continuing environment removal\" % prefix)\n-        rm_rf(prefix, clean_empty_parents=True)\n-        unregister_env(prefix)\n+        if not context.dry_run:\n+            rm_rf(prefix, clean_empty_parents=True)\n+            unregister_env(prefix)\n \n         return\n", "issue": "`conda env remove --dry-run` actually deletes the env\n## Current Behavior\r\nUsing the `--dry-run` flag doesn't do a dry-run at all.\r\n\r\n\r\n### Steps to Reproduce\r\n```\r\n$ conda env list\r\n# conda environments:\r\n#\r\nbase                  *  /usr\r\n\r\n$ conda create -n foo\r\nCollecting package metadata (current_repodata.json): done\r\nSolving environment: done\r\n\r\n## Package Plan ##\r\n\r\n  environment location: /home/eric/.conda/envs/foo\r\n\r\n\r\n\r\nProceed ([y]/n)? y\r\n\r\nPreparing transaction: done\r\nVerifying transaction: done\r\nExecuting transaction: done\r\n#\r\n# To activate this environment, use\r\n#\r\n#     $ conda activate foo\r\n#\r\n# To deactivate an active environment, use\r\n#\r\n#     $ conda deactivate\r\n\r\n$ conda env list\r\n# conda environments:\r\n#\r\nfoo                      /home/eric/.conda/envs/foo\r\nbase                  *  /usr\r\n\r\n~ $ conda env remove --dry-run -n foo\r\n\r\nRemove all packages in environment /home/eric/.conda/envs/foo:\r\n\r\n$ conda env list\r\n# conda environments:\r\n#\r\nbase                  *  /usr\r\n\r\n$ \r\n```\r\n\r\n\r\n## Expected Behavior\r\n`--dry-run` is documented as `Only display what would have been done.`, but clearly that's not true :upside_down_face: \r\n\r\nThe expected behaviour here is obviously that the environment is **not** removed :slightly_smiling_face: \r\n\r\n\r\n## Environment Information\r\n<details open><summary><code>`conda info`</code></summary><p>\r\n\r\n```\r\n     active environment : None\r\n            shell level : 0\r\n       user config file : /home/eric/.condarc\r\n populated config files : /usr/share/conda/condarc.d/defaults.yaml\r\n                          /home/eric/.condarc\r\n          conda version : 4.8.2\r\n    conda-build version : not installed\r\n         python version : 3.8.5.final.0\r\n       virtual packages : __glibc=2.31\r\n       base environment : /usr  (read only)\r\n           channel URLs : https://conda.anaconda.org/conda-forge/linux-64\r\n                          https://conda.anaconda.org/conda-forge/noarch\r\n                          https://repo.anaconda.com/pkgs/main/linux-64\r\n                          https://repo.anaconda.com/pkgs/main/noarch\r\n                          https://repo.anaconda.com/pkgs/r/linux-64\r\n                          https://repo.anaconda.com/pkgs/r/noarch\r\n          package cache : /var/cache/conda/pkgs\r\n                          /home/eric/.conda/pkgs\r\n       envs directories : /home/eric/.conda/envs\r\n                          /usr/envs\r\n               platform : linux-64\r\n             user-agent : conda/4.8.2 requests/2.22.0 CPython/3.8.5 Linux/5.8.6-201.fc32.x86_64 fedora/32 glibc/2.31\r\n                UID:GID : 1000:1000\r\n             netrc file : None\r\n           offline mode : False\r\n```\r\n</p></details>\r\n\r\n\r\n<details open><summary><code>`conda config --show-sources`</code></summary><p>\r\n\r\n```\r\n==> /usr/share/conda/condarc.d/defaults.yaml <==\r\npkgs_dirs:\r\n  - /var/cache/conda/pkgs\r\n  - ~/.conda/pkgs\r\n\r\n==> /home/eric/.condarc <==\r\nchannels:\r\n  - conda-forge\r\n  - defaults\r\n```\r\n</p></details>\r\n\r\n\r\n<details><summary><code>`conda list --show-channel-urls`</code></summary><p>\r\n<!-- between the ticks below, paste the output of 'conda list --show-channel-urls' -->\r\n\r\n```\r\nEnvironmentLocationNotFound: Not a conda environment: /usr\r\n```\r\n(I expect that might also be a bug, conda shouldn't crash like that here.)\r\n</p></details>\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright (C) 2012 Anaconda, Inc\n# SPDX-License-Identifier: BSD-3-Clause\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nimport logging\nfrom os.path import isfile, join\nimport sys\n\nfrom .common import check_non_admin, specs_from_args\nfrom .install import handle_txn\nfrom ..base.context import context\nfrom ..core.envs_manager import unregister_env\nfrom ..core.link import PrefixSetup, UnlinkLinkTransaction\nfrom ..core.prefix_data import PrefixData\nfrom ..core.solve import Solver\nfrom ..exceptions import CondaEnvironmentError, CondaValueError, DirectoryNotACondaEnvironmentError\nfrom ..gateways.disk.delete import rm_rf, path_is_clean\nfrom ..models.match_spec import MatchSpec\nfrom ..exceptions import PackagesNotFoundError\n\nlog = logging.getLogger(__name__)\n\n\ndef execute(args, parser):\n\n    if not (args.all or args.package_names):\n        raise CondaValueError('no package names supplied,\\n'\n                              '       try \"conda remove -h\" for more details')\n\n    prefix = context.target_prefix\n    check_non_admin()\n\n    if args.all and prefix == context.default_prefix:\n        msg = \"cannot remove current environment. deactivate and run conda remove again\"\n        raise CondaEnvironmentError(msg)\n\n    if args.all and path_is_clean(prefix):\n        # full environment removal was requested, but environment doesn't exist anyway\n\n        # .. but you know what? If you call `conda remove --all` you'd expect the dir\n        # not to exist afterwards, would you not? If not (fine, I can see the argument\n        # about deleting people's work in envs being a very bad thing indeed), but if\n        # being careful is the goal it would still be nice if after `conda remove --all`\n        # to be able to do `conda create` on the same environment name.\n        #\n        # try:\n        #     rm_rf(prefix, clean_empty_parents=True)\n        # except:\n        #     log.warning(\"Failed rm_rf() of partially existent env {}\".format(prefix))\n\n        return 0\n\n    if args.all:\n        if prefix == context.root_prefix:\n            raise CondaEnvironmentError('cannot remove root environment,\\n'\n                                        '       add -n NAME or -p PREFIX option')\n        if not isfile(join(prefix, 'conda-meta', 'history')):\n            raise DirectoryNotACondaEnvironmentError(prefix)\n        print(\"\\nRemove all packages in environment %s:\\n\" % prefix, file=sys.stderr)\n\n        if 'package_names' in args:\n            stp = PrefixSetup(\n                target_prefix=prefix,\n                unlink_precs=tuple(PrefixData(prefix).iter_records()),\n                link_precs=(),\n                remove_specs=(),\n                update_specs=(),\n                neutered_specs={},\n            )\n            txn = UnlinkLinkTransaction(stp)\n            try:\n                handle_txn(txn, prefix, args, False, True)\n            except PackagesNotFoundError:\n                print(\"No packages found in %s. Continuing environment removal\" % prefix)\n        rm_rf(prefix, clean_empty_parents=True)\n        unregister_env(prefix)\n\n        return\n\n    else:\n        if args.features:\n            specs = tuple(MatchSpec(track_features=f) for f in set(args.package_names))\n        else:\n            specs = specs_from_args(args.package_names)\n        channel_urls = ()\n        subdirs = ()\n        solver = Solver(prefix, channel_urls, subdirs, specs_to_remove=specs)\n        txn = solver.solve_for_transaction()\n        handle_txn(txn, prefix, args, False, True)\n\n    # Keep this code for dev reference until private envs can be re-enabled in\n    # Solver.solve_for_transaction\n\n    # specs = None\n    # if args.features:\n    #     specs = [MatchSpec(track_features=f) for f in set(args.package_names)]\n    #     actions = remove_actions(prefix, specs, index, pinned=not context.ignore_pinned)\n    #     actions['ACTION'] = 'REMOVE_FEATURE'\n    #     action_groups = (actions, index),\n    # elif args.all:\n    #     if prefix == context.root_prefix:\n    #         raise CondaEnvironmentError('cannot remove root environment,\\n'\n    #                                     '       add -n NAME or -p PREFIX option')\n    #     actions = defaultdict(list)\n    #     actions[PREFIX] = prefix\n    #     for dist in sorted(iterkeys(index)):\n    #         add_unlink(actions, dist)\n    #     actions['ACTION'] = 'REMOVE_ALL'\n    #     action_groups = (actions, index),\n    # elif prefix == context.root_prefix and not context.prefix_specified:\n    #     from ..core.envs_manager import EnvsDirectory\n    #     ed = EnvsDirectory(join(context.root_prefix, 'envs'))\n    #     get_env = lambda s: ed.get_registered_preferred_env(MatchSpec(s).name)\n    #     specs = specs_from_args(args.package_names)\n    #     env_spec_map = groupby(get_env, specs)\n    #     action_groups = []\n    #     for env_name, spcs in iteritems(env_spec_map):\n    #         pfx = ed.to_prefix(env_name)\n    #         r = get_resolve_object(index.copy(), pfx)\n    #         specs_to_remove = tuple(MatchSpec(s) for s in spcs)\n    #         prune = pfx != context.root_prefix\n    #         dists_for_unlinking, dists_for_linking = solve_for_actions(\n    #             pfx, r,\n    #             specs_to_remove=specs_to_remove, prune=prune,\n    #         )\n    #         actions = get_blank_actions(pfx)\n    #         actions['UNLINK'].extend(dists_for_unlinking)\n    #         actions['LINK'].extend(dists_for_linking)\n    #         actions['SPECS'].extend(text_type(s) for s in specs_to_remove)\n    #         actions['ACTION'] = 'REMOVE'\n    #         action_groups.append((actions, r.index))\n    #     action_groups = tuple(action_groups)\n    # else:\n    #     specs = specs_from_args(args.package_names)\n    #     if sys.prefix == abspath(prefix) and names_in_specs(ROOT_NO_RM, specs) and not args.force:  # NOQA\n    #         raise CondaEnvironmentError('cannot remove %s from root environment' %\n    #                                     ', '.join(ROOT_NO_RM))\n    #     action_groups = (remove_actions(prefix, list(specs), index=index,\n    #                                     force=args.force,\n    #                                     pinned=not context.ignore_pinned,\n    #                                     ), index),\n    #\n    #\n    # delete_trash()\n    # if any(nothing_to_do(x[0]) for x in action_groups):\n    #     if args.all:\n    #         print(\"\\nRemove all packages in environment %s:\\n\" % prefix, file=sys.stderr)\n    #         if not context.json:\n    #             confirm_yn(args)\n    #         rm_rf(prefix)\n    #\n    #         if context.json:\n    #             stdout_json({\n    #                 'success': True,\n    #                 'actions': tuple(x[0] for x in action_groups)\n    #             })\n    #         return\n    #\n    #     pkg = str(args.package_names).replace(\"['\", \"\")\n    #     pkg = pkg.replace(\"']\", \"\")\n    #\n    #     error_message = \"No packages named '%s' found to remove from environment.\" % pkg\n    #     raise PackageNotFoundError(error_message)\n    # if not context.json:\n    #     for actions, ndx in action_groups:\n    #         print()\n    #         print(\"Package plan for package removal in environment %s:\" % actions[\"PREFIX\"])\n    #         display_actions(actions, ndx)\n    # elif context.json and args.dry_run:\n    #     stdout_json({\n    #         'success': True,\n    #         'dry_run': True,\n    #         'actions': tuple(x[0] for x in action_groups),\n    #     })\n    #     return\n    #\n    # if not context.json:\n    #     confirm_yn(args)\n    #\n    # for actions, ndx in action_groups:\n    #     if context.json and not context.quiet:\n    #         with json_progress_bars():\n    #             execute_actions(actions, ndx, verbose=not context.quiet)\n    #     else:\n    #         execute_actions(actions, ndx, verbose=not context.quiet)\n    #\n    #     target_prefix = actions[\"PREFIX\"]\n    #     if is_private_env_path(target_prefix) and linked_data(target_prefix) == {}:\n    #         rm_rf(target_prefix)\n    #\n    # if args.all:\n    #     rm_rf(prefix)\n    #\n    # if context.json:\n    #     stdout_json({\n    #         'success': True,\n    #         'actions': tuple(x[0] for x in action_groups),\n    #     })\n", "path": "conda/cli/main_remove.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright (C) 2012 Anaconda, Inc\n# SPDX-License-Identifier: BSD-3-Clause\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nimport logging\nfrom os.path import isfile, join\nimport sys\n\nfrom .common import check_non_admin, specs_from_args\nfrom .install import handle_txn\nfrom ..base.context import context\nfrom ..core.envs_manager import unregister_env\nfrom ..core.link import PrefixSetup, UnlinkLinkTransaction\nfrom ..core.prefix_data import PrefixData\nfrom ..core.solve import Solver\nfrom ..exceptions import CondaEnvironmentError, CondaValueError, DirectoryNotACondaEnvironmentError\nfrom ..gateways.disk.delete import rm_rf, path_is_clean\nfrom ..models.match_spec import MatchSpec\nfrom ..exceptions import PackagesNotFoundError\n\nlog = logging.getLogger(__name__)\n\n\ndef execute(args, parser):\n\n    if not (args.all or args.package_names):\n        raise CondaValueError('no package names supplied,\\n'\n                              '       try \"conda remove -h\" for more details')\n\n    prefix = context.target_prefix\n    check_non_admin()\n\n    if args.all and prefix == context.default_prefix:\n        msg = \"cannot remove current environment. deactivate and run conda remove again\"\n        raise CondaEnvironmentError(msg)\n\n    if args.all and path_is_clean(prefix):\n        # full environment removal was requested, but environment doesn't exist anyway\n\n        # .. but you know what? If you call `conda remove --all` you'd expect the dir\n        # not to exist afterwards, would you not? If not (fine, I can see the argument\n        # about deleting people's work in envs being a very bad thing indeed), but if\n        # being careful is the goal it would still be nice if after `conda remove --all`\n        # to be able to do `conda create` on the same environment name.\n        #\n        # try:\n        #     rm_rf(prefix, clean_empty_parents=True)\n        # except:\n        #     log.warning(\"Failed rm_rf() of partially existent env {}\".format(prefix))\n\n        return 0\n\n    if args.all:\n        if prefix == context.root_prefix:\n            raise CondaEnvironmentError('cannot remove root environment,\\n'\n                                        '       add -n NAME or -p PREFIX option')\n        if not isfile(join(prefix, 'conda-meta', 'history')):\n            raise DirectoryNotACondaEnvironmentError(prefix)\n        print(\"\\nRemove all packages in environment %s:\\n\" % prefix, file=sys.stderr)\n\n        if 'package_names' in args:\n            stp = PrefixSetup(\n                target_prefix=prefix,\n                unlink_precs=tuple(PrefixData(prefix).iter_records()),\n                link_precs=(),\n                remove_specs=(),\n                update_specs=(),\n                neutered_specs={},\n            )\n            txn = UnlinkLinkTransaction(stp)\n            try:\n                handle_txn(txn, prefix, args, False, True)\n            except PackagesNotFoundError:\n                print(\"No packages found in %s. Continuing environment removal\" % prefix)\n        if not context.dry_run:\n            rm_rf(prefix, clean_empty_parents=True)\n            unregister_env(prefix)\n\n        return\n\n    else:\n        if args.features:\n            specs = tuple(MatchSpec(track_features=f) for f in set(args.package_names))\n        else:\n            specs = specs_from_args(args.package_names)\n        channel_urls = ()\n        subdirs = ()\n        solver = Solver(prefix, channel_urls, subdirs, specs_to_remove=specs)\n        txn = solver.solve_for_transaction()\n        handle_txn(txn, prefix, args, False, True)\n\n    # Keep this code for dev reference until private envs can be re-enabled in\n    # Solver.solve_for_transaction\n\n    # specs = None\n    # if args.features:\n    #     specs = [MatchSpec(track_features=f) for f in set(args.package_names)]\n    #     actions = remove_actions(prefix, specs, index, pinned=not context.ignore_pinned)\n    #     actions['ACTION'] = 'REMOVE_FEATURE'\n    #     action_groups = (actions, index),\n    # elif args.all:\n    #     if prefix == context.root_prefix:\n    #         raise CondaEnvironmentError('cannot remove root environment,\\n'\n    #                                     '       add -n NAME or -p PREFIX option')\n    #     actions = defaultdict(list)\n    #     actions[PREFIX] = prefix\n    #     for dist in sorted(iterkeys(index)):\n    #         add_unlink(actions, dist)\n    #     actions['ACTION'] = 'REMOVE_ALL'\n    #     action_groups = (actions, index),\n    # elif prefix == context.root_prefix and not context.prefix_specified:\n    #     from ..core.envs_manager import EnvsDirectory\n    #     ed = EnvsDirectory(join(context.root_prefix, 'envs'))\n    #     get_env = lambda s: ed.get_registered_preferred_env(MatchSpec(s).name)\n    #     specs = specs_from_args(args.package_names)\n    #     env_spec_map = groupby(get_env, specs)\n    #     action_groups = []\n    #     for env_name, spcs in iteritems(env_spec_map):\n    #         pfx = ed.to_prefix(env_name)\n    #         r = get_resolve_object(index.copy(), pfx)\n    #         specs_to_remove = tuple(MatchSpec(s) for s in spcs)\n    #         prune = pfx != context.root_prefix\n    #         dists_for_unlinking, dists_for_linking = solve_for_actions(\n    #             pfx, r,\n    #             specs_to_remove=specs_to_remove, prune=prune,\n    #         )\n    #         actions = get_blank_actions(pfx)\n    #         actions['UNLINK'].extend(dists_for_unlinking)\n    #         actions['LINK'].extend(dists_for_linking)\n    #         actions['SPECS'].extend(text_type(s) for s in specs_to_remove)\n    #         actions['ACTION'] = 'REMOVE'\n    #         action_groups.append((actions, r.index))\n    #     action_groups = tuple(action_groups)\n    # else:\n    #     specs = specs_from_args(args.package_names)\n    #     if sys.prefix == abspath(prefix) and names_in_specs(ROOT_NO_RM, specs) and not args.force:  # NOQA\n    #         raise CondaEnvironmentError('cannot remove %s from root environment' %\n    #                                     ', '.join(ROOT_NO_RM))\n    #     action_groups = (remove_actions(prefix, list(specs), index=index,\n    #                                     force=args.force,\n    #                                     pinned=not context.ignore_pinned,\n    #                                     ), index),\n    #\n    #\n    # delete_trash()\n    # if any(nothing_to_do(x[0]) for x in action_groups):\n    #     if args.all:\n    #         print(\"\\nRemove all packages in environment %s:\\n\" % prefix, file=sys.stderr)\n    #         if not context.json:\n    #             confirm_yn(args)\n    #         rm_rf(prefix)\n    #\n    #         if context.json:\n    #             stdout_json({\n    #                 'success': True,\n    #                 'actions': tuple(x[0] for x in action_groups)\n    #             })\n    #         return\n    #\n    #     pkg = str(args.package_names).replace(\"['\", \"\")\n    #     pkg = pkg.replace(\"']\", \"\")\n    #\n    #     error_message = \"No packages named '%s' found to remove from environment.\" % pkg\n    #     raise PackageNotFoundError(error_message)\n    # if not context.json:\n    #     for actions, ndx in action_groups:\n    #         print()\n    #         print(\"Package plan for package removal in environment %s:\" % actions[\"PREFIX\"])\n    #         display_actions(actions, ndx)\n    # elif context.json and args.dry_run:\n    #     stdout_json({\n    #         'success': True,\n    #         'dry_run': True,\n    #         'actions': tuple(x[0] for x in action_groups),\n    #     })\n    #     return\n    #\n    # if not context.json:\n    #     confirm_yn(args)\n    #\n    # for actions, ndx in action_groups:\n    #     if context.json and not context.quiet:\n    #         with json_progress_bars():\n    #             execute_actions(actions, ndx, verbose=not context.quiet)\n    #     else:\n    #         execute_actions(actions, ndx, verbose=not context.quiet)\n    #\n    #     target_prefix = actions[\"PREFIX\"]\n    #     if is_private_env_path(target_prefix) and linked_data(target_prefix) == {}:\n    #         rm_rf(target_prefix)\n    #\n    # if args.all:\n    #     rm_rf(prefix)\n    #\n    # if context.json:\n    #     stdout_json({\n    #         'success': True,\n    #         'actions': tuple(x[0] for x in action_groups),\n    #     })\n", "path": "conda/cli/main_remove.py"}]}