james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1686804 - in /james/mailbox/trunk: jcr/src/test/java/org/apache/james/mailbox/jcr/ maildir/src/main/java/org/apache/james/mailbox/maildir/ maildir/src/main/java/org/apache/james/mailbox/maildir/mail/
Date Mon, 22 Jun 2015 08:15:03 GMT
Author: btellier
Date: Mon Jun 22 08:15:02 2015
New Revision: 1686804

URL: http://svn.apache.org/r1686804
Log:
MAILBOX-232 Use FileUtils when deleting files - contributed by Antoine Duprat

Modified:
    james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
    james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
    james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRSubscriptionManagerTest.java
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java

Modified: james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java?rev=1686804&r1=1686803&r2=1686804&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
(original)
+++ james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxManagerTest.java
Mon Jun 22 08:15:02 2015
@@ -18,6 +18,13 @@
  ****************************************************************/
 package org.apache.james.mailbox.jcr;
 
+import static org.junit.Assert.fail;
+
+import java.io.File;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.ConfigurationException;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
@@ -32,14 +39,10 @@ import org.apache.james.mailbox.jcr.mail
 import org.apache.james.mailbox.jcr.mail.JCRUidProvider;
 import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.junit.After;
-import static org.junit.Assert.fail;
 import org.junit.Before;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.InputSource;
 
-import javax.jcr.RepositoryException;
-import java.io.File;
-
 /**
  * JCRMailboxManagerTest that extends the StoreMailboxManagerTest.
  */
@@ -57,17 +60,14 @@ public class JCRMailboxManagerTest exten
     }
 
     @After
-    public void tearDown() throws MailboxException {
+    public void tearDown() throws Exception {
         MailboxSession session = getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test"));
         session.close();
         repository.shutdown();
-        new File(JACKRABBIT_HOME).delete();
+        FileUtils.forceDelete(new File(JACKRABBIT_HOME));
     }
 
     protected void createMailboxManager() throws MailboxException {
-
-        new File(JACKRABBIT_HOME).delete();
-
         String user = "user";
         String pass = "pass";
         String workspace = null;

Modified: james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java?rev=1686804&r1=1686803&r2=1686804&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
(original)
+++ james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRStressTest.java
Mon Jun 22 08:15:02 2015
@@ -18,6 +18,12 @@
  ****************************************************************/
 package org.apache.james.mailbox.jcr;
 
+import java.io.File;
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 import org.apache.james.mailbox.AbstractStressTest;
@@ -36,9 +42,6 @@ import org.junit.Before;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.InputSource;
 
-import javax.jcr.RepositoryException;
-import java.io.File;
-
 public class JCRStressTest extends AbstractStressTest {
 
     private JCRMailboxManager mailboxManager;
@@ -47,9 +50,6 @@ public class JCRStressTest extends Abstr
 
     @Before
     public void setUp() throws RepositoryException, MailboxException {
-
-        new File(JACKRABBIT_HOME).delete();
-
         String user = "user";
         String pass = "pass";
         String workspace = null;
@@ -71,11 +71,11 @@ public class JCRStressTest extends Abstr
     }
 
     @After
-    public void tearDown() {
+    public void tearDown() throws IOException {
         MailboxSession session = mailboxManager.createSystemSession("test", LoggerFactory.getLogger(JCRStressTest.class));
         session.close();
         repository.shutdown();
-        new File(JACKRABBIT_HOME).delete();
+        FileUtils.forceDelete(new File(JACKRABBIT_HOME));
     }
 
     @Override

Modified: james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRSubscriptionManagerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRSubscriptionManagerTest.java?rev=1686804&r1=1686803&r2=1686804&view=diff
==============================================================================
--- james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRSubscriptionManagerTest.java
(original)
+++ james/mailbox/trunk/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRSubscriptionManagerTest.java
Mon Jun 22 08:15:02 2015
@@ -18,6 +18,12 @@
  ****************************************************************/
 package org.apache.james.mailbox.jcr;
 
+import java.io.File;
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 import org.apache.james.mailbox.AbstractSubscriptionManagerTest;
@@ -26,9 +32,6 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.xml.sax.InputSource;
 
-import javax.jcr.RepositoryException;
-import java.io.File;
-
 public class JCRSubscriptionManagerTest extends AbstractSubscriptionManagerTest {
     private static final String JACKRABBIT_HOME = "target/jackrabbit";
 
@@ -49,17 +52,15 @@ public class JCRSubscriptionManagerTest
     }
 
     @AfterClass
-    public static void after() {
+    public static void after() throws IOException {
         if (repository != null) {
             repository.shutdown();
         }
-        new File(JACKRABBIT_HOME).delete();
+        FileUtils.forceDelete(new File(JACKRABBIT_HOME));
     }
 
     @Override
     public SubscriptionManager createSubscriptionManager() {
-
-        new File(JACKRABBIT_HOME).delete();
         MailboxSessionJCRRepository sessionRepos = new GlobalMailboxSessionJCRRepository(repository,
workspace, user, pass);
         JCRMailboxSessionMapperFactory mf = new JCRMailboxSessionMapperFactory(sessionRepos,
null, null);
         JCRSubscriptionManager sm = new JCRSubscriptionManager(mf);

Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java?rev=1686804&r1=1686803&r2=1686804&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
(original)
+++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirFolder.java
Mon Jun 22 08:15:02 2015
@@ -40,17 +40,18 @@ import java.util.Properties;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.james.mailbox.MailboxPathLocker;
 import org.apache.james.mailbox.MailboxPathLocker.LockAwareExecution;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.SimpleMailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
-import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.SimpleMailboxACL;
 
 public class MaildirFolder {
 
@@ -896,8 +897,7 @@ public class MaildirFolder {
                         }
                     }
                     if (deletedMessage != null) {
-                        if (!deletedMessage.getFile().delete())
-                            throw new IOException("Cannot delete file " + deletedMessage.getFile().getAbsolutePath());
+                        FileUtils.forceDelete(deletedMessage.getFile());
                         writer = new PrintWriter(uidList);
                         writer.println(createUidListHeader());
                         for (String entry : lines)

Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java?rev=1686804&r1=1686803&r2=1686804&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
(original)
+++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
Mon Jun 22 08:15:02 2015
@@ -70,30 +70,37 @@ public class MaildirMailboxMapper extend
         String folderName = maildirStore.getFolderName(mailbox);
         File folder = new File(folderName);
         if (folder.isDirectory()) {
+            // Shouldn't fail on file deletion, else the mailbox will never be deleted
+            if (mailbox.getName().equals(MailboxConstants.INBOX)) {
+                // We must only delete cur, new, tmp and metadata for top INBOX mailbox.
+                delete(new File(folder, MaildirFolder.CUR), 
+                        new File(folder, MaildirFolder.NEW),
+                        new File(folder, MaildirFolder.TMP),
+                        new File(folder, MaildirFolder.UIDLIST_FILE),
+                        new File(folder, MaildirFolder.VALIDITY_FILE));
+            }
+            else {
+                // We simply delete all the folder for non INBOX mailboxes.
+                delete(folder);
+            }
+        }
+        else
+            throw new MailboxNotFoundException(mailbox.getName());
+    }
+
+    private void delete(File...files) {
+        for (File file : files) {
             try {
-                if (mailbox.getName().equals(MailboxConstants.INBOX)) {
-                    // We must only delete cur, new, tmp and metadata for top INBOX mailbox.
-                    FileUtils.deleteDirectory(new File(folder, MaildirFolder.CUR));
-                    FileUtils.deleteDirectory(new File(folder, MaildirFolder.NEW));
-                    FileUtils.deleteDirectory(new File(folder, MaildirFolder.TMP));
-                    File uidListFile = new File(folder, MaildirFolder.UIDLIST_FILE);
-                    uidListFile.delete();
-                    File validityFile = new File(folder, MaildirFolder.VALIDITY_FILE);
-                    validityFile.delete();
-                }
-                else {
-                    // We simply delete all the folder for non INBOX mailboxes.
-                    FileUtils.deleteDirectory(folder);
+                if (file.isDirectory()) {
+                        FileUtils.deleteDirectory(file);
+                } else {
+                    FileUtils.forceDelete(file);
                 }
             } catch (IOException e) {
                 e.printStackTrace();
-                throw new MailboxException("Unable to delete Mailbox " + mailbox, e);
             }
         }
-        else
-            throw new MailboxNotFoundException(mailbox.getName());
     }
-
    
     /**
      * @see org.apache.james.mailbox.store.mail.MailboxMapper#findMailboxByPath(org.apache.james.mailbox.model.MailboxPath)
@@ -160,8 +167,7 @@ public class MaildirMailboxMapper extend
                     try {
                         File inboxFolder = originalFolder.getRootFile();
                         File newFolder = folder.getRootFile();
-                        if (!newFolder.mkdirs())
-                            throw new IOException("Could not create folder " + newFolder);
+                        FileUtils.forceMkdir(newFolder);
                         if (!originalFolder.getCurFolder().renameTo(folder.getCurFolder()))
                             throw new IOException("Could not rename folder " + originalFolder.getCurFolder()
+ " to " + folder.getCurFolder());
                         if (!originalFolder.getNewFolder().renameTo(folder.getNewFolder()))
@@ -178,12 +184,9 @@ public class MaildirMailboxMapper extend
                             throw new IOException("Could not rename file " + oldValidityFile
+ " to " + newValidityFile);
                         // recreate the INBOX folders, uidvalidity and uidlist will
                         // automatically be recreated later
-                        if (!originalFolder.getCurFolder().mkdir())
-                            throw new IOException("Could not create folder " + originalFolder.getCurFolder());
-                        if (!originalFolder.getNewFolder().mkdir())
-                            throw new IOException("Could not create folder " + originalFolder.getNewFolder());
-                        if (!originalFolder.getTmpFolder().mkdir())
-                            throw new IOException("Could not create folder " + originalFolder.getTmpFolder());
+                        FileUtils.forceMkdir(originalFolder.getCurFolder());
+                        FileUtils.forceMkdir(originalFolder.getNewFolder());
+                        FileUtils.forceMkdir(originalFolder.getTmpFolder());
                     } catch (IOException e) {
                         throw new MailboxException("Failed to save Mailbox " + mailbox, e);
                     }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message