mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
7 hours ago e24c2780b6d44c7e5d386e70a1fb3346149ccdc9
opendj-server-legacy/src/main/java/org/opends/server/util/BackupManager.java
@@ -20,6 +20,7 @@
import static java.util.Collections.*;
import static org.opends.messages.BackendMessages.*;
import static org.opends.messages.CoreMessages.ERR_BACKUPINFO_CANNOT_DECODE;
import static org.opends.messages.UtilityMessages.*;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -515,7 +516,7 @@
    private final NewBackupParams newBackupParams;
    private final CryptoEngine cryptoEngine;
    NewBackupArchive(String backendID, NewBackupParams backupParams, CryptoEngine crypt)
    NewBackupArchive(String backendID, NewBackupParams backupParams, CryptoEngine crypt) throws DirectoryException
    {
      this.backendID = backendID;
      this.newBackupParams = backupParams;
@@ -525,11 +526,26 @@
      {
        Map<String, String> properties = backupParams.baseBackupInfo.getBackupProperties();
        latestFileName = properties.get(PROPERTY_LAST_LOGFILE_NAME);
        latestFileSize = Long.parseLong(properties.get(PROPERTY_LAST_LOGFILE_SIZE));
        latestFileSize = parseLatestFileSize(backupParams, properties.get(PROPERTY_LAST_LOGFILE_SIZE));
      }
      archiveFilename = BACKUP_BASE_FILENAME + backendID + "-" +  backupParams.backupID;
    }
    /** Returns the size recorded by the base backup for the last file it archived. */
    private static long parseLatestFileSize(NewBackupParams backupParams, String size) throws DirectoryException
    {
      try
      {
        return Long.parseLong(size);
      }
      catch (NumberFormatException e)
      {
        throw new DirectoryException(DirectoryServer.getCoreConfigManager().getServerErrorResultCode(),
            ERR_BACKUPINFO_CANNOT_DECODE.get(backupParams.backupDir.getPath(),
                PROPERTY_LAST_LOGFILE_SIZE + ": " + size), e);
      }
    }
    String getArchiveFilename()
    {
      return archiveFilename;
@@ -1553,7 +1569,7 @@
  {
    final File baseFile = new File(basePath).getCanonicalFile();
    final File[] existingFiles = baseFile.getParentFile().listFiles();
    final Pattern pattern = Pattern.compile(baseFile + "\\d*");
    final Pattern pattern = Pattern.compile(Pattern.quote(baseFile.getPath()) + "\\d*");
    int highestNumber = 0;
    for (File file : existingFiles)
    {
@@ -1561,10 +1577,32 @@
      if (pattern.matcher(name).matches())
      {
        String numberAsString = name.substring(baseFile.getPath().length());
        int number = numberAsString.isEmpty() ? 0 : Integer.valueOf(numberAsString);
        int number = parseSuffixNumber(numberAsString);
        highestNumber = number > highestNumber ? number : highestNumber;
      }
    }
    return highestNumber;
  }
  /**
   * Returns the number held by the provided file name suffix, or 0 if the suffix is empty or holds a
   * number which is too big to have been generated by this class.
   */
  private static int parseSuffixNumber(final String numberAsString)
  {
    if (numberAsString.isEmpty())
    {
      return 0;
    }
    try
    {
      return Integer.parseInt(numberAsString);
    }
    catch (NumberFormatException e)
    {
      logger.trace("Ignoring file suffix \"%s\" which is too big to have been generated by this class",
          numberAsString);
      return 0;
    }
  }
}