Skip to content

Commit

Permalink
Directory.fileLength impl and invocations should align with spec for …
Browse files Browse the repository at this point in the history
…absent files
  • Loading branch information
magibney committed Mar 8, 2024
1 parent a2ad9cf commit d406e95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.io.Closeable;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -131,7 +132,7 @@ public AccessDirectory(
public long fileLength(String name) throws IOException {
try {
return super.fileLength(name);
} catch (NoSuchFileException ex) {
} catch (NoSuchFileException | FileNotFoundException ex) {
LazyEntry lazy = open(name);
if (lazy == null) {
throw ex;
Expand Down Expand Up @@ -174,7 +175,7 @@ public void sync(Collection<String> names) throws IOException {
for (String name : names) {
try {
fsync(name);
} catch (NoSuchFileException ex) {
} catch (NoSuchFileException | FileNotFoundException ex) {
LazyEntry lazy = open(name);
if (lazy == null) {
throw ex;
Expand Down Expand Up @@ -380,7 +381,7 @@ public IndexInput openInput(String name, IOContext context) throws IOException {
IndexInput ret = super.openInput(name, context);
rawCt.increment();
return ret;
} catch (NoSuchFileException ex) {
} catch (NoSuchFileException | FileNotFoundException ex) {
try {
LazyEntry lazy = open(name);
if (lazy == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.solr.storage;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -107,15 +106,14 @@ public CompressingDirectory(
@Override
public long fileLength(String name) throws IOException {
Path path = directoryPath.resolve(name);
File file = path.toFile();
ensureOpen();
if (getPendingDeletions().contains(name)) {
throw new NoSuchFileException("file \"" + name + "\" is pending delete");
}
if (file.length() < Long.BYTES) {
if (Files.size(path) < Long.BYTES) {
return 0;
} else {
try (FileInputStream in = new FileInputStream(file)) {
try (FileInputStream in = new FileInputStream(path.toFile())) {
byte[] bytes = in.readNBytes(Long.BYTES);
return ByteBuffer.wrap(bytes).getLong(0);
}
Expand Down

0 comments on commit d406e95

Please sign in to comment.