james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1686799 - in /james/server/trunk: container/core/src/main/java/org/apache/james/core/ container/filesystem-api/src/test/java/org/apache/james/filesystem/api/ data/data-file/src/main/java/org/apache/james/mailrepository/file/ data/data-file...
Date Mon, 22 Jun 2015 08:09:31 GMT
Author: btellier
Date: Mon Jun 22 08:09:30 2015
New Revision: 1686799

URL: http://svn.apache.org/r1686799
Log:
JAMES-1310 Use FileUtils when deleting files - contributed by Antoine Duprat

Modified:
    james/server/trunk/container/core/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java
    james/server/trunk/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java
    james/server/trunk/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
    james/server/trunk/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java
    james/server/trunk/data/data-jcr/src/test/java/org/apache/james/user/jcr/JcrUserRepositoryTest.java
    james/server/trunk/data/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java
    james/server/trunk/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
    james/server/trunk/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/FileSystemBlobStrategy.java
    james/server/trunk/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueBlobTest.java
    james/server/trunk/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java

Modified: james/server/trunk/container/core/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container/core/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java?rev=1686799&r1=1686798&r2=1686799&view=diff
==============================================================================
--- james/server/trunk/container/core/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java
(original)
+++ james/server/trunk/container/core/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java
Mon Jun 22 08:09:30 2015
@@ -19,14 +19,6 @@
 
 package org.apache.james.core;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.output.DeferredFileOutputStream;
-import org.apache.james.lifecycle.api.Disposable;
-
-import javax.mail.MessagingException;
-import javax.mail.util.SharedByteArrayInputStream;
-import javax.mail.util.SharedFileInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -34,6 +26,15 @@ import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.mail.MessagingException;
+import javax.mail.util.SharedByteArrayInputStream;
+import javax.mail.util.SharedFileInputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.DeferredFileOutputStream;
+import org.apache.james.lifecycle.api.Disposable;
+
 /**
  * Takes an input stream and creates a repeatable input stream source for a
  * MimeMessageWrapper. It does this by completely reading the input stream and
@@ -88,7 +89,7 @@ public class MimeMessageInputStreamSourc
 
                     File file = out.getFile();
                     if (file != null) {
-                        file.delete();
+                        FileUtils.forceDelete(file);
                     }
                 }
             } catch (IOException ioe) {

Modified: james/server/trunk/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java
URL: http://svn.apache.org/viewvc/james/server/trunk/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java?rev=1686799&r1=1686798&r2=1686799&view=diff
==============================================================================
--- james/server/trunk/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java
(original)
+++ james/server/trunk/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/SieveFileRepositoryTestCase.java
Mon Jun 22 08:09:30 2015
@@ -19,11 +19,27 @@
  */
 package org.apache.james.filesystem.api;
 
-import java.io.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.List;
+
 import org.apache.commons.io.FileUtils;
-import org.apache.james.managesieve.api.*;
-import static org.junit.Assert.*;
+import org.apache.james.managesieve.api.DuplicateException;
+import org.apache.james.managesieve.api.DuplicateUserException;
+import org.apache.james.managesieve.api.IsActiveException;
+import org.apache.james.managesieve.api.QuotaExceededException;
+import org.apache.james.managesieve.api.QuotaNotFoundException;
+import org.apache.james.managesieve.api.ScriptNotFoundException;
+import org.apache.james.managesieve.api.ScriptSummary;
+import org.apache.james.managesieve.api.SieveRepository;
+import org.apache.james.managesieve.api.StorageException;
+import org.apache.james.managesieve.api.UserNotFoundException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -63,7 +79,7 @@ public class SieveFileRepositoryTestCase
         if (root.exists()) {
             FileUtils.forceDelete(root);
         }
-        root.mkdir();
+        FileUtils.forceMkdir(root);
     }
 
     /**

Modified: james/server/trunk/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java?rev=1686799&r1=1686798&r2=1686799&view=diff
==============================================================================
--- james/server/trunk/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
(original)
+++ james/server/trunk/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
Mon Jun 22 08:09:30 2015
@@ -71,6 +71,7 @@ import javax.mail.internet.MimeMessage;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.io.FileUtils;
 import org.apache.james.core.MailImpl;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.lifecycle.api.LogEnabled;
@@ -683,7 +684,9 @@ public class MBoxMailRepository implemen
         // Just delete the MBOX file
         String lockFileName = mboxFile + LOCKEXT;
         File mBoxLock = new File(lockFileName);
-        if (!mBoxLock.delete()) {
+        try {
+            FileUtils.forceDelete(mBoxLock);
+        } catch (IOException e) {
             String logBuffer = this.getClass().getName() + " Failed to delete lock file "
+ lockFileName;
             getLogger().error(logBuffer);
         }
@@ -748,9 +751,7 @@ public class MBoxMailRepository implemen
             outputFile.close();
             // Delete the old mbox file
             File mbox = new File(mboxFile);
-            if (!mbox.delete()) {
-                throw new IOException("Unable to delete file " + mbox);
-            }
+            FileUtils.forceDelete(mbox);
             // And rename the lock file to be the new mbox
             mbox = new File(mboxFile + WORKEXT);
             if (!mbox.renameTo(new File(mboxFile))) {

Modified: james/server/trunk/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java?rev=1686799&r1=1686798&r2=1686799&view=diff
==============================================================================
--- james/server/trunk/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java
(original)
+++ james/server/trunk/data/data-file/src/test/java/org/apache/james/user/file/UsersFileRepositoryTest.java
Mon Jun 22 08:09:30 2015
@@ -33,6 +33,7 @@ import org.apache.james.lifecycle.api.Li
 import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.lib.AbstractUsersRepositoryTest;
+import org.junit.After;
 import org.junit.Before;
 import org.slf4j.LoggerFactory;
 
@@ -42,6 +43,7 @@ import org.slf4j.LoggerFactory;
 public class UsersFileRepositoryTest extends AbstractUsersRepositoryTest {
     
     private static final String TARGET_REPOSITORY_FOLDER = "target/var/users";
+	private File targetRepositoryFolder;
 
     /**
      * @see junit.framework.TestCase#setUp()
@@ -50,13 +52,15 @@ public class UsersFileRepositoryTest ext
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        File targetRepositoryFolder = new File(TARGET_REPOSITORY_FOLDER);
-        if (targetRepositoryFolder.exists()) {
-            FileUtils.deleteDirectory(targetRepositoryFolder);
-        }
+        targetRepositoryFolder = new File(TARGET_REPOSITORY_FOLDER);
         this.usersRepository = getUsersRepository();
     }
 
+    @After
+    public void tearDown() throws IOException {
+        FileUtils.forceDelete(targetRepositoryFolder);
+    }
+
     /**
      * Create the repository to be tested.
      * 

Modified: james/server/trunk/data/data-jcr/src/test/java/org/apache/james/user/jcr/JcrUserRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/data/data-jcr/src/test/java/org/apache/james/user/jcr/JcrUserRepositoryTest.java?rev=1686799&r1=1686798&r2=1686799&view=diff
==============================================================================
--- james/server/trunk/data/data-jcr/src/test/java/org/apache/james/user/jcr/JcrUserRepositoryTest.java
(original)
+++ james/server/trunk/data/data-jcr/src/test/java/org/apache/james/user/jcr/JcrUserRepositoryTest.java
Mon Jun 22 08:09:30 2015
@@ -19,7 +19,10 @@
 package org.apache.james.user.jcr;
 
 import java.io.File;
+import java.io.IOException;
+
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 import org.apache.james.user.api.UsersRepository;
@@ -29,6 +32,8 @@ import org.junit.Before;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.InputSource;
 
+import com.google.common.base.Throwables;
+
 public class JcrUserRepositoryTest extends AbstractUsersRepositoryTest {
 
     private static final String JACKRABBIT_HOME = "target/jackrabbit";
@@ -60,13 +65,11 @@ public class JcrUserRepositoryTest exten
     }
 
     private void delete(File file) {
-        if (file.isDirectory()) {
-            File[] contents = file.listFiles();
-            for (File content : contents) {
-                delete(content);
-            }
+        try {
+            FileUtils.forceDelete(file);
+        } catch (IOException e) {
+            Throwables.propagate(e);
         }
-        file.delete();
     }
 
     @Override

Modified: james/server/trunk/data/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/data/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java?rev=1686799&r1=1686798&r2=1686799&view=diff
==============================================================================
--- james/server/trunk/data/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java
(original)
+++ james/server/trunk/data/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java
Mon Jun 22 08:09:30 2015
@@ -37,6 +37,7 @@ import javax.inject.Named;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.io.FileUtils;
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.lifecycle.api.LogEnabled;
@@ -107,9 +108,7 @@ public abstract class AbstractFileReposi
         m_filter = new ExtensionFileFilter(m_extension);
         // m_filter = new NumberedRepositoryFileFilter(getExtensionDecorator());
 
-        if (!directory.exists() && !directory.mkdirs()) {
-            throw new IOException("Unable to create directory " + directory);
-        }
+        FileUtils.forceMkdir(directory);
 
         getLogger().info(getClass().getName() + " opened in " + m_baseDirectory);
 
@@ -266,11 +265,12 @@ public abstract class AbstractFileReposi
      */
     public synchronized void remove(final String key) {
         try {
-            final File file = getFile(key);
-            file.delete();
+            FileUtils.forceDelete(getFile(key));
             if (DEBUG)
                 getLogger().debug("removed key " + key);
-        } catch (final Exception e) {
+        } catch (FileNotFoundException e) {
+            getLogger().debug("File for " + key + " not found: wasn't able to remove");
+        } catch (Exception e) {
             throw new RuntimeException("Exception caught while removing" + " an object: "
+ e);
         }
     }

Modified: james/server/trunk/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java?rev=1686799&r1=1686798&r2=1686799&view=diff
==============================================================================
--- james/server/trunk/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
(original)
+++ james/server/trunk/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
Mon Jun 22 08:09:30 2015
@@ -27,6 +27,7 @@ import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.james.imap.api.ImapMessage;
 import org.apache.james.imap.api.ImapSessionState;
@@ -134,9 +135,7 @@ public class ImapRequestFrameDecoder ext
                             @Override
                             public void close() throws IOException {
                                 super.close();
-                                if (!f.delete()) {
-                                    throw new IOException("Unable to delete file " + f);
-                                }
+                                FileUtils.forceDelete(f);
                             }
 
                         }, retry);

Modified: james/server/trunk/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/FileSystemBlobStrategy.java
URL: http://svn.apache.org/viewvc/james/server/trunk/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/FileSystemBlobStrategy.java?rev=1686799&r1=1686798&r2=1686799&view=diff
==============================================================================
--- james/server/trunk/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/FileSystemBlobStrategy.java
(original)
+++ james/server/trunk/queue/queue-activemq/src/main/java/org/apache/james/queue/activemq/FileSystemBlobStrategy.java
Mon Jun 22 08:09:30 2015
@@ -18,14 +18,6 @@
  ****************************************************************/
 package org.apache.james.queue.activemq;
 
-import org.apache.activemq.BlobMessage;
-import org.apache.activemq.blob.BlobDownloadStrategy;
-import org.apache.activemq.blob.BlobTransferPolicy;
-import org.apache.activemq.blob.BlobUploadStrategy;
-import org.apache.activemq.command.ActiveMQBlobMessage;
-import org.apache.james.filesystem.api.FileSystem;
-
-import javax.jms.JMSException;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -34,6 +26,16 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 
+import javax.jms.JMSException;
+
+import org.apache.activemq.BlobMessage;
+import org.apache.activemq.blob.BlobDownloadStrategy;
+import org.apache.activemq.blob.BlobTransferPolicy;
+import org.apache.activemq.blob.BlobUploadStrategy;
+import org.apache.activemq.command.ActiveMQBlobMessage;
+import org.apache.commons.io.FileUtils;
+import org.apache.james.filesystem.api.FileSystem;
+
 /**
  * {@link BlobUploadStrategy} and {@link BlobDownloadStrategy} implementation
  * which use the {@link FileSystem} to lookup the {@link File} for the
@@ -94,9 +96,7 @@ public class FileSystemBlobStrategy impl
     public void deleteFile(ActiveMQBlobMessage message) throws IOException, JMSException
{
         File f = getFile(message);
         synchronized (lock) {
-            if (f.exists() && !f.delete()) {
-                throw new IOException("Unable to delete file " + f);
-            }
+            FileUtils.forceDelete(f);
         }
     }
 
@@ -134,9 +134,7 @@ public class FileSystemBlobStrategy impl
 
         synchronized (lock) {
             // check if we need to create the queue folder
-            if (!queueF.exists() && !queueF.mkdirs()) {
-                throw new IOException("Unable to create directory " + queueF.getAbsolutePath());
-            }
+            FileUtils.forceMkdir(queueF);
         }
 
         return fileSystem.getFile(queueUrl + "/" + filename);

Modified: james/server/trunk/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueBlobTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueBlobTest.java?rev=1686799&r1=1686798&r2=1686799&view=diff
==============================================================================
--- james/server/trunk/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueBlobTest.java
(original)
+++ james/server/trunk/queue/queue-activemq/src/test/java/org/apache/james/queue/activemq/ActiveMQMailQueueBlobTest.java
Mon Jun 22 08:09:30 2015
@@ -18,15 +18,18 @@
  ****************************************************************/
 package org.apache.james.queue.activemq;
 
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.james.filesystem.api.FileSystem;
-import org.apache.james.queue.jms.JMSMailQueue;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.commons.io.FileUtils;
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.queue.jms.JMSMailQueue;
+
+import com.google.common.base.Throwables;
+
 public class ActiveMQMailQueueBlobTest extends ActiveMQMailQueueTest {
 
     public final static String BASE_DIR = "file://target/james-test";
@@ -98,7 +101,13 @@ public class ActiveMQMailQueueBlobTest e
         }
 
         public void destroy() throws FileNotFoundException {
-            getFile(BASE_DIR).delete();
+            try {
+                FileUtils.forceDelete(getFile(BASE_DIR));
+            } catch (FileNotFoundException e) {
+                throw e;
+            } catch (IOException e) {
+                Throwables.propagate(e);
+            }
         }
     }
 }

Modified: james/server/trunk/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
URL: http://svn.apache.org/viewvc/james/server/trunk/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java?rev=1686799&r1=1686798&r2=1686799&view=diff
==============================================================================
--- james/server/trunk/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
(original)
+++ james/server/trunk/queue/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
Mon Jun 22 08:09:30 2015
@@ -18,17 +18,6 @@
  ****************************************************************/
 package org.apache.james.queue.file;
 
-import com.google.common.io.Closeables;
-import org.apache.james.core.MimeMessageCopyOnWriteProxy;
-import org.apache.james.core.MimeMessageSource;
-import org.apache.james.lifecycle.api.Disposable;
-import org.apache.james.lifecycle.api.LifecycleUtil;
-import org.apache.james.queue.api.ManageableMailQueue;
-import org.apache.mailet.Mail;
-import org.slf4j.Logger;
-
-import javax.mail.MessagingException;
-import javax.mail.util.SharedFileInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -49,6 +38,20 @@ import java.util.concurrent.ScheduledExe
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
+import javax.mail.MessagingException;
+import javax.mail.util.SharedFileInputStream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.james.core.MimeMessageCopyOnWriteProxy;
+import org.apache.james.core.MimeMessageSource;
+import org.apache.james.lifecycle.api.Disposable;
+import org.apache.james.lifecycle.api.LifecycleUtil;
+import org.apache.james.queue.api.ManageableMailQueue;
+import org.apache.mailet.Mail;
+import org.slf4j.Logger;
+
+import com.google.common.io.Closeables;
+
 /**
  * {@link ManageableMailQueue} implementation which use the fs to store {@link Mail}'s
  * <p/>
@@ -84,9 +87,7 @@ public class FileMailQueue implements Ma
         for (int i = 1; i <= SPLITCOUNT; i++) {
 
             File qDir = new File(queueDir, Integer.toString(i));
-            if (!qDir.exists() && !qDir.mkdirs()) {
-                throw new IOException("Unable to create queue directory " + qDir);
-            }
+            FileUtils.forceMkdir(qDir);
 
             String[] files = qDir.list(new FilenameFilter() {
                 @Override
@@ -379,22 +380,18 @@ public class FileMailQueue implements Ma
         }
 
         public void delete() throws MailQueueException {
-            File msgFile = new File(getMessageFile());
-            File objectFile = new File(getObjectFile());
-
-            if (objectFile.exists()) {
-                if (!objectFile.delete()) {
-                    throw new MailQueueException("Unable to delete mail");
-                }
+            try {
+                FileUtils.forceDelete(new File(getObjectFile()));
+            } catch (IOException e) {
+                throw new MailQueueException("Unable to delete mail");
             }
-            if (msgFile.exists()) {
-                if (!msgFile.delete()) {
-                    log.debug("Remove of msg file for mail failed");
-                }
 
+            try {
+                FileUtils.forceDelete(new File(getMessageFile()));
+            } catch (IOException e) {
+                log.debug("Remove of msg file for mail failed");
             }
         }
-
     }
 
     @Override



---------------------------------------------------------------------
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