Kaydet (Commit) 4468e55d authored tarafından Éric Araujo's avatar Éric Araujo

Close file handles in a timely manner in packaging.database (#12504).

This fixes a bug with the remove (uninstall) feature on Windows.  Patch
by Thomas Holmes.
üst ce5fe838
...@@ -158,17 +158,18 @@ class Distribution: ...@@ -158,17 +158,18 @@ class Distribution:
self.name, self.version, self.path) self.name, self.version, self.path)
def _get_records(self, local=False): def _get_records(self, local=False):
results = []
with self.get_distinfo_file('RECORD') as record: with self.get_distinfo_file('RECORD') as record:
record_reader = csv.reader(record, delimiter=',', record_reader = csv.reader(record, delimiter=',',
lineterminator='\n') lineterminator='\n')
# XXX needs an explaining comment
for row in record_reader: for row in record_reader:
path, checksum, size = (row[:] + missing = [None for i in range(len(row), 3)]
[None for i in range(len(row), 3)]) path, checksum, size = row + missing
if local: if local:
path = path.replace('/', os.sep) path = path.replace('/', os.sep)
path = os.path.join(sys.prefix, path) 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): def get_resource_path(self, relative_path):
with self.get_distinfo_file('RESOURCES') as resources_file: with self.get_distinfo_file('RESOURCES') as resources_file:
...@@ -197,7 +198,8 @@ class Distribution: ...@@ -197,7 +198,8 @@ class Distribution:
:type local: boolean :type local: boolean
:returns: iterator of (path, md5, size) :returns: iterator of (path, md5, size)
""" """
return self._get_records(local) for result in self._get_records(local):
yield result
def uses(self, path): def uses(self, path):
""" """
......
...@@ -93,7 +93,6 @@ class UninstallTestCase(support.TempdirManager, ...@@ -93,7 +93,6 @@ class UninstallTestCase(support.TempdirManager,
self.assertRaises(PackagingError, remove, 'Foo', self.assertRaises(PackagingError, remove, 'Foo',
paths=[self.root_dir]) paths=[self.root_dir])
@unittest.skipIf(sys.platform == 'win32', 'deactivated for now')
def test_uninstall(self): def test_uninstall(self):
dist, install_lib = self.install_dist() dist, install_lib = self.install_dist()
self.assertIsFile(install_lib, 'foo', '__init__.py') self.assertIsFile(install_lib, 'foo', '__init__.py')
...@@ -103,7 +102,6 @@ class UninstallTestCase(support.TempdirManager, ...@@ -103,7 +102,6 @@ class UninstallTestCase(support.TempdirManager,
self.assertIsNotFile(install_lib, 'foo', 'sub', '__init__.py') self.assertIsNotFile(install_lib, 'foo', 'sub', '__init__.py')
self.assertIsNotFile(install_lib, 'Foo-0.1.dist-info', 'RECORD') self.assertIsNotFile(install_lib, 'Foo-0.1.dist-info', 'RECORD')
@unittest.skipIf(sys.platform == 'win32', 'deactivated for now')
def test_remove_issue(self): def test_remove_issue(self):
# makes sure if there are OSErrors (like permission denied) # makes sure if there are OSErrors (like permission denied)
# remove() stops and display a clean error # remove() stops and display a clean error
......
...@@ -419,6 +419,7 @@ Jonathan Hogg ...@@ -419,6 +419,7 @@ Jonathan Hogg
Gerrit Holl Gerrit Holl
Shane Holloway Shane Holloway
Rune Holm Rune Holm
Thomas Holmes
Philip Homburg Philip Homburg
Naofumi Honda Naofumi Honda
Jeffrey Honig Jeffrey Honig
......
...@@ -219,6 +219,9 @@ Core and Builtins ...@@ -219,6 +219,9 @@ Core and Builtins
Library 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 - Issues #12169 and #10510: Factor out code used by various packaging commands
to make HTTP POST requests, and make sure it uses CRLF. to make HTTP POST requests, and make sure it uses CRLF.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment