create a mapbuilder when listing files and not ImmutableMap builder since it seems like listFiles might return duplicate files.

This commit is contained in:
kimchy 2010-09-23 19:13:48 +02:00
parent 761639150d
commit 832914bf6d
1 changed files with 6 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import org.elasticsearch.common.blobstore.BlobPath;
import org.elasticsearch.common.blobstore.support.AbstractBlobContainer; import org.elasticsearch.common.blobstore.support.AbstractBlobContainer;
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData; import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.collect.MapBuilder;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -50,11 +51,13 @@ public abstract class AbstractFsBlobContainer extends AbstractBlobContainer {
if (files == null || files.length == 0) { if (files == null || files.length == 0) {
return ImmutableMap.of(); return ImmutableMap.of();
} }
ImmutableMap.Builder<String, BlobMetaData> builder = ImmutableMap.builder(); MapBuilder<String, BlobMetaData> builder = MapBuilder.newMapBuilder();
for (File file : files) { for (File file : files) {
if (file.isFile()) {
builder.put(file.getName(), new PlainBlobMetaData(file.getName(), file.length())); builder.put(file.getName(), new PlainBlobMetaData(file.getName(), file.length()));
} }
return builder.build(); }
return builder.immutableMap();
} }
public boolean deleteBlob(String blobName) throws IOException { public boolean deleteBlob(String blobName) throws IOException {