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

Chris Ridd
02.00.2015 f63b8c6059974c45f34cdffef8fb72fb69fe23d3
CR-6056 fix OPENDJ-1764: admin-backend.ldif can end up empty
2 files modified
50 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/LDIFBackend.java 46 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/messages/org/opends/messages/backend.properties 4 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/LDIFBackend.java
@@ -251,21 +251,49 @@
      }
    }
    StaticUtils.close(writer);
    // Rename the existing "live" file out of the way and move the new file
    // into place.
    // On Linux the final write() on a file can actually fail but not throw an Exception.
    // The close() will throw an Exception in this case so we MUST check for Exceptions
    // here.
    try
    {
      if (oldFile.exists())
      {
        oldFile.delete();
      }
        writer.close();
    }
    catch (Exception e)
    {
      logger.traceException(e);
      LocalizableMessage m = ERR_LDIF_BACKEND_ERROR_CLOSING_FILE.get(
                       tempFile.getAbsolutePath(),
                       currentConfig.dn(),
                       stackTraceToSingleLineString(e));
      DirectoryServer.sendAlertNotification(this,
                           ALERT_TYPE_LDIF_BACKEND_CANNOT_WRITE_UPDATE, m);
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
                                   m, e);
    }
    // Extra sanity check
    if (!entryMap.isEmpty() && tempFile.exists() && tempFile.length() == 0)
    {
      LocalizableMessage m = ERR_LDIF_BACKEND_ERROR_EMPTY_FILE.get(
                       tempFile.getAbsolutePath(),
                       currentConfig.dn());
      DirectoryServer.sendAlertNotification(this,
                           ALERT_TYPE_LDIF_BACKEND_CANNOT_WRITE_UPDATE, m);
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), m);
    }
    if (tempFile.exists())
    {
      // Rename the existing "live" file out of the way and move the new file
      // into place.
      try
      {
        oldFile.delete();
      }
      catch (Exception e)
      {
        logger.traceException(e);
      }
    }
    try
opendj-server-legacy/src/messages/org/opends/messages/backend.properties
@@ -836,6 +836,10 @@
ERR_LDIF_BACKEND_ERROR_WRITING_FILE_346=An error occurred while \
 trying to write updated data to file %s for the LDIF backend defined in \
 configuration entry %s:  %s
ERR_LDIF_BACKEND_ERROR_CLOSING_FILE_426=An error occurred while trying to \
 close file %s for the LDIF backend defined in configuration entry %s:  %s
ERR_LDIF_BACKEND_ERROR_EMPTY_FILE_427=The file %s written for the LDIF backend \
 defined in configuration entry %s is 0 bytes long and unusable.
ERR_LDIF_BACKEND_ERROR_RENAMING_FILE_347=An error occurred while \
 attempting to rename file %s to %s while writing updated data for the LDIF \
 backend defined in configuration entry %s:  %s