Zum Inhalt

Registering manual file changes

Files in a publication's processing folder may occasionally need to be changed outside a harvesting module. The filesystem and the bookkeeping graph must describe the same state, so these changes have to be declared in a manual_file_edits.json file. A later, successful processing step reads this file and incorporates the declared changes into the normal bookkeeping update.

How the manual registration can be used

Make the required changes in the publication's current processing folder and create manual_file_edits.json in that same folder. The JSON object may contain the following keys:

  • created_files: files that now exist but were not part of the location recorded in bookkeeping;
  • modified_files: files that still exist but whose content has changed;
  • deleted_files: files that were recorded in bookkeeping but no longer exist.

Each value must be a JSON array of file paths. Paths are relative to the processing folder containing manual_file_edits.json; do not include the processing folder's own name. Forward slashes are recommended for nested paths.

{
  "created_files": [
    "supplements/new-data.csv"
  ],
  "modified_files": [
    "xml/article.xml"
  ],
  "deleted_files": [
    "images/obsolete-figure.tif"
  ]
}

Keys for which there are no changes may be omitted or assigned an empty array. Put each path in exactly one category. In particular:

  • a created file must exist and must not already be registered for the location;
  • a modified file must exist and must already be registered;
  • a deleted file is intended to be absent and to have been registered previously.

After saving the file, let the publication pass through its next normal processing step. ProcessingInterface.create_temp_folder(...) copies the current processing folder, including manual_file_edits.json, to the module's temporary folder. The information is consumed when the job is returned successfully with return_job(...) (or when the equivalent startup-job finalization path is used). Merely creating the JSON file does not update the bookkeeping graph, and a temporary-only or unsuccessful return does not process it.

If the JSON is malformed, loading raises a JSON decoding error and processing stops so that the file can be corrected. Unknown keys are ignored. The three recognized values are not schema-validated, so they should always be arrays of path strings.

How the information about the manual changes is processed in the bookkeeping system

The processing sequence starts in ProcessingJob.__register_file_changes(...) at line 210 of bookkeeping/processinginterface.py:

  1. ProcessingJob.finish(...) first determines whether the returned job represents a normal/stop result or only temporary changes. Temporary-only results return before file changes are registered.
  2. For a result that can be finalized, the location object's content path is changed to the temporary processing folder. This makes all reported file paths resolve relative to that folder.
  3. __register_file_changes(...) calls __add_manual_change_information(...). If <article directory>/<temporary processing folder>/manual_file_edits.json exists, load_manual_edit_information(...) parses it and retrieves the optional created_files, modified_files, and deleted_files arrays.
  4. Each manual array is merged with the corresponding array supplied by the module to return_job(...). Duplicate paths within the same category are removed when both sources supplied that category. Conflicts between different categories are not resolved automatically.
  5. filter_ignored_files(...) removes bookkeeping-internal paths. In particular, manual_file_edits.json itself and processing/history.csv are not registered as publication files; content below pre_module_state is also ignored.
  6. Created, modified, and deleted entries are applied to the in-memory DataLocation through report_file_added(...), report_file_modified(...), and report_file_deleted(...), respectively. Created and modified files must exist; their SHA-256 checksums are calculated and they receive the corresponding processing status. A deleted file must no longer exist and must already be registered. Its entry is retained with no checksum and receives the deleted processing status.
  7. If any entry cannot be registered, __register_file_changes(...) returns False. Finalization is aborted, the previous module folder is retained, and the current module folder remains temporary so the problem can be investigated and retried.
  8. If all entries are accepted, BookkeepingHandler.update_processing_files_file_info(...) persists the changed file state to the triple store. Created files receive new file and checksum information; modified files receive a new checksum and processing provenance. For a deleted file, the existing checksum relation is removed and a wdmvoc:wasDeletedBy relation to the current processing activity is added. The location's processing-folder and module-assignment information is updated as part of the same finalization phase.
  9. Finally, resolve_temp_folder(...) renames the temporary folder to its processed name, removes manual_file_edits.json from that folder, and clears the superseded processing folder according to the normal job-completion rules. Removing the JSON prevents the same manual changes from being registered again during a later module run.