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

Avoid the Windows file lock by moving files to a trash directory #1133

Merged
merged 28 commits into from May 7, 2015

Conversation

asmeurer
Copy link
Contributor

@asmeurer asmeurer commented Feb 6, 2015

This lets you update Python, pycosat, and psutil in the root environment.

Conda moves all files that it can't delete to a trash directory. Conda attempts to clear the trash directory every time it links a package. This typically will not actually work until the next time conda is run.

Preliminary tests indicate this is working, but obviously it needs a lot more testing. If you do test, I highly recommend installing a new Miniconda, as the risk of borking your existing installation is still high.

Fixes #1001.

@asmeurer
Copy link
Contributor Author

asmeurer commented Feb 6, 2015

Known issue: a lot of "access is denied" errors are printed to the screen on installation.

@asmeurer
Copy link
Contributor Author

asmeurer commented Feb 6, 2015

TODO:

  • Test envs dirs stuff
  • Put the trash in the prefix, not the envs dir (negates the above)
  • See if rm_rf does partial deletions
  • Access is denied errors
  • Use tasklist /m somehow?
  • Test failures
  • Move this logic to rm_rf?

This reverts commit 287b4a0.

subprocess.DEVNULL is only available in Python 3.
The output is printed to the log.
@asmeurer
Copy link
Contributor Author

asmeurer commented Feb 6, 2015

An error I got changing Python versions:


C:\Users\Aaron Meurer\Documents\GitHub\conda>"C:\Users\Aaron Meurer\Miniconda3
-test\Scripts\conda.exe" install python=3
Fetching package metadata: ......
Solving package specifications: .......
Package plan for installation in environment C:\Users\Aaron Meurer\Miniconda3-te
st:

The following packages will be UPDATED:

    conda:     3.8.4-py27_0 defaults --> 3.8.4-py34_0 defaults
    conda-env: 2.0.2-py27_0 defaults --> 2.0.2-py34_0 defaults
    pycosat:   0.6.1-py27_0 defaults --> 0.6.1-py34_0 defaults
    python:    2.7.9-1      defaults --> 3.4.2-1      defaults
    pyyaml:    3.11-py27_0  defaults --> 3.11-py34_0  defaults
    requests:  2.5.1-py27_0 defaults --> 2.5.1-py34_0 defaults

Unlinking packages ...
[      COMPLETE      ] |#################################################| 100%
Linking packages ...
An unexpected error has occurred, please consider sending the            |   0%
following traceback to the conda GitHub issue tracker at:

    https://github.com/conda/conda/issues

Include the output of the command 'conda info' in your report.


Traceback (most recent call last):
  File "C:\Users\Aaron Meurer\Miniconda3-test\Scripts\conda-script.py", line 4,
in <module>
  File "c:\users\aaron meurer\documents\github\conda\conda\cli\main.py", line 20
2, in main
    args_func(args, p)
  File "c:\users\aaron meurer\documents\github\conda\conda\cli\main.py", line 20
7, in args_func
    args.func(args, p)
  File "c:\users\aaron meurer\documents\github\conda\conda\cli\main_install.py",
 line 46, in execute
    install.install(args, parser, 'install')
  File "c:\users\aaron meurer\documents\github\conda\conda\cli\install.py", line
 412, in install
    plan.execute_actions(actions, index, verbose=not args.quiet)
  File "c:\users\aaron meurer\documents\github\conda\conda\plan.py", line 498, i
n execute_actions
    inst.execute_instructions(plan, index, verbose)
  File "c:\users\aaron meurer\documents\github\conda\conda\instructions.py", lin
e 134, in execute_instructions
    getLogger('progress.update').info((arg, state['i']))
  File "C:\Users\Aaron Meurer\Miniconda3-test\lib\logging\__init__.py", line 116
0, in info
  File "C:\Users\Aaron Meurer\Miniconda3-test\lib\logging\__init__.py", line 127
9, in _log
  File "C:\Users\Aaron Meurer\Miniconda3-test\lib\logging\__init__.py", line 128
9, in handle
  File "C:\Users\Aaron Meurer\Miniconda3-test\lib\logging\__init__.py", line 132
9, in callHandlers
  File "C:\Users\Aaron Meurer\Miniconda3-test\lib\logging\__init__.py", line 757
, in handle
  File "c:\users\aaron meurer\documents\github\conda\conda\console.py", line 47,
 in emit
    progress.update(n)
  File "c:\users\aaron meurer\documents\github\conda\conda\progressbar\__init__.
py", line 283, in update
    self.fd.write(self._format_line() + '\r')
LookupError: unknown encoding: cp437

I don't know if this is a bug in conda or if it's due to pulling out DLLs from under Python.

@asmeurer asmeurer added the os::windows relevant to Windows label Feb 6, 2015
@asmeurer
Copy link
Contributor Author

asmeurer commented Feb 6, 2015

I have no idea how to fix these mock tests.

@asmeurer
Copy link
Contributor Author

asmeurer commented Feb 6, 2015

Annoyingly, the above error is only triggered if you don't use --debug.

@asmeurer
Copy link
Contributor Author

asmeurer commented Feb 6, 2015

I've only seen it happen when moving from Python 2 to Python 3. Unfortunately, this is something that people try to do.

@asmeurer
Copy link
Contributor Author

asmeurer commented Feb 6, 2015

Heh, so catching LookupError on that line fixes it. I'm still quite concerned, though.

@ilanschnell
Copy link
Contributor

I just gave it a try on Windows XP, it updated from Python 2.7.7 to 2.7.9 without any problems. Great!

@asmeurer
Copy link
Contributor Author

asmeurer commented Feb 6, 2015

Anyway, don't merge at least until all of these are checked off.

@ilanschnell
Copy link
Contributor

Yes, testing is critical here, because otherwise people are likely to hose their installations.

@Maggie-M
Copy link
Contributor

I've managed to complete the testing from the first checkbox (test envs dirs stuff), and I didn't run into any issues. It all seems to be working correctly.

The two are related, but the pkgs dir is where we can actually expect to be
able to write things.
With the new trash functionality, it is unnecessary.
It now uses Popen, and it isn't worth my time to figure out how to change these
meaningless mock tests.
Otherwise the retries are on a delay timer, which would slow down the install.
Once we are sure there are no other issues with the trash stuff we can remove
it again.
@asmeurer
Copy link
Contributor Author

asmeurer commented May 5, 2015

This is pretty much ready for merging. I have left the win_ignore_root in for now (so conda still won't update Python in the root environment), as I'd like to make sure there are no other issues with this before we potentially break people's installations. I'd also like to eventually move this logic to rm_rf and use that everywhere instead of unlink, but that's a future TODO.

@asmeurer asmeurer mentioned this pull request May 6, 2015
@ilanschnell
Copy link
Contributor

Looks great. Thanks for the effort Aaron.

ilanschnell added a commit that referenced this pull request May 7, 2015
Avoid the Windows file lock by moving files to a trash directory
@ilanschnell ilanschnell merged commit a4406fb into conda:master May 7, 2015
@ilanschnell ilanschnell mentioned this pull request Jul 13, 2015
@almarklein
Copy link
Contributor

@asmeurer Does this apply to any package with binary modules, or only to Python, pycosat, and psutil? (Going to test this in a minute, but would like to know whether it's intended to work.)

@ilanschnell
Copy link
Contributor

This applies to any packages, which contain files that are opened by a process and then not closed. So yes, any package with binary modules, but it could also be any other file which is open.

@almarklein
Copy link
Contributor

Awesome :)

asmeurer added a commit to asmeurer/conda that referenced this pull request Sep 29, 2015
Sometimes updating Python in the root environment on Windows raises this
error. See conda#1657 and conda#1133.
@github-actions
Copy link

github-actions bot commented Oct 4, 2021

Hi there, thank you for your contribution to Conda!

This pull request has been automatically locked since it has not had recent activity after it was closed.

Please open a new issue or pull request if needed.

@github-actions github-actions bot added the locked [bot] locked due to inactivity label Oct 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked [bot] locked due to inactivity os::windows relevant to Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid the Windows file lock
4 participants