Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backups: handle discarded changes v1 #9441

Closed
wants to merge 1 commit into from

Conversation

mmohanb1
Copy link

@mmohanb1 mmohanb1 commented Dec 11, 2022

Fix #9361

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@HoussemNasri
Copy link
Member

Hello! Welcome to JabRef!

I have read through the changes made in this PR and I'm not entirely sure what is the underlying issue you are addressing here. If you could provide more information or context, that would be great. If this PR is in response to an issue that's already been reported, please include a link to the issue in the PR description. If this is a new issue, please describe it here and mention your motivations for addressing it.

@calixtus calixtus marked this pull request as draft December 11, 2022 22:34
@calixtus calixtus added the status: waiting-for-feedback The submitter or other users need to provide more information about the issue label Dec 11, 2022
@ThiloteE ThiloteE added component: export-or-save component: backup and removed status: waiting-for-feedback The submitter or other users need to provide more information about the issue component: export-or-save labels Dec 12, 2022
@koppor koppor added this to the v5.8 milestone Dec 12, 2022
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through the PR. Have some minor comments.

Please also fix the checkstyle issues.

Then, we can continue thinking whether the whole algorithm works.

I miss test cases.

Comment on lines +1 to +7
@Article{,
author = {Test1-abc},
title = {Test1},
month = may,
}

@Comment{jabref-meta: databaseType:bibtex;}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path of the file is very strange. I think you accidently commited the file and it should not be part of the PR?

Comment on lines +1211 to +1212
String backUpPath = BackupFileUtil.getPathOfLatestExisingBackupFile(directory, BackupFileType.BACKUP).map(Path::toString).
orElse(Localization.lang("File not found"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should not be a file File not found be created.

@@ -189,7 +198,8 @@ private Optional<Path> determineBackupPathForNewBackup() {
* @param backupPath the path where the library should be backed up to
*/
private void performBackup(Path backupPath) {
if (!needsBackup) {

if (!needsBackup || discardedFileExists) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the check here? A backup should be performed regardless of the discared file. The discarded file was of the last JabRef run.


Path directory = Path.of(filename);
try {
SaveDatabaseAction saveAction = new SaveDatabaseAction(libraryTab, prefs, Globals.entryTypesManager);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do NOT Call UI methods for saving. The logic for creating a --discared file should be in the BackupManager. You can see the saving at org.jabref.logic.autosaveandbackup.BackupManager#performBackup.

As written in #9361 (comment), it really should be done in BackupManager.

Comment on lines +1215 to +1218
if (saveAction.saveAs(Path.of(backUpPath))) {
BackupManager.setDiscardedFileExists(true);
return true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, you misunderstood the user interaction of JabRef.

  1. User starts JabRef
  2. User opens a file demo.bib
  3. User changes file demo.bib for 10 minutes (and does not save)
  4. User closes file.
  5. JabRef diplays "File changed dialog"
  6. User selects "Discard changes"
  7. User opens the file demo.bib again
  8. JabRef should NOT prompt for restoring backup

In the code at hand, sets the flag after step 7, but not at step 8, where it is needed.

@koppor
Copy link
Member

koppor commented Dec 16, 2022

Superseeded by #9457

@koppor koppor closed this Dec 16, 2022
@ThiloteE ThiloteE changed the title Additional code to handle discarded changes Backups: handle discarded changes Dec 20, 2022
@ThiloteE ThiloteE changed the title Backups: handle discarded changes Backups: handle discarded changes v1 Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Discard changes" in "Save before closing" should delete "newer" backups
5 participants