[exo-jcr-commits] exo-jcr SVN: r5572 - in jcr/branches/1.15.x: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config and 8 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Feb 7 05:35:57 EST 2012


Author: andrew.plotnikov
Date: 2012-02-07 05:35:56 -0500 (Tue, 07 Feb 2012)
New Revision: 5572

Added:
   jcr/branches/1.15.x/exo.jcr.component.ext/src/test/resources/tsm-excludes.properties
Modified:
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecoveryImpl.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/CASableWriteValue.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java
   jcr/branches/1.15.x/exo.jcr.component.core/src/test/resources/tsm-excludes.properties
   jcr/branches/1.15.x/exo.jcr.component.ext/pom.xml
Log:
EXOJCR-1576: Adapted eXo JCR to GlusterFS

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java	2012-02-07 08:05:23 UTC (rev 5571)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/backup/rdbms/DirectoryRestore.java	2012-02-07 10:35:56 UTC (rev 5572)
@@ -16,8 +16,8 @@
  */
 package org.exoplatform.services.jcr.impl.backup.rdbms;
 
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
 import org.exoplatform.commons.utils.PrivilegedSystemHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.services.jcr.impl.backup.BackupException;
 import org.exoplatform.services.jcr.impl.backup.DataRestore;
 import org.exoplatform.services.jcr.impl.util.io.DirectoryHelper;
@@ -27,6 +27,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -96,27 +97,35 @@
     */
    public void clean() throws BackupException
    {
-      for (int i = 0; i < dataDirs.size(); i++)
+      try
       {
-         File dataDir = dataDirs.get(i);
-
-         try
+         SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
          {
-            File tmpDir = new File(tempDir, PREFIX + IdGenerator.generate());
-            PrivilegedFileHelper.mkdirs(tmpDir);
-            tmpDirs.add(tmpDir);
+            public Void run() throws IOException
+            {
+               for (int i = 0; i < dataDirs.size(); i++)
+               {
+                  File dataDir = dataDirs.get(i);
 
-            if (PrivilegedFileHelper.exists(dataDir))
-            {
-               DirectoryHelper.copyDirectory(dataDir, tmpDir);
-               DirectoryHelper.removeDirectory(dataDir);
+                  File tmpDir = new File(tempDir, PREFIX + IdGenerator.generate());
+                  tmpDir.mkdirs();
+                  tmpDirs.add(tmpDir);
+
+                  if (dataDir.exists())
+                  {
+                     DirectoryHelper.copyDirectory(dataDir, tmpDir);
+                     DirectoryHelper.removeDirectory(dataDir);
+                  }
+               }
+
+               return null;
             }
-         }
-         catch (IOException e)
-         {
-            throw new BackupException(e);
-         }
+         });
       }
+      catch (IOException e)
+      {
+         throw new BackupException(e);
+      }
    }
 
    /**
@@ -124,27 +133,37 @@
     */
    public void restore() throws BackupException
    {
-      for (int i = 0; i < zipFiles.size(); i++)
+      try
       {
-         File zipFile = zipFiles.get(i);
-         File dataDir = dataDirs.get(i);
-
-         try
+         SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
          {
-            if (PrivilegedFileHelper.isDirectory(zipFile))
+            public Void run() throws IOException
             {
-               DirectoryHelper.uncompressEveryFileFromDirectory(zipFile, dataDir);
+
+               for (int i = 0; i < zipFiles.size(); i++)
+               {
+                  File zipFile = zipFiles.get(i);
+                  File dataDir = dataDirs.get(i);
+
+                  if (zipFile.isDirectory())
+                  {
+                     DirectoryHelper.uncompressEveryFileFromDirectory(zipFile, dataDir);
+                  }
+                  else
+                  {
+                     DirectoryHelper.uncompressDirectory(zipFile, dataDir);
+                  }
+               }
+
+               return null;
             }
-            else
-            {
-               DirectoryHelper.uncompressDirectory(zipFile, dataDir);
-            }
-         }
-         catch (IOException e)
-         {
-            throw new BackupException(e);
-         }
+         });
+
       }
+      catch (IOException e)
+      {
+         throw new BackupException(e);
+      }
    }
 
    /**
@@ -159,25 +178,33 @@
     */
    public void rollback() throws BackupException
    {
-      for (int i = 0; i < tmpDirs.size(); i++)
+      try
       {
-         try
+         SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
          {
-            File tmpDir = tmpDirs.get(i);
-            File dataDir = dataDirs.get(i);
+            public Void run() throws IOException
+            {
+               for (int i = 0; i < tmpDirs.size(); i++)
+               {
+                  File tmpDir = tmpDirs.get(i);
+                  File dataDir = dataDirs.get(i);
 
-            if (PrivilegedFileHelper.exists(dataDir))
-            {
-               DirectoryHelper.removeDirectory(dataDir);
+                  if (dataDir.exists())
+                  {
+                     DirectoryHelper.removeDirectory(dataDir);
+                  }
+
+                  DirectoryHelper.copyDirectory(tmpDir, dataDir);
+               }
+
+               return null;
             }
-
-            DirectoryHelper.copyDirectory(tmpDir, dataDir);
-         }
-         catch (IOException e)
-         {
-            throw new BackupException(e);
-         }
+         });
       }
+      catch (IOException e)
+      {
+         throw new BackupException(e);
+      }
    }
 
    /**
@@ -185,17 +212,25 @@
     */
    public void close() throws BackupException
    {
-      for (File tmpDir : tmpDirs)
+      try
       {
-         try
+         SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
          {
-            DirectoryHelper.removeDirectory(tmpDir);
-         }
-         catch (IOException e)
-         {
-            throw new BackupException(e);
-         }
+            public Void run() throws IOException
+            {
+               for (File tmpDir : tmpDirs)
+               {
+                  DirectoryHelper.removeDirectory(tmpDir);
+               }
+
+               return null;
+            }
+         });
       }
+      catch (IOException e)
+      {
+         throw new BackupException(e);
+      }
 
       dataDirs.clear();
       zipFiles.clear();

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java	2012-02-07 08:05:23 UTC (rev 5571)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java	2012-02-07 10:35:56 UTC (rev 5572)
@@ -174,17 +174,25 @@
          else
          {
             URL filePath = configurationService.getURL(param.getValue());
-            File sourceConfig = new File(filePath.toURI());
+            final File sourceConfig = new File(filePath.toURI());
             SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
-            File backUp = new File(sourceConfig.getAbsoluteFile() + "_" + format.format(new Date()));
+            final File backUp = new File(sourceConfig.getAbsoluteFile() + "_" + format.format(new Date()));
+            
             try
             {
-               DirectoryHelper.renameFile(sourceConfig, backUp);
+               SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
+               {
+                  public Void run() throws IOException
+                  {
+                     DirectoryHelper.renameFile(sourceConfig, backUp);
+                     return null;
+                  }
+               });
             }
             catch (IOException ioe)
             {
                throw new RepositoryException("Can't back up configuration on path "
-                        + PrivilegedFileHelper.getAbsolutePath(sourceConfig), ioe);
+                  + PrivilegedFileHelper.getAbsolutePath(sourceConfig), ioe);
             }
 
             saveStream = PrivilegedFileHelper.fileOutputStream(sourceConfig);

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecoveryImpl.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecoveryImpl.java	2012-02-07 08:05:23 UTC (rev 5571)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexRecoveryImpl.java	2012-02-07 10:35:56 UTC (rev 5572)
@@ -16,7 +16,7 @@
  */
 package org.exoplatform.services.jcr.impl.core.query;
 
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
+import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
 import org.exoplatform.services.jcr.impl.core.query.lucene.OfflinePersistentIndex;
 import org.exoplatform.services.jcr.impl.util.io.DirectoryHelper;
@@ -33,6 +33,7 @@
 import java.io.InputStream;
 import java.io.RandomAccessFile;
 import java.io.Serializable;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -140,21 +141,27 @@
 
          public Serializable execute(Serializable[] args) throws Throwable
          {
-            int indexDirLen = PrivilegedFileHelper.getAbsolutePath(indexDirectory).length();
-
-            ArrayList<String> result = new ArrayList<String>();
-            for (File file : DirectoryHelper.listFiles(indexDirectory))
+            return SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<ArrayList<String>>()
             {
-               if (!file.isDirectory())
+               public ArrayList<String> run() throws IOException
                {
-                  // if parent directory is not "offline" then add this file. Otherwise skip it.
-                  if (!file.getParent().endsWith(OfflinePersistentIndex.NAME))
+                  int indexDirLen = indexDirectory.getAbsolutePath().length();
+
+                  ArrayList<String> result = new ArrayList<String>();
+                  for (File file : DirectoryHelper.listFiles(indexDirectory))
                   {
-                     result.add(PrivilegedFileHelper.getAbsolutePath(file).substring(indexDirLen));
+                     if (!file.isDirectory())
+                     {
+                        // if parent directory is not "offline" then add this file. Otherwise skip it.
+                        if (!file.getParent().endsWith(OfflinePersistentIndex.NAME))
+                        {
+                           result.add(file.getAbsolutePath().substring(indexDirLen));
+                        }
+                     }
                   }
+                  return result;
                }
-            }
-            return result;
+            });
          }
       });
 

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java	2012-02-07 08:05:23 UTC (rev 5571)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java	2012-02-07 10:35:56 UTC (rev 5572)
@@ -21,9 +21,9 @@
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.WildcardQuery;
+import org.exoplatform.commons.utils.ClassLoading;
 import org.exoplatform.commons.utils.PrivilegedFileHelper;
 import org.exoplatform.commons.utils.SecurityHelper;
-import org.exoplatform.commons.utils.ClassLoading;
 import org.exoplatform.container.ExoContainerContext;
 import org.exoplatform.container.configuration.ConfigurationManager;
 import org.exoplatform.management.annotations.Managed;
@@ -1623,7 +1623,17 @@
    {
       try
       {
-         DirectoryHelper.removeDirectory(getIndexDirectory());
+         final File indexDir = getIndexDirectory();
+
+         SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
+         {
+            public Void run() throws IOException
+            {
+               DirectoryHelper.removeDirectory(indexDir);
+
+               return null;
+            }
+         });
       }
       catch (IOException e)
       {
@@ -1638,22 +1648,30 @@
    /**
     * {@inheritDoc}}
     */
-   public void backup(File storageDir) throws BackupException
+   public void backup(final File storageDir) throws BackupException
    {
       try
       {
-         File indexDir = getIndexDirectory();
+         final File indexDir = getIndexDirectory();
 
-         if (!PrivilegedFileHelper.exists(indexDir))
+         SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
          {
-            throw new BackupException("Can't backup index. Directory "
-               + PrivilegedFileHelper.getCanonicalPath(indexDir) + " doesn't exists");
-         }
-         else
-         {
-            File destZip = new File(storageDir, getStorageName() + ".zip");
-            DirectoryHelper.compressDirectory(indexDir, destZip);
-         }
+            public Void run() throws IOException
+            {
+               if (!indexDir.exists())
+               {
+                  throw new IOException("Can't backup index. Directory " + indexDir.getCanonicalPath()
+                     + " doesn't exists");
+               }
+               else
+               {
+                  File destZip = new File(storageDir, getStorageName() + ".zip");
+                  DirectoryHelper.compressDirectory(indexDir, destZip);
+               }
+
+               return null;
+            }
+         });
       }
       catch (RepositoryConfigurationException e)
       {

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java	2012-02-07 08:05:23 UTC (rev 5571)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/directory/FSDirectoryManager.java	2012-02-07 10:35:56 UTC (rev 5572)
@@ -22,6 +22,7 @@
 import org.exoplatform.commons.utils.PropertyManager;
 import org.exoplatform.commons.utils.SecurityHelper;
 import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
+import org.exoplatform.services.jcr.impl.util.io.DirectoryHelper;
 
 import java.io.File;
 import java.io.FileFilter;
@@ -221,15 +222,27 @@
     */
    public boolean rename(final String from, final String to)
    {
-      return SecurityHelper.doPrivilegedAction(new PrivilegedAction<Boolean>()
+      final File src = new File(baseDir, from);
+      final File dest = new File(baseDir, to);
+
+      try
       {
-         public Boolean run()
+         SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
          {
-            File src = new File(baseDir, from);
-            File dest = new File(baseDir, to);
-            return src.renameTo(dest);
-         }
-      });
+            public Void run() throws IOException
+            {
+               DirectoryHelper.renameFile(src, dest);
+
+               return null;
+            }
+         });
+      }
+      catch (IOException e)
+      {
+         return false;
+      }
+
+      return true;
    }
 
    /**

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java	2012-02-07 08:05:23 UTC (rev 5571)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java	2012-02-07 10:35:56 UTC (rev 5572)
@@ -110,8 +110,8 @@
    /**
     * Indicates if the statistics has to be enabled.
     */
-   public static final boolean STATISTICS_ENABLED =
-      Boolean.valueOf(PrivilegedSystemHelper.getProperty("JDBCWorkspaceDataContainer.statistics.enabled"));
+   public static final boolean STATISTICS_ENABLED = Boolean.valueOf(PrivilegedSystemHelper
+      .getProperty("JDBCWorkspaceDataContainer.statistics.enabled"));
 
    static
    {
@@ -486,8 +486,8 @@
       // by default
       if (dbSourceName != null)
       {
-         return new GenericConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider, maxBufferSize,
-            swapDirectory, swapCleaner);
+         return new GenericConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider,
+            maxBufferSize, swapDirectory, swapCleaner);
       }
 
       return new GenericConnectionFactory(dbDriver, dbUrl, dbUserName, dbPassword, containerName, multiDb,
@@ -537,8 +537,8 @@
          }
 
          // MULTIDB
-         if (!wsEntry.getContainer().getParameterValue(MULTIDB).equals(
-            wsConfig.getContainer().getParameterValue(MULTIDB)))
+         if (!wsEntry.getContainer().getParameterValue(MULTIDB)
+            .equals(wsConfig.getContainer().getParameterValue(MULTIDB)))
          {
             throw new RepositoryConfigurationException("All workspaces must be " + MULTIDB + " or " + SINGLEDB
                + ". But " + wsEntry.getName() + "- multi-db=" + wsEntry.getContainer().getParameterValue(MULTIDB)
@@ -667,14 +667,14 @@
          this.connFactory = defaultConnectionFactory();
          dbInitializer = new PgSQLDBInitializer(containerName, this.connFactory.getJdbcConnection(), sqlPath, multiDb);
       }
-      else if (dbDialect == DBConstants.DB_DIALECT_MYSQL || dbDialect == DBConstants.DB_DIALECT_MYSQL_UTF8 ||
-               dbDialect == DBConstants.DB_DIALECT_MYSQL_MYISAM || dbDialect == DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8)
+      else if (dbDialect == DBConstants.DB_DIALECT_MYSQL || dbDialect == DBConstants.DB_DIALECT_MYSQL_UTF8
+         || dbDialect == DBConstants.DB_DIALECT_MYSQL_MYISAM || dbDialect == DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8)
       {
          if (dbDialect == DBConstants.DB_DIALECT_MYSQL_MYISAM || dbDialect == DBConstants.DB_DIALECT_MYSQL_MYISAM_UTF8)
          {
-            LOG.warn("MyISAM is not supported due to its lack of transaction support and integrity check, so use it only" +
-                  " if you don't expect any support and performances in read accesses are more important than the consistency" +
-                  " in your use-case. This dialect is only dedicated to the community.");
+            LOG.warn("MyISAM is not supported due to its lack of transaction support and integrity check, so use it only"
+               + " if you don't expect any support and performances in read accesses are more important than the consistency"
+               + " in your use-case. This dialect is only dedicated to the community.");
          }
          if (dbSourceName != null)
          {
@@ -728,8 +728,8 @@
          if (dbSourceName != null)
          {
             this.connFactory =
-               new HSQLDBConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider, maxBufferSize,
-                  swapDirectory, swapCleaner);
+               new HSQLDBConnectionFactory(getDataSource(), containerName, multiDb, valueStorageProvider,
+                  maxBufferSize, swapDirectory, swapCleaner);
          }
          else
          {
@@ -1036,11 +1036,20 @@
          {
             for (ValueStorageEntry valueStorage : wsConfig.getContainer().getValueStorages())
             {
-               File valueStorageDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
-               if (PrivilegedFileHelper.exists(valueStorageDir))
+               final File valueStorageDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
+
+               SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
                {
-                  DirectoryHelper.removeDirectory(valueStorageDir);
-               }
+                  public Void run() throws IOException
+                  {
+                     if (valueStorageDir.exists())
+                     {
+                        DirectoryHelper.removeDirectory(valueStorageDir);
+                     }
+
+                     return null;
+                  }
+               });
             }
          }
       }
@@ -1061,7 +1070,7 @@
    /**
     * {@inheritDoc}
     */
-   public void backup(File storageDir) throws BackupException
+   public void backup(final File storageDir) throws BackupException
    {
       ObjectWriter backupInfo = null;
 
@@ -1102,19 +1111,28 @@
          // backup value storage
          if (wsConfig.getContainer().getValueStorages() != null)
          {
-            for (ValueStorageEntry valueStorage : wsConfig.getContainer().getValueStorages())
+            for (final ValueStorageEntry valueStorage : wsConfig.getContainer().getValueStorages())
             {
-               File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
-               if (!PrivilegedFileHelper.exists(srcDir))
+               final File srcDir = new File(valueStorage.getParameterValue(FileValueStorage.PATH));
+
+               SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>()
                {
-                  throw new BackupException("Can't backup value storage. Directory " + srcDir.getName()
-                     + " doesn't exists");
-               }
-               else
-               {
-                  File zipFile = new File(storageDir, "values-" + valueStorage.getId() + ".zip");
-                  DirectoryHelper.compressDirectory(srcDir, zipFile);
-               }
+                  public Void run() throws IOException
+                  {
+                     if (!srcDir.exists())
+                     {
+                        throw new IOException("Can't backup value storage. Directory " + srcDir.getName()
+                           + " doesn't exists");
+                     }
+                     else
+                     {
+                        File zipFile = new File(storageDir, "values-" + valueStorage.getId() + ".zip");
+                        DirectoryHelper.compressDirectory(srcDir, zipFile);
+                     }
+
+                     return null;
+                  }
+               });
             }
          }
       }
@@ -1157,7 +1175,7 @@
       ObjectReader backupInfo = null;
       try
       {
-         File storageDir = (File) context.getObject(DataRestoreContext.STORAGE_DIR);
+         File storageDir = (File)context.getObject(DataRestoreContext.STORAGE_DIR);
          Connection jdbcConn = null;
 
          if (context.getObject(DataRestoreContext.DB_CONNECTION) == null)
@@ -1179,11 +1197,11 @@
          }
          else
          {
-            jdbcConn = (Connection) context.getObject(DataRestoreContext.DB_CONNECTION);
+            jdbcConn = (Connection)context.getObject(DataRestoreContext.DB_CONNECTION);
          }
 
          backupInfo =
-                  new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
+            new ObjectReaderImpl(PrivilegedFileHelper.fileInputStream(new File(storageDir,
                "JDBCWorkspaceDataContainer.info")));
 
          String srcContainerName = backupInfo.readString();

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/CASableWriteValue.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/CASableWriteValue.java	2012-02-07 08:05:23 UTC (rev 5571)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/CASableWriteValue.java	2012-02-07 10:35:56 UTC (rev 5572)
@@ -26,6 +26,7 @@
 import org.exoplatform.services.jcr.impl.storage.value.cas.ValueContentAddressStorage;
 import org.exoplatform.services.jcr.impl.storage.value.fs.CASableIOSupport;
 import org.exoplatform.services.jcr.impl.storage.value.fs.FileDigestOutputStream;
+import org.exoplatform.services.jcr.impl.util.io.DirectoryHelper;
 import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
 import org.exoplatform.services.jcr.util.IdGenerator;
 
@@ -175,11 +176,16 @@
 
                // make sure parent dir exists
                vcasFile.getParentFile().mkdirs();
+
                // rename propetynamed file to hashnamed one
-               if (!tempFile.renameTo(vcasFile))
+               try
                {
+                  DirectoryHelper.renameFile(tempFile, vcasFile);
+               }
+               catch (IOException e)
+               {
                   throw new VCASException("File " + tempFile.getAbsolutePath() + " can't be renamed to VCAS-named "
-                     + vcasFile.getAbsolutePath());
+                     + vcasFile.getAbsolutePath(), e);
                }
             } // else - CASed Value already exists
 

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java	2012-02-07 08:05:23 UTC (rev 5571)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/DirectoryHelper.java	2012-02-07 10:35:56 UTC (rev 5572)
@@ -18,9 +18,9 @@
  */
 package org.exoplatform.services.jcr.impl.util.io;
 
-import org.exoplatform.commons.utils.PrivilegedFileHelper;
-
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -56,12 +56,12 @@
    {
       List<File> result = new ArrayList<File>();
 
-      if (!PrivilegedFileHelper.isDirectory(srcPath))
+      if (!srcPath.isDirectory())
       {
-         throw new IOException(PrivilegedFileHelper.getAbsolutePath(srcPath) + " is a directory");
+         throw new IOException(srcPath.getAbsolutePath() + " is a directory");
       }
 
-      for (File subFile : PrivilegedFileHelper.listFiles(srcPath))
+      for (File subFile : srcPath.listFiles())
       {
          result.add(subFile);
          if (subFile.isDirectory())
@@ -85,14 +85,14 @@
     */
    public static void copyDirectory(File srcPath, File dstPath) throws IOException
    {
-      if (PrivilegedFileHelper.isDirectory(srcPath))
+      if (srcPath.isDirectory())
       {
-         if (!PrivilegedFileHelper.exists(dstPath))
+         if (!dstPath.exists())
          {
-            PrivilegedFileHelper.mkdirs(dstPath);
+            dstPath.mkdirs();
          }
 
-         String files[] = PrivilegedFileHelper.list(srcPath);
+         String files[] = srcPath.list();
          for (int i = 0; i < files.length; i++)
          {
             copyDirectory(new File(srcPath, files[i]), new File(dstPath, files[i]));
@@ -105,8 +105,8 @@
 
          try
          {
-            in = PrivilegedFileHelper.fileInputStream(srcPath);
-            out = PrivilegedFileHelper.fileOutputStream(dstPath);
+            in = new FileInputStream(srcPath);
+            out = new FileOutputStream(dstPath);
 
             transfer(in, out);
          }
@@ -136,23 +136,23 @@
     */
    public static void removeDirectory(File dir) throws IOException
    {
-      if (PrivilegedFileHelper.isDirectory(dir))
+      if (dir.isDirectory())
       {
-         for (File subFile : PrivilegedFileHelper.listFiles(dir))
+         for (File subFile : dir.listFiles())
          {
             removeDirectory(subFile);
          }
 
-         if (!PrivilegedFileHelper.delete(dir))
+         if (!dir.delete())
          {
-            throw new IOException("Can't remove folder : " + PrivilegedFileHelper.getCanonicalPath(dir));
+            throw new IOException("Can't remove folder : " + dir.getCanonicalPath());
          }
       }
       else
       {
-         if (!PrivilegedFileHelper.delete(dir))
+         if (!dir.delete())
          {
-            throw new IOException("Can't remove file : " + PrivilegedFileHelper.getCanonicalPath(dir));
+            throw new IOException("Can't remove file : " + dir.getCanonicalPath());
          }
       }
    }
@@ -172,12 +172,12 @@
     */
    public static void compressDirectory(File rootPath, File dstZipPath) throws IOException
    {
-      ZipOutputStream zip = PrivilegedFileHelper.zipOutputStream(dstZipPath);
+      ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(dstZipPath));
       try
       {
-         if (PrivilegedFileHelper.isDirectory(rootPath))
+         if (rootPath.isDirectory())
          {
-            String files[] = PrivilegedFileHelper.list(rootPath);
+            String files[] = rootPath.list();
             for (int i = 0; i < files.length; i++)
             {
                compressDirectory("", new File(rootPath, files[i]), zip);
@@ -203,12 +203,12 @@
     */
    private static void compressDirectory(String relativePath, File srcPath, ZipOutputStream zip) throws IOException
    {
-      if (PrivilegedFileHelper.isDirectory(srcPath))
+      if (srcPath.isDirectory())
       {
          zip.putNextEntry(new ZipEntry(relativePath + "/" + srcPath.getName() + "/"));
          zip.closeEntry();
 
-         String files[] = PrivilegedFileHelper.list(srcPath);
+         String files[] = srcPath.list();
          for (int i = 0; i < files.length; i++)
          {
             compressDirectory(relativePath + "/" + srcPath.getName(), new File(srcPath, files[i]), zip);
@@ -216,7 +216,7 @@
       }
       else
       {
-         InputStream in = PrivilegedFileHelper.fileInputStream(srcPath);
+         InputStream in = new FileInputStream(srcPath);
          try
          {
             zip.putNextEntry(new ZipEntry(relativePath + "/" + srcPath.getName()));
@@ -247,7 +247,7 @@
     */
    public static void uncompressDirectory(File srcZipPath, File dstDirPath) throws IOException
    {
-      ZipInputStream in = PrivilegedFileHelper.zipInputStream(srcZipPath);
+      ZipInputStream in = new ZipInputStream(new FileInputStream(srcZipPath));
       ZipEntry entry = null;
 
       try
@@ -255,15 +255,15 @@
          while ((entry = in.getNextEntry()) != null)
          {
             File dstFile = new File(dstDirPath, entry.getName());
-            PrivilegedFileHelper.mkdirs(dstFile.getParentFile());
+            dstFile.getParentFile().mkdirs();
 
             if (entry.isDirectory())
             {
-               PrivilegedFileHelper.mkdirs(dstFile);
+               dstFile.mkdirs();
             }
             else
             {
-               OutputStream out = PrivilegedFileHelper.fileOutputStream(dstFile);
+               OutputStream out = new FileOutputStream(dstFile);
                try
                {
                   transfer(in, out);
@@ -296,14 +296,14 @@
     */
    public static void uncompressEveryFileFromDirectory(File srcPath, File dstPath) throws IOException
    {
-      if (PrivilegedFileHelper.isDirectory(srcPath))
+      if (srcPath.isDirectory())
       {
-         if (!PrivilegedFileHelper.exists(dstPath))
+         if (!dstPath.exists())
          {
-            PrivilegedFileHelper.mkdirs(dstPath);
+            dstPath.mkdirs();
          }
 
-         String files[] = PrivilegedFileHelper.list(srcPath);
+         String files[] = srcPath.list();
          for (int i = 0; i < files.length; i++)
          {
             uncompressEveryFileFromDirectory(new File(srcPath, files[i]), new File(dstPath, files[i]));
@@ -316,10 +316,10 @@
 
          try
          {
-            in = PrivilegedFileHelper.zipInputStream(srcPath);
+            in = new ZipInputStream(new FileInputStream(srcPath));
             in.getNextEntry();
 
-            out = PrivilegedFileHelper.fileOutputStream(dstPath);
+            out = new FileOutputStream(dstPath);
 
             transfer(in, out);
          }
@@ -354,7 +354,8 @@
    }
 
    /**
-    * Rename file.
+    * Rename file. If file can't be renamed in standard way the coping
+    * data will be used instead.
     * 
     * @param srcFile
     *          source file
@@ -363,34 +364,21 @@
     * @throws IOException
     *          if any exception occurred 
     */
-   public static synchronized void renameFile(File srcFile, File dstFile) throws IOException
+   public static void renameFile(File srcFile, File dstFile) throws IOException
    {
-      /* This is not atomic.  If the program crashes between the call to
-         delete() and the call to renameTo() then we're screwed, but I've
-         been unable to figure out how else to do this... */
-
-      if (PrivilegedFileHelper.exists(dstFile))
-         if (!PrivilegedFileHelper.delete(dstFile))
-            throw new IOException("Cannot delete " + dstFile);
-
       // Rename the srcFile file to the new one. Unfortunately, the renameTo()
       // method does not work reliably under some JVMs.  Therefore, if the
       // rename fails, we manually rename by copying the srcFile file to the new one
-      if (!PrivilegedFileHelper.renameTo(srcFile, dstFile))
+      if (!srcFile.renameTo(dstFile))
       {
          InputStream in = null;
          OutputStream out = null;
          try
          {
-            in = PrivilegedFileHelper.fileInputStream(srcFile);
-            out = PrivilegedFileHelper.fileOutputStream(dstFile);
-            // see if the buffer needs to be initialized. Initialization is
-            // only done on-demand since many VM's will never run into the renameTo
-            // bug and hence shouldn't waste 1K of mem for no reason.
-            transfer(in, out);
+            in = new FileInputStream(srcFile);
+            out = new FileOutputStream(dstFile);
 
-            // delete the srcFile file.
-            PrivilegedFileHelper.delete(srcFile);
+            transfer(in, out);
          }
          catch (IOException ioe)
          {
@@ -410,6 +398,9 @@
                out.close();
             }
          }
+
+         // delete the srcFile file.
+         srcFile.delete();
       }
    }
 }

Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/test/resources/tsm-excludes.properties
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/test/resources/tsm-excludes.properties	2012-02-07 08:05:23 UTC (rev 5571)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/test/resources/tsm-excludes.properties	2012-02-07 10:35:56 UTC (rev 5572)
@@ -38,3 +38,6 @@
 org.exoplatform.services.jcr.cluster.functional.WebdavQueryTest.testPathSearch=addDir
 org.exoplatform.services.jcr.cluster.functional.WebdavQueryTest.testPropertyValueSearch=addNode
 org.exoplatform.services.jcr.cluster.functional.WebdavVersionTest.testVersioning=addNode
+org.exoplatform.services.jcr.impl.utils.io.TestDirectoryHelper.testCompressEmptyDirectory=compressDirectory
+org.exoplatform.services.jcr.impl.utils.io.TestDirectoryHelper.testCompressDirectory=compressDirectory,uncompressDirectory
+org.exoplatform.services.jcr.impl.utils.io.TestDirectoryHelper.testCompressFile=compressDirectory,uncompressDirectory

Modified: jcr/branches/1.15.x/exo.jcr.component.ext/pom.xml
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.ext/pom.xml	2012-02-07 08:05:23 UTC (rev 5571)
+++ jcr/branches/1.15.x/exo.jcr.component.ext/pom.xml	2012-02-07 10:35:56 UTC (rev 5572)
@@ -160,6 +160,7 @@
           <include>**/*.xls</include>
           <include>**/*.groovy</include>
           <include>**/login.conf</include>
+          <include>**/tsm-excludes.properties</include>
         </includes>
       </testResource>
     </testResources>

Added: jcr/branches/1.15.x/exo.jcr.component.ext/src/test/resources/tsm-excludes.properties
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.ext/src/test/resources/tsm-excludes.properties	                        (rev 0)
+++ jcr/branches/1.15.x/exo.jcr.component.ext/src/test/resources/tsm-excludes.properties	2012-02-07 10:35:56 UTC (rev 5572)
@@ -0,0 +1,2 @@
+org.exoplatform.services.jcr.ext.backup.AbstractBackupTestCase.removeRepositoryFully=removeDirectory
+org.exoplatform.services.jcr.ext.backup.AbstractBackupTestCase.removeWorkspaceFully=removeDirectory



More information about the exo-jcr-commits mailing list