Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4468e55

Browse files
committed
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.
1 parent ce5fe83 commit 4468e55

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

Lib/packaging/database.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,18 @@ def __repr__(self):
158158
self.name, self.version, self.path)
159159

160160
def _get_records(self, local=False):
161+
results = []
161162
with self.get_distinfo_file('RECORD') as record:
162163
record_reader = csv.reader(record, delimiter=',',
163164
lineterminator='\n')
164-
# XXX needs an explaining comment
165165
for row in record_reader:
166-
path, checksum, size = (row[:] +
167-
[None for i in range(len(row), 3)])
166+
missing = [None for i in range(len(row), 3)]
167+
path, checksum, size = row + missing
168168
if local:
169169
path = path.replace('/', os.sep)
170170
path = os.path.join(sys.prefix, path)
171-
yield path, checksum, size
171+
results.append((path, checksum, size))
172+
return results
172173

173174
def get_resource_path(self, relative_path):
174175
with self.get_distinfo_file('RESOURCES') as resources_file:
@@ -197,7 +198,8 @@ def list_installed_files(self, local=False):
197198
:type local: boolean
198199
:returns: iterator of (path, md5, size)
199200
"""
200-
return self._get_records(local)
201+
for result in self._get_records(local):
202+
yield result
201203

202204
def uses(self, path):
203205
"""

Lib/packaging/tests/test_uninstall.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def test_uninstall_unknow_distribution(self):
9393
self.assertRaises(PackagingError, remove, 'Foo',
9494
paths=[self.root_dir])
9595

96-
@unittest.skipIf(sys.platform == 'win32', 'deactivated for now')
9796
def test_uninstall(self):
9897
dist, install_lib = self.install_dist()
9998
self.assertIsFile(install_lib, 'foo', '__init__.py')
@@ -103,7 +102,6 @@ def test_uninstall(self):
103102
self.assertIsNotFile(install_lib, 'foo', 'sub', '__init__.py')
104103
self.assertIsNotFile(install_lib, 'Foo-0.1.dist-info', 'RECORD')
105104

106-
@unittest.skipIf(sys.platform == 'win32', 'deactivated for now')
107105
def test_remove_issue(self):
108106
# makes sure if there are OSErrors (like permission denied)
109107
# remove() stops and display a clean error

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ Jonathan Hogg
419419
Gerrit Holl
420420
Shane Holloway
421421
Rune Holm
422+
Thomas Holmes
422423
Philip Homburg
423424
Naofumi Honda
424425
Jeffrey Honig

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ Core and Builtins
219219
Library
220220
-------
221221

222+
- Issue #12504: Close file handles in a timely manner in packaging.database.
223+
This fixes a bug with the remove (uninstall) feature on Windows.
224+
222225
- Issues #12169 and #10510: Factor out code used by various packaging commands
223226
to make HTTP POST requests, and make sure it uses CRLF.
224227

0 commit comments

Comments
 (0)