Skip to content

Commit

Permalink
Remove sync in FileUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
mlbiscoc committed Dec 16, 2024
1 parent 1c1a315 commit 4e43fed
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ private static class LocalFsFile implements FileInterface {
Path file;

LocalFsFile(Path dir, String saveAs) throws IOException {
this.file = dir.resolve(saveAs);
this.file = dir.resolve(saveAs);

Path parentDir = this.file.getParent();
if (Files.notExists(parentDir)) {
Expand Down
35 changes: 0 additions & 35 deletions solr/core/src/java/org/apache/solr/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,14 @@
*/
package org.apache.solr.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.commons.io.FileExistsException;

/** */
public class FileUtils {

/**
* Copied from Lucene's FSDirectory.fsync(String)
*
* @param fullFile the File to be synced to disk
* @throws IOException if the file could not be synced
*/
public static void sync(Path fullFile) throws IOException {
if (fullFile == null || Files.notExists(fullFile))
throw new FileNotFoundException("File does not exist " + fullFile);

boolean success = false;
int retryCount = 0;
IOException exc = null;
while (!success && retryCount < 5) {
retryCount++;
try (RandomAccessFile file = new RandomAccessFile(fullFile.toFile(), "rw")) {
file.getFD().sync();
success = true;
} catch (IOException ioe) {
if (exc == null) exc = ioe;
try {
// Pause 5 msec
Thread.sleep(5);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
}
}
if (!success)
// Throw original exception
throw exc;
}

public static boolean fileExists(String filePathString) {
return Files.exists(Path.of(filePathString));
}
Expand Down

0 comments on commit 4e43fed

Please sign in to comment.