Saving a Library

Library save must detect concurrent modification of library file

req~logic.exporter.concurrent-save-detection~1

When the target file is modified by another process between the start of a save and its commit, the save must be aborted with an error instead of silently overwriting the other process’s changes. The detection is best-effort: it is based on the file’s size and modification time, so it is subject to the file system’s timestamp resolution.

Rationale: Two processes (e.g., two JabRef instances on different machines using a network share) may write the same library file at overlapping times, risking silent data loss.

Needs: impl, utest

Atomic save must preserve existing file attributes

req~logic.exporter.preserve-file-attributes~1

An atomic save replaces the target file with a newly created one. The group, DOS attributes (hidden, system, archive, read-only), ACL, and user-defined extended attributes (e.g., macOS Finder tags) of the previous file must be carried over to the new file. This is best-effort: an attribute class the file system does not support, or the OS refuses to set (e.g., a group the user is not a member of), is skipped without failing the save. Ownership is not restored, because that requires elevated privileges.

Needs: impl, utest

PDF metadata writer must replace target file atomically

req~logic.xmp.atomic-pdf-write~1

Writing metadata into a PDF (XMP metadata, embedded bib file, or metadata removal) must never rewrite the original file in place. The new content is committed through the same atomic-replacement mechanism as library saves (temporary file in the target directory, atomic move, hard links preserved via in-place inode overwrite), so concurrent readers such as file synchronization tools never observe a partially written PDF. A failed write must leave the original file untouched and must not leave temporary files behind.

Needs: impl, utest

Template export failures must preserve the destination file

req~logic.exporter.preserve-output-on-template-failure~1

If loading or rendering a required layout fails, an existing destination remains unchanged and a new destination is not created, even if output has already been generated.

See JabRef/jabref#17423.

Needs: impl, utest

Backup system must not overwrite valid backups on write failure

req~jabgui.autosaveandbackup.complete-backup~1

When creating a backup, a serialization failure must not replace a previous backup with incomplete content. JabRef must not restore an empty backup over an existing library.

Needs: impl, utest

Changes accepted from a backup must be recorded in the undo history of the restored library

req~jabgui.autosaveandbackup.accepted-backup-changes-undoable~1

Issue: #15846

When a library is opened and the user accepts changes while reviewing its backup, the merge must be recorded in the undo history of the tab that shows the library. Then the library is marked as modified and the merge can be undone; otherwise, the restored library looks saved and the restored content is lost when it is closed.

Needs: impl, utest

Backup must batch field edits into scheduled writes

req~jabgui.autosaveandbackup.backup-every-edit~1

Typing into a newly added or existing field must mark the library for backup, including single-character changes. Keystrokes must only mark a backup as pending; they must not trigger serialization or disk writes. The backup timer must batch pending edits into at most one backup write per interval (currently 19 seconds). The next scheduled backup must contain the latest field value so recovery can detect and restore unsaved edits after a crash.

Needs: impl, utest

Backup completion must preserve pending edits made after its snapshot

req~jabgui.autosaveandbackup.preserve-pending-edits~1

A field edit received after a backup captures its snapshot must remain pending for the next scheduled backup, even if the older snapshot is written successfully. A failed backup must leave its edits pending for another attempt.

Needs: impl, utest

Backup writers for a library must execute one at a time

req~jabgui.autosaveandbackup.serialized-writes~1

Scheduled backups and backups requested during shutdown must serialize generation capture, snapshot creation, file commit, and completion acknowledgement. A shutdown backup must wait for an in-flight backup before capturing the latest edits, so an older snapshot cannot replace the final backup.

Needs: impl, utest

Autosave must trigger save automatically upon library changes

req~jabgui.autosaveandbackup.autosave-listens~1

While autosave is enabled for a library, every change to the library must lead to the library being saved shortly afterwards without user interaction. Entry mutations made by save actions must run on the JavaFX event thread, while formatting and file writing remain in the background.

When the autosave manager is shut down, its periodic task must stop and pending callbacks must not post further autosave events.

Needs: impl, utest

Library cleanup must normalize keyword delimiters using library separator

req~save.keywords.normalize-delimiters~1

Rewriting a keyword field from an accepted import delimiter to the library’s keyword separator is a field formatter cleanup (“Normalize keyword delimiters”). It is part of the default save actions and available in the cleanup dialog, so users see it, can disable it per library, and can run it on demand. A field that already uses the library’s separator is returned unchanged, including its spacing. Cleanups that depend on the keyword separator use the separator declared by the library the entry belongs to and fall back to the global preference when the library declares none.

Needs: impl, utest

User can convert LaTeX character commands to Unicode-aware LaTeX

feat~save.cleanup.latex-to-unicode-aware-latex~1

The field formatter “LaTeX to Unicode-aware LaTeX” replaces commands that encode a single character, such as \textcopyright{} or \"{o}, by the Unicode character, because current LaTeX engines read Unicode directly. It is available in the cleanup dialog and as a save action. Unlike “LaTeX to Unicode”, it keeps all other LaTeX code: protective braces, math, formatting commands such as \emph{...}, and commands without a single-character Unicode equivalent. It preserves LaTeX comments and braces protecting uppercase character commands from BibTeX case changes. Math preservation recognizes standard math delimiters and a fixed set of common math environments; custom and unlisted environments are not recognized. A command whose conversion would introduce a LaTeX special character (such as \textbackslash{}) is kept.

See https://github.com/JabRef/jabref/issues/8715.

Needs: impl, utest

LaTeX to Unicode-aware LaTeX formatter must keep escaped special characters

req~save.cleanup.latex-to-unicode-aware-latex.keep-escaped-characters~1

Escaped LaTeX special characters (\%, \&, \$, \#, \_, \{, \}, \\) stay escaped, because the unescaped character has a different meaning in LaTeX.

Needs: impl, utest

JabRef must preserve extended name parts on save

req~save.names.preserve-extended-parts~1

BibLaTeX extended name attributes include keys such as family=, given=, prefix=, and useprefix=.

Needs: impl, utest

Name normalization must preserve BibLaTeX extended name data

req~save.names.normalize-extended-parts~1

Normalization preserves name attributes, name-list options, and quotes protecting individual name parts. If an extended name has malformed syntax or repeats an attribute, normalization preserves the field as entered.

Needs: impl, utest

Citation key generation must normalize extended names to readable name parts

req~save.citation-keys.normalize-extended-names~1

The normalize_names modifier in a citation key pattern uses the names without their BibLaTeX attribute labels. Saving and reopening the entry preserves the generated key and the original name field.

Needs: impl, utest