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/08/11 05:57:00 UTC
svn commit: r1903332 - in /jackrabbit/branches/2.20: ./ jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
Author: reschke
Date: Thu Aug 11 05:56:59 2022
New Revision: 1903332
URL: http://svn.apache.org/viewvc?rev=1903332&view=rev
Log:
JCR-4814: File.renameTo sometimes fails to move temporary file to data record location (merged r1903102 and r1903106 into 2.20)
Modified:
jackrabbit/branches/2.20/ (props changed)
jackrabbit/branches/2.20/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
Propchange: jackrabbit/branches/2.20/
------------------------------------------------------------------------------
Merged /jackrabbit/trunk:r1903102,1903106
Modified: jackrabbit/branches/2.20/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.20/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java?rev=1903332&r1=1903331&r2=1903332&view=diff
==============================================================================
--- jackrabbit/branches/2.20/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java (original)
+++ jackrabbit/branches/2.20/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java Thu Aug 11 05:56:59 2022
@@ -23,6 +23,10 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.lang.ref.WeakReference;
+import java.nio.file.CopyOption;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -58,7 +62,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(Path, Path, CopyOption...)}.
*/
public class FileDataStore extends AbstractDataStore
implements MultiDataStoreAware {
@@ -196,15 +200,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) {