Repository: conda/conda

Issue:
Activate issue with parallel activations - "File exists" in symlinked path
I'm working in a cluster environment where I am trying to activate a conda environment in multiple parallel processes. After recently upgrading to the latest release (4.1.2), I've been receiving a "File exists" error in some of those processes, similar to the below:

```
Traceback (most recent call last):
  File "/symln_home/anaconda/bin/conda", line 6, in <module>
    sys.exit(main())
  File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/cli/main.py", line 48, in main
    activate.main()
  File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/cli/activate.py", line 163, in main
    conda.install.symlink_conda(prefix, root_dir, shell)
  File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/install.py", line 582, in symlink_conda
    symlink_conda_hlp(prefix, root_dir, where, symlink_fn)
  File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/install.py", line 599, in symlink_conda_hlp
    symlink_fn(root_file, prefix_file)
OSError: [Errno 17] File exists
```

I've been able to repro this issue on a laptop when my PATH to the root anaconda install contains a symlinked directory ("symln_home," in this example). Doesn't seem to be a problem when the PATH is symlink-free. The below has produced the error consistently for me on OS X:

```
$ echo $PATH
/symln_home/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
```

``` python
from multiprocessing import Pool
import os

call = ['source activate myenv && echo $PATH' for i in range(30)]
pool = Pool(4)
pool.map(os.system, call)
pool.close()
```

Is this a bug, or are there any workarounds for this particular use case? In my cluster environment, my HOME directory (where I've installed anaconda) is symlinked, which I would assume is a fairly common setup in shared computing (I don't admin it, so unfortunately I can't change that aspect). 

Activate issue with parallel activations - "File exists" in symlinked path
I'm working in a cluster environment where I am trying to activate a conda environment in multiple parallel processes. After recently upgrading to the latest release (4.1.2), I've been receiving a "File exists" error in some of those processes, similar to the below:

```
Traceback (most recent call last):
  File "/symln_home/anaconda/bin/conda", line 6, in <module>
    sys.exit(main())
  File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/cli/main.py", line 48, in main
    activate.main()
  File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/cli/activate.py", line 163, in main
    conda.install.symlink_conda(prefix, root_dir, shell)
  File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/install.py", line 582, in symlink_conda
    symlink_conda_hlp(prefix, root_dir, where, symlink_fn)
  File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/install.py", line 599, in symlink_conda_hlp
    symlink_fn(root_file, prefix_file)
OSError: [Errno 17] File exists
```

I've been able to repro this issue on a laptop when my PATH to the root anaconda install contains a symlinked directory ("symln_home," in this example). Doesn't seem to be a problem when the PATH is symlink-free. The below has produced the error consistently for me on OS X:

```
$ echo $PATH
/symln_home/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
```

``` python
from multiprocessing import Pool
import os

call = ['source activate myenv && echo $PATH' for i in range(30)]
pool = Pool(4)
pool.map(os.system, call)
pool.close()
```

Is this a bug, or are there any workarounds for this particular use case? In my cluster environment, my HOME directory (where I've installed anaconda) is symlinked, which I would assume is a fairly common setup in shared computing (I don't admin it, so unfortunately I can't change that aspect). 



Discussion:
@tomfleming We've had some fixes since `4.1.2` that might have tangentially touched on this, and may have ended up helping.  Can you see if you still have the problem as of `4.1.5`?

I downgraded to `4.0.0` and it appears to have resolved this issue.

I'd recommend dropping back not to 4.0.0, but rather 4.0.10.

This has been an issue brought to us. When running multiple instances of a bash script in parallel where a conda environment is activated prior to executing some python code, but the error below is produced:

`Traceback (most recent call last):`
`File "/usr/prog/anaconda/3.5-4.0.0/bin/conda", line 6, in <module>`
`sys.exit(main())`
`File "/usr/prog/anaconda/3.5-4.0.0/lib/python3.5/site-packages/conda/cli/main.py", line 48, in main 
activate.main()`
`File "/usr/prog/anaconda/3.5-4.0.0/lib/python3.5/site-packages/conda/cli/activate.py", line 163, in main 
conda.install.symlink_conda(prefix, root_dir, shell)`
`File "/usr/prog/anaconda/3.5-4.0.0/lib/python3.5/site-packages/conda/install.py", line 582, in symlink_conda`
`symlink_conda_hlp(prefix, root_dir, where, symlink_fn)`
`File "/usr/prog/anaconda/3.5-4.0.0/lib/python3.5/site-packages/conda/install.py", line 599, in symlink_conda_hlp`
`symlink_fn(root_file, prefix_file)`
`FileExistsError: [Errno 17] File exists: '/usr/prog/anaconda/3.5-4.0.0/bin/conda' -> '/home/john/.conda/envs/scikit/bin/conda'`

The script works as expected when it's not executed concurrently. The error was worked around by replacing the activation of the environment with the corresponding $PATH settings.

@tomfleming We've had some fixes since `4.1.2` that might have tangentially touched on this, and may have ended up helping.  Can you see if you still have the problem as of `4.1.5`?

I downgraded to `4.0.0` and it appears to have resolved this issue.

I'd recommend dropping back not to 4.0.0, but rather 4.0.10.

This has been an issue brought to us. When running multiple instances of a bash script in parallel where a conda environment is activated prior to executing some python code, but the error below is produced:

`Traceback (most recent call last):`
`File "/usr/prog/anaconda/3.5-4.0.0/bin/conda", line 6, in <module>`
`sys.exit(main())`
`File "/usr/prog/anaconda/3.5-4.0.0/lib/python3.5/site-packages/conda/cli/main.py", line 48, in main 
activate.main()`
`File "/usr/prog/anaconda/3.5-4.0.0/lib/python3.5/site-packages/conda/cli/activate.py", line 163, in main 
conda.install.symlink_conda(prefix, root_dir, shell)`
`File "/usr/prog/anaconda/3.5-4.0.0/lib/python3.5/site-packages/conda/install.py", line 582, in symlink_conda`
`symlink_conda_hlp(prefix, root_dir, where, symlink_fn)`
`File "/usr/prog/anaconda/3.5-4.0.0/lib/python3.5/site-packages/conda/install.py", line 599, in symlink_conda_hlp`
`symlink_fn(root_file, prefix_file)`
`FileExistsError: [Errno 17] File exists: '/usr/prog/anaconda/3.5-4.0.0/bin/conda' -> '/home/john/.conda/envs/scikit/bin/conda'`

The script works as expected when it's not executed concurrently. The error was worked around by replacing the activation of the environment with the corresponding $PATH settings.


Resolving patch:
diff --git a/conda/install.py b/conda/install.py
--- a/conda/install.py
+++ b/conda/install.py
@@ -613,7 +613,7 @@ def symlink_conda_hlp(prefix, root_dir, where, symlink_fn):
                 symlink_fn(root_file, prefix_file)
         except (IOError, OSError) as e:
             if (os.path.lexists(prefix_file) and
-                    (e.errno in (errno.EPERM, errno.EACCES, errno.EROFS))):
+                    (e.errno in (errno.EPERM, errno.EACCES, errno.EROFS, errno.EEXIST))):
                 log.debug("Cannot symlink {0} to {1}. Ignoring since link already exists."
                           .format(root_file, prefix_file))
             else:


Test patch: