From 348b156e4ab1f209b181d68698ec1068ed9a7277 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 18 Nov 2008 13:32:15 +0000
Subject: [PATCH] Fix for issue 3614 (control panel: restore fails when the available backup is a directory)
---
opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupListPanel.java | 66 ++++++++++++---------
opends/src/guitools/org/opends/guitools/controlpanel/ui/renderer/BackupTableCellRenderer.java | 46 ++++++++++++++-
opends/src/guitools/org/opends/guitools/controlpanel/ui/RestorePanel.java | 2
opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackupTableModel.java | 1
opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupPanel.java | 10 +++
5 files changed, 91 insertions(+), 34 deletions(-)
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackupTableModel.java b/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackupTableModel.java
index c25357c..ffa6e86 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackupTableModel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackupTableModel.java
@@ -40,6 +40,7 @@
private static final long serialVersionUID = -3511425157550147124L;
private ArrayList<BackupDescriptor> backups =
new ArrayList<BackupDescriptor>();
+
/**
* Clears the contents ot the table model.
*
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupListPanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupListPanel.java
index 1878bc5..ac6a741 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupListPanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupListPanel.java
@@ -57,7 +57,6 @@
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
-import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import org.opends.guitools.controlpanel.datamodel.BackupDescriptor;
@@ -139,6 +138,8 @@
*/
private boolean backupDirectoryInitialized;
+ private BackupTableCellRenderer renderer;
+
private static final Logger LOG =
Logger.getLogger(RestorePanel.class.getName());
@@ -246,7 +247,8 @@
ListSelectionModel.SINGLE_SELECTION);
backupList.setShowGrid(false);
backupList.setIntercellSpacing(new Dimension(0, 0));
- TableCellRenderer renderer = new BackupTableCellRenderer();
+ renderer = new BackupTableCellRenderer();
+ renderer.setParentPath(new File(DUMMY_PARENT_PATH));
for (int i=0; i<model.getColumnCount(); i++)
{
TableColumn col = backupList.getColumn(model.getColumnName(i));
@@ -341,6 +343,7 @@
lRefreshingList.setVisible(true);
final int lastSelectedRow = backupList.getSelectedRow();
+ final String parentPath = parentDirectory.getText();
BackgroundTask<Set<BackupInfo>> worker =
new BackgroundTask<Set<BackupInfo>>()
{
@@ -355,45 +358,48 @@
try
{
BackupDirectory backupDir =
- BackupDirectory.readBackupDirectoryDescriptor(
- parentDirectory.getText());
+ BackupDirectory.readBackupDirectoryDescriptor(parentPath);
backups.addAll(backupDir.getBackups().values());
}
catch (Throwable t)
{
firstThrowable = t;
- // Check the subdirectories
- File f = new File(parentDirectory.getText());
+ }
+ // Check the subdirectories
+ File f = new File(parentPath);
- if (f.isDirectory())
+ // Check the first level of directories (we might have done a backup
+ // of one backend and then a backup of several backends under the
+ // same directory).
+ if (f.isDirectory())
+ {
+ File[] children = f.listFiles();
+ for (int i=0; i<children.length; i++)
{
- File[] children = f.listFiles();
- for (int i=0; i<children.length; i++)
+ if (children[i].isDirectory())
{
- if (children[i].isDirectory())
+ try
{
- try
- {
- BackupDirectory backupDir =
- BackupDirectory.readBackupDirectoryDescriptor(
- children[i].getAbsolutePath());
+ BackupDirectory backupDir =
+ BackupDirectory.readBackupDirectoryDescriptor(
+ children[i].getAbsolutePath());
- backups.addAll(backupDir.getBackups().values());
- }
- catch (Throwable t2)
+ backups.addAll(backupDir.getBackups().values());
+ }
+ catch (Throwable t2)
+ {
+ if (!children[i].getName().equals("tasks") &&
+ (firstThrowable != null))
{
- if (!children[i].getName().equals("tasks"))
- {
- LOG.log(Level.WARNING, "Error searching backup: "+t2, t2);
- }
+ LOG.log(Level.WARNING, "Error searching backup: "+t2, t2);
}
}
}
}
- if (backups.size() == 0)
- {
- throw firstThrowable;
- }
+ }
+ if ((backups.size() == 0) && (firstThrowable != null))
+ {
+ throw firstThrowable;
}
return backups;
}
@@ -405,6 +411,7 @@
{
BackupTableModel model = (BackupTableModel)backupList.getModel();
model.clear();
+ renderer.setParentPath(new File(parentPath));
if (t == null)
{
if (returnValue.size() > 0)
@@ -482,6 +489,7 @@
worker.startBackgroundTask();
}
+ private final String DUMMY_PARENT_PATH = "/local/OpenDS-X.X.X/bak";
/**
* Creates a list with backup descriptor. This is done simply to have a good
* initial size for the table.
@@ -491,15 +499,15 @@
{
ArrayList<BackupDescriptor> list = new ArrayList<BackupDescriptor>();
list.add(new BackupDescriptor(
- new File("/local/OpenDS-0.9.0/bak/200704201567Z"),
+ new File(DUMMY_PARENT_PATH+"/200704201567Z"),
new GregorianCalendar(2007, 5, 20, 8, 10).getTime(),
BackupDescriptor.Type.FULL, "id"));
list.add(new BackupDescriptor(
- new File("/local/OpenDS-0.9.0/bak/200704201567Z"),
+ new File(DUMMY_PARENT_PATH+"/200704201567Z"),
new GregorianCalendar(2007, 5, 22, 8, 10).getTime(),
BackupDescriptor.Type.INCREMENTAL, "id"));
list.add(new BackupDescriptor(
- new File("/local/OpenDS-0.9.0/bak/200704221567Z"),
+ new File(DUMMY_PARENT_PATH+"/200704221567Z"),
new GregorianCalendar(2007, 5, 25, 8, 10).getTime(),
BackupDescriptor.Type.INCREMENTAL, "id"));
return list;
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupPanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupPanel.java
index 7007366..0aee3cd 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupPanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupPanel.java
@@ -602,7 +602,15 @@
}
}
}
- dir = parentDirectory.getText();
+ if (incrementalBackup.isSelected())
+ {
+ BackupDescriptor backup = getSelectedBackup();
+ dir = backup.getPath().getAbsolutePath();
+ }
+ else
+ {
+ dir = parentDirectory.getText();
+ }
}
/**
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/RestorePanel.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/RestorePanel.java
index 8a6ff67..358d602 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/RestorePanel.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/RestorePanel.java
@@ -312,8 +312,8 @@
{
super(info, dlg);
this.verify = verify;
- dir = parentDirectory.getText();
BackupDescriptor backup = getSelectedBackup();
+ dir = backup.getPath().getAbsolutePath();
backupID = backup.getID();
backendSet = new HashSet<String>();
for (BackendDescriptor backend : info.getServerDescriptor().getBackends())
diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/ui/renderer/BackupTableCellRenderer.java b/opends/src/guitools/org/opends/guitools/controlpanel/ui/renderer/BackupTableCellRenderer.java
index b4f3c3a..4015dfd 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/ui/renderer/BackupTableCellRenderer.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/ui/renderer/BackupTableCellRenderer.java
@@ -51,6 +51,7 @@
{
private static final long serialVersionUID = -4645902129785751854L;
private DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL);
+ private File backupParentPath;
private final static Border fullBorder = BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(1, 0, 0, 0,
ColorAndFontConstants.gridColor),
@@ -68,6 +69,16 @@
setBackground(ColorAndFontConstants.tableBackground);
}
+
+ /**
+ * Sets the path to which the backups are relative.
+ * @param backupParentPath the path to which the backups are relative.
+ */
+ public void setParentPath(File backupParentPath)
+ {
+ this.backupParentPath = backupParentPath;
+ }
+
/**
* {@inheritDoc}
*/
@@ -80,10 +91,39 @@
== BackupDescriptor.Type.FULL;
if (value instanceof File)
{
- s = "..."+File.separator+((File)value).getName();
- if (!isFull)
+ File f = (File)value;
+ s = "";
+ boolean isParent = false;
+ while (f != null)
{
- s = " "+s;
+ if (!f.equals(backupParentPath))
+ {
+ if (s.length() == 0)
+ {
+ s = f.getName();
+ }
+ else
+ {
+ s = f.getName() + File.separator + s;
+ }
+ }
+ else
+ {
+ isParent = true;
+ break;
+ }
+ f = f.getParentFile();
+ }
+ if (isParent)
+ {
+ if (!isFull)
+ {
+ s = " "+s;
+ }
+ }
+ else
+ {
+ s = value.toString();
}
}
else if (value instanceof Date)
--
Gitblit v1.10.0