You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2022/07/29 13:37:42 UTC

svn commit: r1903102 - /jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java

Author: reschke
Date: Fri Jul 29 13:37:42 2022
New Revision: 1903102

URL: http://svn.apache.org/viewvc?rev=1903102&view=rev
Log:
JCR-4814: File.renameTo sometimes fails to move temporary file to data record location

Modified:
    jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java?rev=1903102&r1=1903101&r2=1903102&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java (original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java Fri Jul 29 13:37:42 2022
@@ -23,6 +23,8 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.RandomAccessFile;
 import java.lang.ref.WeakReference;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
 import java.security.DigestOutputStream;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -58,7 +60,7 @@ import org.slf4j.LoggerFactory;
  * up to billions of distinct records.
  * <p>
  * This implementation relies on the underlying file system to support
- * atomic O(1) move operations with {@link File#renameTo(File)}.
+ * atomic O(1) move operations with {@link Files#move()}.
  */
 public class FileDataStore extends AbstractDataStore
         implements MultiDataStoreAware {
@@ -196,15 +198,9 @@ public class FileDataStore extends Abstr
                 if (!file.exists()) {
                     File parent = file.getParentFile();
                     parent.mkdirs();
-                    if (temporary.renameTo(file)) {
-                        // no longer need to delete the temporary file
-                        temporary = null;
-                    } else {
-                        throw new IOException(
-                                "Can not rename " + temporary.getAbsolutePath()
-                                + " to " + file.getAbsolutePath()
-                                + " (media read only?)");
-                    }
+                    Files.move(temporary.toPath(), file.toPath(), StandardCopyOption.ATOMIC_MOVE);
+                    // no longer need to delete the temporary file
+                    temporary = null;
                 } else {
                     long now = System.currentTimeMillis();
                     if (getLastModified(file) < now + ACCESS_TIME_RESOLUTION) {