camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r905715 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/file/ main/java/org/apache/camel/util/ test/java/org/apache/camel/language/
Date Tue, 02 Feb 2010 17:25:28 GMT
Author: davsclaus
Date: Tue Feb  2 17:25:12 2010
New Revision: 905715

URL: http://svn.apache.org/viewvc?rev=905715&view=rev
Log:
CAMEL-2439: Fixed issue with detecting absolute paths on Windows. This could potential cause
not moving files to correct path after they have been processed.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=905715&r1=905714&r2=905715&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
Tue Feb  2 17:25:12 2010
@@ -84,7 +84,7 @@
     /**
      * Creates a new GenericFile<File> based on the given file.
      *
-     * @param endpointPath the starting directory the endpoint was configued with
+     * @param endpointPath the starting directory the endpoint was configured with
      * @param file the source file
      * @return wrapped as a GenericFile
      */
@@ -98,10 +98,15 @@
         answer.setFileName(file.getName());
         answer.setFileNameOnly(file.getName());
         answer.setFileLength(file.length());
-        answer.setAbsolute(file.isAbsolute());
+        // must use FileUtil.isAbsolute to have consistent check for whether the file is
+        // absolute or not. As windows do not consider \ paths as absolute where as all
+        // other OS platforms will consider \ as absolute. The logic in Camel mandates
+        // that we align this for all OS. That is why we must use FileUtil.isAbsolute
+        // to return a consistent answer for all OS platforms.
+        answer.setAbsolute(FileUtil.isAbsolute(file));
         answer.setAbsoluteFilePath(file.getAbsolutePath());
         answer.setLastModified(file.lastModified());
-        if (file.isAbsolute()) {
+        if (answer.isAbsolute()) {
             // use absolute path as relative
             answer.setRelativeFilePath(file.getAbsolutePath());
         } else {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=905715&r1=905714&r2=905715&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
Tue Feb  2 17:25:12 2010
@@ -23,6 +23,7 @@
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.processor.idempotent.MemoryIdempotentRepository;
+import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -59,7 +60,7 @@
                 if (log.isDebugEnabled()) {
                     log.debug("Creating non existing starting directory: " + file);
                 }
-                boolean absolute = file.isAbsolute();
+                boolean absolute = FileUtil.isAbsolute(file);
                 operations.buildDirectory(file.getPath(), absolute);
             }
         }
@@ -136,8 +137,7 @@
     @Override
     public boolean isAbsolute(String name) {
         // relative or absolute path?
-        File file = new File(name);
-        return file.isAbsolute();
+        return FileUtil.isAbsolute(new File(name));
     }
 
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=905715&r1=905714&r2=905715&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
Tue Feb  2 17:25:12 2010
@@ -134,8 +134,7 @@
     }
     
     protected boolean isAbsolute(String name) {
-        File file = new File(name);
-        return file.isAbsolute();        
+        return FileUtil.isAbsolute(new File(name));
     }
     
     protected String normalizePath(String name) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java?rev=905715&r1=905714&r2=905715&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
Tue Feb  2 17:25:12 2010
@@ -177,7 +177,7 @@
                 // use java.io.File to compute the file path
                 File file = new File(fileName);
                 String directory = file.getParent();
-                boolean absolute = file.isAbsolute();
+                boolean absolute = FileUtil.isAbsolute(file);
                 if (directory != null) {
                     if (!operations.buildDirectory(directory, absolute)) {
                         if (log.isDebugEnabled()) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java?rev=905715&r1=905714&r2=905715&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java Tue Feb  2 17:25:12
2010
@@ -329,5 +329,24 @@
         return deleted;
     }
 
+    /**
+     * Is the given file an absolute file.
+     * <p/>
+     * Will also work around issue on Windows to consider files on Windows starting with
a \
+     * as absolute files. This makes the logic consistent across all OS platforms.
+     *
+     * @param file  the file
+     * @return <tt>true</ff> if its an absolute path, <tt>false</tt>
otherwise.
+     */
+    public static boolean isAbsolute(File file) {
+        if (isWindows()) {
+            // special for windows
+            String path = file.getPath();
+            if (path.startsWith(File.separator)) {
+                return true;
+            }
+        }
+        return file.isAbsolute();
+    }
 
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java?rev=905715&r1=905714&r2=905715&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java Tue
Feb  2 17:25:12 2010
@@ -30,6 +30,7 @@
 import org.apache.camel.component.file.GenericFile;
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.language.simple.SimpleLanguage;
+import org.apache.camel.util.FileUtil;
 
 /**
  * Unit test for File Language.
@@ -66,7 +67,7 @@
         assertExpression("${file:onlyname.noext}", "hello");
         assertExpression("${file:parent}", file.getParent());
         assertExpression("${file:path}", file.getPath());
-        assertExpression("${file:absolute}", file.isAbsolute());
+        assertExpression("${file:absolute}", FileUtil.isAbsolute(file));
         assertExpression("${file:absolute.path}", file.getAbsolutePath());
         assertExpression("${file:length}", file.length());
 



Mime
View raw message