Skip to content

Commit 15daa6e

Browse files
committed
refactor license-file check for tar.gz sdists
1 parent 94f0d4b commit 15daa6e

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

warehouse/forklift/legacy.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212

13-
import copy
1413
import hashlib
1514
import hmac
1615
import os.path
@@ -1130,20 +1129,17 @@ def file_upload(request):
11301129
Ensure all License-File keys exist in the wheel
11311130
See https://peps.python.org/pep-0639/#add-license-file-field
11321131
"""
1133-
license_files = copy.deepcopy(meta.license_files)
11341132
with tarfile.open(temporary_filename, "r:gz") as tar:
11351133
# Already validated as a tarfile by _is_valid_dist_file above
1136-
member = tar.next()
1137-
while member:
1138-
if member.name in license_files:
1139-
license_files.remove(member.name)
1140-
member = tar.next()
1141-
if license_files != []:
1142-
raise _exc_with_message(
1143-
HTTPBadRequest,
1144-
f"License-File {license_files[0]} does not exist in "
1145-
f"distribution file {filename}",
1146-
)
1134+
for license_file in meta.license_files:
1135+
try:
1136+
tar.getmember(license_file)
1137+
except KeyError:
1138+
raise _exc_with_message(
1139+
HTTPBadRequest,
1140+
f"License-File {license_file} does not exist in "
1141+
f"distribution file {filename}",
1142+
)
11471143

11481144
# Check that if it's a binary wheel, it's on a supported platform
11491145
if filename.endswith(".whl"):

0 commit comments

Comments
 (0)