From 2b48ed4d7ff1accde1eb21a1e1afe5ab553fd7d0 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Thu, 18 Jan 2007 23:17:42 +0000
Subject: [PATCH] Fix issue where backups of an empty backend would fail. Added a placeholder file in the zip stream if the backend is empty. On restore, this file will not be restored.

---
 opends/src/server/org/opends/server/backends/jeb/BackupManager.java |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/jeb/BackupManager.java b/opends/src/server/org/opends/server/backends/jeb/BackupManager.java
index 1eaf9e7..483cb48 100644
--- a/opends/src/server/org/opends/server/backends/jeb/BackupManager.java
+++ b/opends/src/server/org/opends/server/backends/jeb/BackupManager.java
@@ -108,6 +108,12 @@
   public static final String ZIPENTRY_UNCHANGED_LOGFILES = "unchanged.txt";
 
   /**
+   * The name of a dummy entry in the backup archive file that will act
+   * as a placeholder in case a backup is done on an empty backend.
+   */
+  public static final String ZIPENTRY_EMPTY_PLACEHOLDER = "empty.placeholder";
+
+  /**
    * The fully-qualified name of this class for debugging purposes.
    */
   private static final String CLASS_NAME =
@@ -436,7 +442,27 @@
       message = getMessage(msgID, backendDir.getAbsolutePath(),
                            stackTraceToSingleLineString(e));
       throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
-                                   message, msgID, e);
+          message, msgID, e);
+    }
+
+    // Check to see if backend is empty. If so, insert placeholder entry into
+    // archive
+    if(logFiles.length <= 0)
+    {
+      try
+      {
+        ZipEntry emptyPlaceholder = new ZipEntry(ZIPENTRY_EMPTY_PLACEHOLDER);
+        zipStream.putNextEntry(emptyPlaceholder);
+      }
+      catch (IOException e)
+      {
+        assert debugException(CLASS_NAME, "createBackup", e);
+        msgID   = MSGID_JEB_BACKUP_CANNOT_WRITE_ARCHIVE_FILE;
+        message = getMessage(msgID, ZIPENTRY_EMPTY_PLACEHOLDER,
+            stackTraceToSingleLineString(e));
+        throw new DirectoryException(
+            DirectoryServer.getServerErrorResultCode(), message, msgID, e);
+      }
     }
 
     // Sort the log files from oldest to youngest since this is the order
@@ -988,6 +1014,15 @@
     {
       String name = zipEntry.getName();
 
+      if (name.equals(ZIPENTRY_EMPTY_PLACEHOLDER))
+      {
+        // This entry is treated specially to indicate a backup of an empty
+        // backend was attempted.
+
+        zipEntry = zipStream.getNextEntry();
+        continue;
+      }
+
       if (name.equals(ZIPENTRY_UNCHANGED_LOGFILES))
       {
         // This entry is treated specially. It is never restored,

--
Gitblit v1.10.0