Skip to main content

Module user_pdf

Module user_pdf 

Source
Expand description

Add a PDF the user downloaded themselves to the store (#606).

For a paper with no OA copy, the user downloads it under their own access and wants the store to know, so no other project hits the same wall. What this may and may not check is fixed by ADR-0003: the PDF is an opaque blob, so nothing here reads its text, its metadata streams or its page structure. The checks are the ones a fetch already makes of bytes off the wire, plus one about the file’s name:

  • a regular file, not a symlink, starting with %PDF-, under crate::PDF_MAX_BYTES;
  • a file name that is itself a work id – BF01397394.pdf, PhysRev.34.1293.pdf – must be the id of the ref it is added under. A name like 1928-024 PCPS Hartree - The wave mechanics.pdf makes no claim and is accepted. force overrides the mismatch.

The entry is recorded as what it is: [doiget] source = "user", license = "unknown", origin = "user-supplied" – never as an open copy, since bib, paper_pdf_path and an agent would otherwise read a licensed download as free to use. The file is copied, not moved, and the provenance row names the store path only: the original path, which carries the user’s home directory, is not logged.

Structs§

AddOutcome
What add_user_pdf stored.

Enums§

AddError
Why a file was not added.

Functions§

add_user_pdf
Add file to the store as ref_’s PDF.
check_file
Check file the way a fetch checks bytes off the wire, and return the bytes that passed – the only ones the store is given. Nothing past the magic number is interpreted (ADR-0003); the bytes are held, as a fetch holds a response body, never parsed.
file_stem
The file’s name without its .pdf extension (case-insensitive) and a browser’s duplicate suffix (name (1).pdf).
looks_like_an_id
Whether stem reads as a work id rather than a description: six or more characters, only letters, digits, ., - and _, and at least one digit. BF01397394, PhysRev.34.1293 and rspa.1950.0036 are ids; 1928-024 PCPS Hartree - The wave mechanics is not.
match_file
The one ref in candidates whose id stem is, if exactly one (#606 --from-dir). Two candidates sharing a DOI suffix is ambiguous and matches none.
stem_names
Whether stem names ref_: the DOI suffix (BF01340294 for 10.1007/BF01340294), the whole DOI with / as _ or -, or the arXiv id with or without a version. Case-insensitive.