]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Close file handles in a timely manner in packaging.database (#12504).
authorÉric Araujo <merwok@netwok.org>
Fri, 8 Jul 2011 15:22:19 +0000 (17:22 +0200)
committerÉric Araujo <merwok@netwok.org>
Fri, 8 Jul 2011 15:22:19 +0000 (17:22 +0200)
This fixes a bug with the remove (uninstall) feature on Windows.  Patch
by Thomas Holmes.

Lib/packaging/database.py
Lib/packaging/tests/test_uninstall.py
Misc/ACKS
Misc/NEWS

index 67946a249b744ed4aa75d244e63babcbef32c946..c71d608491a91934616c7b60f122fc9bc45e2cd7 100644 (file)
@@ -158,17 +158,18 @@ class Distribution:
             self.name, self.version, self.path)
 
     def _get_records(self, local=False):
+        results = []
         with self.get_distinfo_file('RECORD') as record:
             record_reader = csv.reader(record, delimiter=',',
                                        lineterminator='\n')
-            # XXX needs an explaining comment
             for row in record_reader:
-                path, checksum, size = (row[:] +
-                                        [None for i in range(len(row), 3)])
+                missing = [None for i in range(len(row), 3)]
+                path, checksum, size = row + missing
                 if local:
                     path = path.replace('/', os.sep)
                     path = os.path.join(sys.prefix, path)
-                yield path, checksum, size
+                results.append((path, checksum, size))
+        return results
 
     def get_resource_path(self, relative_path):
         with self.get_distinfo_file('RESOURCES') as resources_file:
@@ -197,7 +198,8 @@ class Distribution:
         :type local: boolean
         :returns: iterator of (path, md5, size)
         """
-        return self._get_records(local)
+        for result in self._get_records(local):
+            yield result
 
     def uses(self, path):
         """
index 0ef7f3be90bac646ab19f8e7543dd7c3b1554067..c7702dedc30104ab2ebb8c38bd4940da18c1d09f 100644 (file)
@@ -93,7 +93,6 @@ class UninstallTestCase(support.TempdirManager,
         self.assertRaises(PackagingError, remove, 'Foo',
                           paths=[self.root_dir])
 
-    @unittest.skipIf(sys.platform == 'win32', 'deactivated for now')
     def test_uninstall(self):
         dist, install_lib = self.install_dist()
         self.assertIsFile(install_lib, 'foo', '__init__.py')
@@ -103,7 +102,6 @@ class UninstallTestCase(support.TempdirManager,
         self.assertIsNotFile(install_lib, 'foo', 'sub', '__init__.py')
         self.assertIsNotFile(install_lib, 'Foo-0.1.dist-info', 'RECORD')
 
-    @unittest.skipIf(sys.platform == 'win32', 'deactivated for now')
     def test_remove_issue(self):
         # makes sure if there are OSErrors (like permission denied)
         # remove() stops and display a clean error
index 0662bae2898a1dfa513d7d5f2f5c2b93cdbb24d8..6879c98a193b529c0a36a97d8b6e40755acac614 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -419,6 +419,7 @@ Jonathan Hogg
 Gerrit Holl
 Shane Holloway
 Rune Holm
+Thomas Holmes
 Philip Homburg
 Naofumi Honda
 Jeffrey Honig
index c45a725aa539ad9338a74d4a7437549d257563c3..cd0eab6a5091753890c9e9ad3ebfd4b6b1e4deda 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -219,6 +219,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #12504: Close file handles in a timely manner in packaging.database.
+  This fixes a bug with the remove (uninstall) feature on Windows.
+
 - Issues #12169 and #10510: Factor out code used by various packaging commands
   to make HTTP POST requests, and make sure it uses CRLF.