You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/02/12 09:46:00 UTC
svn commit: r1445060 - in /camel/branches/camel-2.10.x: ./
camel-core/src/main/java/org/apache/camel/component/file/
camel-core/src/main/java/org/apache/camel/component/file/strategy/
camel-core/src/main/java/org/apache/camel/processor/idempotent/ came...
Author: davsclaus
Date: Tue Feb 12 08:46:00 2013
New Revision: 1445060
URL: http://svn.apache.org/r1445060
Log:
CAMEL-6069: Creating new file can cause problem if NAS. Use FileUtil to handle this.
Modified:
camel/branches/camel-2.10.x/ (props changed)
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1445059
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java?rev=1445060&r1=1445059&r2=1445060&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java (original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileOperations.java Tue Feb 12 08:46:00 2013
@@ -404,7 +404,7 @@ public class FileOperations implements G
private void writeFileEmptyBody(File target) throws IOException {
if (!target.exists()) {
LOG.debug("Creating new empty file: {}", target);
- target.createNewFile();
+ FileUtil.createNewFile(target);
} else if (endpoint.getFileExist() == GenericFileExist.Override) {
LOG.debug("Truncating existing file: {}", target);
FileChannel out = new FileOutputStream(target).getChannel();
Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java?rev=1445060&r1=1445059&r2=1445060&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java (original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/strategy/MarkerFileExclusiveReadLockStrategy.java Tue Feb 12 08:46:00 2013
@@ -50,8 +50,7 @@ public class MarkerFileExclusiveReadLock
LOG.trace("Locking the file: {} using the lock file name: {}", file, lockFileName);
// create a plain file as marker filer for locking (do not use FileLock)
- File lock = new File(lockFileName);
- boolean acquired = lock.createNewFile();
+ boolean acquired = FileUtil.createNewFile(new File(lockFileName));
exchange.setProperty(Exchange.FILE_LOCK_FILE_ACQUIRED, acquired);
return acquired;
Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java?rev=1445060&r1=1445059&r2=1445060&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java (original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java Tue Feb 12 08:46:00 2013
@@ -28,6 +28,7 @@ import org.apache.camel.api.management.M
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.spi.IdempotentRepository;
import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.FileUtil;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.LRUCache;
import org.apache.camel.util.ObjectHelper;
@@ -231,7 +232,7 @@ public class FileIdempotentRepository ex
try {
// create store if missing
if (!fileStore.exists()) {
- fileStore.createNewFile();
+ FileUtil.createNewFile(fileStore);
}
// append to store
fos = new FileOutputStream(fileStore, true);
Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java?rev=1445060&r1=1445059&r2=1445060&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java (original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/util/FileUtil.java Tue Feb 12 08:46:00 2013
@@ -464,4 +464,23 @@ public final class FileUtil {
return file.isAbsolute();
}
+ /**
+ * Creates a new file.
+ *
+ * @param file the file
+ * @return <tt>true</tt> if created a new file, <tt>false</tt> otherwise
+ * @throws IOException is thrown if error creating the new file
+ */
+ public static boolean createNewFile(File file) throws IOException {
+ try {
+ return file.createNewFile();
+ } catch (IOException e) {
+ if (file.exists()) {
+ return true;
+ } else {
+ throw e;
+ }
+ }
+ }
+
}
Modified: camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java?rev=1445060&r1=1445059&r2=1445060&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java (original)
+++ camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java Tue Feb 12 08:46:00 2013
@@ -192,4 +192,14 @@ public class FileUtilTest extends TestCa
assertTrue("Should be a file", tmp.isFile());
}
+ public void testCreateNewFile() throws Exception {
+ File file = new File("target/foo.txt");
+ if (file.exists()) {
+ FileUtil.deleteFile(file);
+ }
+
+ assertFalse("File should not exist " + file, file.exists());
+ assertTrue("A new file should be created " + file, FileUtil.createNewFile(file));
+ }
+
}