Skip to content

Commit

Permalink
Fix BibTexStrings not included in backup file (#12464)
Browse files Browse the repository at this point in the history
* Fix BibTexStrings not included in backup file

Fixes #12462

* fix checkstyle
  • Loading branch information
Siedlerchr authored Feb 5, 2025
1 parent beefbaa commit b4c48ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where removing the sort from the table did not restore the original order. [#12371](https://github.com/JabRef/jabref/pull/12371)
- We fixed an issue where JabRef icon merges with dark background [#7771](https://github.com/JabRef/jabref/issues/7771)
- We fixed an issue where an entry's group was no longer highlighted on selection [#12413](https://github.com/JabRef/jabref/issues/12413)
- We fixed an issue where BibTeX Strings were not included in the backup file [#12462](https://github.com/JabRef/jabref/issues/12462)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.jabref.model.database.event.BibDatabaseContextChangedEvent;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.BibtexString;
import org.jabref.model.metadata.SaveOrder;
import org.jabref.model.metadata.SelfContainedSaveOrder;

Expand All @@ -59,7 +60,7 @@ public class BackupManager {

private static final int DELAY_BETWEEN_BACKUP_ATTEMPTS_IN_SECONDS = 19;

private static Set<BackupManager> runningInstances = new HashSet<>();
private static final Set<BackupManager> RUNNING_INSTANCES = new HashSet<>();

private final BibDatabaseContext bibDatabaseContext;
private final CliPreferences preferences;
Expand Down Expand Up @@ -109,7 +110,7 @@ static Optional<Path> getLatestBackupPath(Path originalPath, Path backupDir) {
public static BackupManager start(LibraryTab libraryTab, BibDatabaseContext bibDatabaseContext, BibEntryTypesManager entryTypesManager, CliPreferences preferences) {
BackupManager backupManager = new BackupManager(libraryTab, bibDatabaseContext, entryTypesManager, preferences);
backupManager.startBackupTask(preferences.getFilePreferences().getBackupDirectory());
runningInstances.add(backupManager);
RUNNING_INSTANCES.add(backupManager);
return backupManager;
}

Expand All @@ -119,7 +120,7 @@ public static BackupManager start(LibraryTab libraryTab, BibDatabaseContext bibD
* @param bibDatabaseContext Associated {@link BibDatabaseContext}
*/
public static void discardBackup(BibDatabaseContext bibDatabaseContext, Path backupDir) {
runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.discardBackup(backupDir));
RUNNING_INSTANCES.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.discardBackup(backupDir));
}

/**
Expand All @@ -130,8 +131,8 @@ public static void discardBackup(BibDatabaseContext bibDatabaseContext, Path bac
* @param backupDir The path to the backup directory
*/
public static void shutdown(BibDatabaseContext bibDatabaseContext, Path backupDir, boolean createBackup) {
runningInstances.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.shutdown(backupDir, createBackup));
runningInstances.removeIf(instance -> instance.bibDatabaseContext == bibDatabaseContext);
RUNNING_INSTANCES.stream().filter(instance -> instance.bibDatabaseContext == bibDatabaseContext).forEach(backupManager -> backupManager.shutdown(backupDir, createBackup));
RUNNING_INSTANCES.removeIf(instance -> instance.bibDatabaseContext == bibDatabaseContext);
}

/**
Expand Down Expand Up @@ -268,6 +269,9 @@ void performBackup(Path backupPath) {
.map(BibEntry.class::cast)
.toList();
BibDatabase bibDatabaseClone = new BibDatabase(list);
bibDatabaseContext.getDatabase().getStringValues().stream().map(BibtexString::clone)
.map(BibtexString.class::cast)
.forEach(bibDatabaseClone::addString);
BibDatabaseContext bibDatabaseContextClone = new BibDatabaseContext(bibDatabaseClone, bibDatabaseContext.getMetaData());

Charset encoding = bibDatabaseContext.getMetaData().getEncoding().orElse(StandardCharsets.UTF_8);
Expand Down

0 comments on commit b4c48ef

Please sign in to comment.