Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123286
D4493.id15954.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D4493.id15954.diff
View Options
diff --git a/swh/deposit/parsers.py b/swh/deposit/parsers.py
--- a/swh/deposit/parsers.py
+++ b/swh/deposit/parsers.py
@@ -8,6 +8,7 @@
"""
+import logging
from typing import Dict, Optional, Union
from xml.parsers.expat import ExpatError
@@ -26,6 +27,8 @@
parse_swhid,
)
+logger = logging.getLogger(__name__)
+
class SWHFileUploadZipParser(FileUploadParser):
"""File upload parser limited to zip archive.
@@ -142,6 +145,9 @@
Either swhid or origin reference if any. None otherwise.
""" # noqa
+ visit_swhid = None
+ anchor_swhid = None
+
swh_deposit = metadata.get("swh:deposit")
if not swh_deposit:
return None
@@ -184,4 +190,18 @@
f"visit qualifier should be a core SWHID with type {SNAPSHOT}"
)
+ if (
+ visit_swhid
+ and anchor_swhid
+ and visit_swhid.object_type == SNAPSHOT
+ and anchor_swhid.object_type == SNAPSHOT
+ ):
+ logger.warn(
+ "SWHID use of both anchor and visit targeting "
+ f"a snapshot: {swhid_reference}"
+ )
+ raise ValidationError(
+ "'anchor=swh:1:snp:' is not supported when 'visit' is also provided."
+ )
+
return swhid_reference
diff --git a/swh/deposit/tests/api/test_parsers.py b/swh/deposit/tests/api/test_parsers.py
--- a/swh/deposit/tests/api/test_parsers.py
+++ b/swh/deposit/tests/api/test_parsers.py
@@ -224,7 +224,11 @@
(
"swh:1:rev:c4993c872593e960dc84e4430dbbfbc34fd706d0;anchor=swh:1:cnt:b5f505b005435fa5c4fa4c279792bd7b17167c04;path=/", # noqa
"anchor qualifier should be a core SWHID with type one of",
- ), # noqa
+ ),
+ (
+ "swh:1:rev:c4993c872593e960dc84e4430dbbfbc34fd706d0;visit=swh:1:snp:0175049fc45055a3824a1675ac06e3711619a55a;anchor=swh:1:snp:b5f505b005435fa5c4fa4c279792bd7b17167c04", # noqa
+ "anchor=swh:1:snp",
+ ),
],
)
def test_parse_swh_reference_invalid_swhid(invalid_swhid, error_msg, xml_with_swhid):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 18, 11:45 AM (1 d, 9 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217039
Attached To
D4493: metadata-only: Restrict swhid use of qualifier anchor and visit on snapshot
Event Timeline
Log In to Comment