Author: tolusha
Date: 2011-10-04 07:52:31 -0400 (Tue, 04 Oct 2011)
New Revision: 5019
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java
Log:
EXOJCR-1565: backward compatibility
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java 2011-10-04
09:58:19 UTC (rev 5018)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java 2011-10-04
11:52:31 UTC (rev 5019)
@@ -131,7 +131,14 @@
try
{
- DirectoryHelper.uncompressDirectory(zipFile, dataDir);
+ if (PrivilegedFileHelper.isDirectory(zipFile))
+ {
+ DirectoryHelper.uncompressEveryFileFromDirectory(zipFile, dataDir);
+ }
+ else
+ {
+ DirectoryHelper.uncompressDirectory(zipFile, dataDir);
+ }
}
catch (IOException e)
{
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2011-10-04
09:58:19 UTC (rev 5018)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2011-10-04
11:52:31 UTC (rev 5019)
@@ -1615,14 +1615,22 @@
{
File zipFile = new File((File)context.getObject(DataRestoreContext.STORAGE_DIR),
getStorageName() + ".zip");
- if (!PrivilegedFileHelper.exists(zipFile))
+ if (PrivilegedFileHelper.exists(zipFile))
{
- throw new RepositoryConfigurationException("Can't restore index.
File " + zipFile.getName()
- + " doesn't exists");
+ return new DirectoryRestore(getIndexDirectory(), zipFile);
}
else
{
- return new DirectoryRestore(getIndexDirectory(), zipFile);
+ // try to check if we have deal with old backup format
+ zipFile = new File((File)context.getObject(DataRestoreContext.STORAGE_DIR),
getStorageName());
+ if (PrivilegedFileHelper.exists(zipFile))
+ {
+ return new DirectoryRestore(getIndexDirectory(), zipFile);
+ }
+ else
+ {
+ throw new BackupException("There is no backup data for index");
+ }
}
}
catch (RepositoryConfigurationException e)
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-10-04
09:58:19 UTC (rev 5018)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-10-04
11:52:31 UTC (rev 5019)
@@ -73,7 +73,6 @@
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
@@ -1304,56 +1303,40 @@
restorers.add(new DBRestore(storageDir, jdbcConn, tables, wsConfig,
swapCleaner));
}
-
- // prepare value storage restorer
- List<ValueStorageEntry> valueStorages =
wsConfig.getContainer().getValueStorages();
- String[] valueStoragesFiles = PrivilegedFileHelper.list(storageDir, new
FilenameFilter()
- {
- public boolean accept(File dir, String name)
- {
- return name.startsWith("values-") &&
name.endsWith(".zip");
- }
- });
-
if (wsConfig.getContainer().getValueStorages() != null)
{
List<File> dataDirs = new ArrayList<File>();
List<File> backupDirs = new ArrayList<File>();
- if ((valueStoragesFiles == null && valueStorages.size() != 0)
- || (valueStoragesFiles != null && valueStoragesFiles.length !=
valueStorages.size()))
- {
- throw new RepositoryConfigurationException("Workspace configuration
[" + wsConfig.getName()
- + "] has a different amount of value storages than exist in
backup");
- }
-
+ List<ValueStorageEntry> valueStorages =
wsConfig.getContainer().getValueStorages();
for (ValueStorageEntry valueStorage : valueStorages)
{
+ File dataDir = new
File(valueStorage.getParameterValue(FileValueStorage.PATH));
+ dataDirs.add(dataDir);
+
File zipFile = new File(storageDir, "values-" +
valueStorage.getId() + ".zip");
- if (!PrivilegedFileHelper.exists(zipFile))
+ if (PrivilegedFileHelper.exists(zipFile))
{
- throw new RepositoryConfigurationException("Can't restore
value storage. File " + zipFile.getName()
- + " doesn't exists");
+ backupDirs.add(zipFile);
}
else
{
- File dataDir = new
File(valueStorage.getParameterValue(FileValueStorage.PATH));
-
- dataDirs.add(dataDir);
- backupDirs.add(zipFile);
+ // try to check if we have deal with old backup format
+ zipFile = new File(storageDir, "values/" +
valueStorage.getId());
+ if (PrivilegedFileHelper.exists(zipFile))
+ {
+ backupDirs.add(zipFile);
+ }
+ else
+ {
+ throw new RepositoryConfigurationException("There is no backup
data for value storage with id "
+ + valueStorage.getId());
+ }
}
}
restorers.add(new DirectoryRestore(dataDirs, backupDirs));
}
- else
- {
- if (valueStoragesFiles != null && valueStoragesFiles.length != 0)
- {
- throw new RepositoryConfigurationException("Value storage didn't
configure in workspace ["
- + wsConfig.getName() + "] configuration but value storage backup
files exist");
- }
- }
return new ComplexDataRestore(restorers);
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java 2011-10-04
09:58:19 UTC (rev 5018)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java 2011-10-04
11:52:31 UTC (rev 5019)
@@ -236,9 +236,7 @@
}
/**
- * Uncompress data to the destination directory. If
<code>srcZipPath</code> is the directory we assume
- * that every file in the directory is compressed, in other case
<code>srcZipPath</code> should contain
- * the compress data.
+ * Uncompress data to the destination directory.
*
* @param srcZipPath
* path to the compressed file, could be the file or the directory
@@ -249,55 +247,54 @@
*/
public static void uncompressDirectory(File srcZipPath, File dstDirPath) throws
IOException
{
- if (PrivilegedFileHelper.isDirectory(srcZipPath))
- {
- uncompressEveryFileInDirectory(srcZipPath, dstDirPath);
- }
- else
- {
+ ZipInputStream in = PrivilegedFileHelper.zipInputStream(srcZipPath);
+ ZipEntry entry = null;
- ZipInputStream in = PrivilegedFileHelper.zipInputStream(srcZipPath);
- ZipEntry entry = null;
-
- try
+ try
+ {
+ while ((entry = in.getNextEntry()) != null)
{
- while ((entry = in.getNextEntry()) != null)
- {
- File dstFile = new File(dstDirPath, entry.getName());
- PrivilegedFileHelper.mkdirs(dstFile.getParentFile());
+ File dstFile = new File(dstDirPath, entry.getName());
+ PrivilegedFileHelper.mkdirs(dstFile.getParentFile());
- if (entry.isDirectory())
+ if (entry.isDirectory())
+ {
+ PrivilegedFileHelper.mkdirs(dstFile);
+ }
+ else
+ {
+ OutputStream out = PrivilegedFileHelper.fileOutputStream(dstFile);
+ try
{
- PrivilegedFileHelper.mkdirs(dstFile);
+ transfer(in, out);
}
- else
+ finally
{
- OutputStream out = PrivilegedFileHelper.fileOutputStream(dstFile);
- try
- {
- transfer(in, out);
- }
- finally
- {
- out.close();
- }
+ out.close();
}
}
}
- finally
+ }
+ finally
+ {
+ if (in != null)
{
- if (in != null)
- {
- in.close();
- }
+ in.close();
}
}
}
/**
- * Uncompress data in case when every file in the directory is compressed.
+ * Uncompress data to the destination directory.
+ *
+ * @param srcZipPath
+ * path to the compressed file, could be the file or the directory
+ * @param dstDirPath
+ * destination path
+ * @throws IOException
+ * if any exception occurred
*/
- private static void uncompressEveryFileInDirectory(File srcPath, File dstPath) throws
IOException
+ public static void uncompressEveryFileFromDirectory(File srcPath, File dstPath) throws
IOException
{
if (PrivilegedFileHelper.isDirectory(srcPath))
{
@@ -309,7 +306,7 @@
String files[] = PrivilegedFileHelper.list(srcPath);
for (int i = 0; i < files.length; i++)
{
- uncompressEveryFileInDirectory(new File(srcPath, files[i]), new File(dstPath,
files[i]));
+ uncompressEveryFileFromDirectory(new File(srcPath, files[i]), new
File(dstPath, files[i]));
}
}
else