This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: packaging remove fails under Windows
Type: behavior Stage: resolved
Components: Distutils2, Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder: packaging: fix database to stop skipping uninstall tests on win32
View: 12504
Assigned To: eric.araujo Nosy List: alexis, eric.araujo, tarek, vinay.sajip
Priority: normal Keywords:

Created on 2011-06-24 11:41 by vinay.sajip, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg138917 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2011-06-24 11:41
"pysetup3 remove projectX" fails on Windows. The reason is that the RECORD file can't be moved, as it's still open (we're using a generator in list_installed_files). Apart from fixing that, a related annoyance is that you get the 

[Error 32] The process cannot access the file because it is being used by another process

but, of course, it doesn't tell you *which* file it failed on. So the error message needs to say which file(s) couldn't be moved.
msg138919 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2011-06-24 11:49
I can confirm that putting a list() around the generator allows the removal to proceed:

diff -r d2453f281baf Lib/packaging/install.py
--- a/Lib/packaging/install.py	Fri Jun 24 10:21:46 2011 +0100
+++ b/Lib/packaging/install.py	Fri Jun 24 12:48:33 2011 +0100
@@ -389,7 +389,10 @@
     dist = get_distribution(project_name, use_egg_info=True, paths=paths)
     if dist is None:
         raise PackagingError('Distribution "%s" not found' % project_name)
-    files = dist.list_installed_files(local=True)
+    # list_installed_files returns a generator, and we need the
+    # RECORD file itself closed so that we can move it - under Windows,
+    # you can't move an opened file
+    files = list(dist.list_installed_files(local=True))
     rmdirs = []
     rmfiles = []
     tmp = tempfile.mkdtemp(prefix=project_name + '-uninstall')


The error message does need fixing, though, for cases where something else has a distribution's files open.
msg138923 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-06-24 11:54
> So the error message needs to say which file(s) couldn't be moved.
Isn’t that a Windows error message which we have no control on?
msg138925 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2011-06-24 12:07
We could fix the error message, for example, like this:

--- a/Lib/packaging/install.py	Fri Jun 24 10:21:46 2011 +0100
+++ b/Lib/packaging/install.py	Fri Jun 24 13:06:08 2011 +0100
@@ -412,6 +415,7 @@
                     error = _move_file(file_, tmpfile)
                     if error is not None:
                         success = False
+                        failed_on = file_
                         break
                 finally:
                     if not os.path.isfile(file_):
@@ -425,7 +429,7 @@
 
     if not success:
         logger.info('%r cannot be removed.', project_name)
-        logger.info('Error: %s' % str(error))
+        logger.info('Error: %s: %s' % (error, failed_on))
         return False
 
     logger.info('Removing %r: ', project_name)
msg138930 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-06-24 12:14
Ah, nice, just use %r for the filename.  I’ll commit this improvement in a few days.

Do you want to write a test for the remove error?
msg144294 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-09-19 16:09
If I’m not mistaken, 2b9a0a091566 fixed this.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56604
2011-09-19 16:09:15eric.araujosetstatus: open -> closed
resolution: duplicate
messages: + msg144294

superseder: packaging: fix database to stop skipping uninstall tests on win32
stage: needs patch -> resolved
2011-06-24 12:14:34eric.araujosetassignee: tarek -> eric.araujo
messages: + msg138930
stage: needs patch
2011-06-24 12:07:31vinay.sajipsetmessages: + msg138925
2011-06-24 11:54:41eric.araujosetmessages: + msg138923
2011-06-24 11:49:58vinay.sajipsetmessages: - msg138920
2011-06-24 11:49:50vinay.sajipsetmessages: + msg138920
2011-06-24 11:49:48vinay.sajipsetmessages: + msg138919
2011-06-24 11:41:09vinay.sajipcreate