Verified Owner
Top Fields Constructors Methods
org.jabref.logic.util.io

public Class BackupFileUtil

extends Object
Class Inheritance
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.file.Files, .Path, java.time.ZonedDateTime, java.time.format.DateTimeFormatter, java.util.HexFormat, .List, .Optional, java.util.stream.Stream, org.jabref.logic.util.BackupFileType, org.slf4j.Logger, .LoggerFactory

Field Summary

Modifier and TypeField and Description
private static final Logger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static Path
public static List<Path>
getExistingBackupFiles(Path targetFile, Path backupDir)

Lists the existing backups of the given library, oldest first.

public static Path
getPathForNewBackupFileAndCreateDirectory(Path targetFile, BackupFileType fileType, Path backupDir)

Determines the path of a new backup file (using the given extension)

The file is named <unique prefix>--<library file name>--<timestamp>.

public static Optional<Path>
getPathOfLatestExistingBackupFile(Path targetFile, Path backupDir)

Determines the most recent existing backup of the given library, see getExistingBackupFiles.

public static String
getUniqueFilePrefix(Path targetFile)

Determines a unique file prefix.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

BackupFileUtilback to summary
private BackupFileUtil()

Method Detail

getDirectoryOfLibraryback to summary
private static Path getDirectoryOfLibrary(Path targetFile)
getExistingBackupFilesback to summary
public static List<Path> getExistingBackupFiles(Path targetFile, Path backupDir)

Lists the existing backups of the given library, oldest first. Name order is time order, because of the timestamp in the file name.

In case there is no backup directory, the directory of the library is searched, because that is where getPathForNewBackupFileAndCreateDirectory places backups then.

getPathForNewBackupFileAndCreateDirectoryback to summary
public static Path getPathForNewBackupFileAndCreateDirectory(Path targetFile, BackupFileType fileType, Path backupDir)

Determines the path of a new backup file (using the given extension)

The file is named <unique prefix>--<library file name>--<timestamp>.<extension> and placed in the backup directory.

SIDE EFFECT: Creates the directory. In case that fails, the backup is placed next to the library — still with the same name pattern, so it can never collide with (and overwrite) the library file itself.

Note that this backup is different from the .sav file generated by org.jabref.logic.exporter.AtomicFileOutputStream while saving

getPathOfLatestExistingBackupFileback to summary
public static Optional<Path> getPathOfLatestExistingBackupFile(Path targetFile, Path backupDir)

Determines the most recent existing backup of the given library, see getExistingBackupFiles.

getUniqueFilePrefixback to summary
public static String getUniqueFilePrefix(Path targetFile)

Determines a unique file prefix.

When creating a backup file, the backup file should belong to the original file. Just adding a suffix to the filename, does not work in all cases: It may be possible that the user has opened "paper.bib" twice. Thus, we need to create a unique prefix to distinguish these files.