Browse Source

Java: FilerProto.Entry can read size via attributes

pull/2280/head
Chris Lu 3 years ago
parent
commit
2ead7adaff
  1. 19
      other/java/client/src/main/java/seaweedfs/client/FilerClient.java

19
other/java/client/src/main/java/seaweedfs/client/FilerClient.java

@ -59,15 +59,28 @@ public class FilerClient extends FilerGrpcClient {
public static FilerProto.Entry afterEntryDeserialization(FilerProto.Entry entry) { public static FilerProto.Entry afterEntryDeserialization(FilerProto.Entry entry) {
if (entry.getChunksList().size() <= 0) { if (entry.getChunksList().size() <= 0) {
if (entry.getContent().isEmpty()) {
return entry; return entry;
} else {
if (entry.getAttributes().getFileSize() <= 0) {
FilerProto.Entry.Builder entryBuilder = entry.toBuilder();
FilerProto.FuseAttributes.Builder attrBuilder = entry.getAttributes().toBuilder();
attrBuilder.setFileSize(entry.getContent().size());
entryBuilder.setAttributes(attrBuilder);
return entryBuilder.build();
}
} }
return entry;
} else {
String fileId = entry.getChunks(0).getFileId(); String fileId = entry.getChunks(0).getFileId();
if (fileId != null && fileId.length() != 0) { if (fileId != null && fileId.length() != 0) {
return entry; return entry;
} }
FilerProto.Entry.Builder entryBuilder = entry.toBuilder(); FilerProto.Entry.Builder entryBuilder = entry.toBuilder();
entryBuilder.clearChunks(); entryBuilder.clearChunks();
long fileSize = 0;
for (FilerProto.FileChunk chunk : entry.getChunksList()) { for (FilerProto.FileChunk chunk : entry.getChunksList()) {
fileSize = Math.max(fileSize, chunk.getOffset()+chunk.getSize());
FilerProto.FileChunk.Builder chunkBuilder = chunk.toBuilder(); FilerProto.FileChunk.Builder chunkBuilder = chunk.toBuilder();
chunkBuilder.setFileId(toFileId(chunk.getFid())); chunkBuilder.setFileId(toFileId(chunk.getFid()));
String sourceFileId = toFileId(chunk.getSourceFid()); String sourceFileId = toFileId(chunk.getSourceFid());
@ -76,8 +89,14 @@ public class FilerClient extends FilerGrpcClient {
} }
entryBuilder.addChunks(chunkBuilder); entryBuilder.addChunks(chunkBuilder);
} }
if (entry.getAttributes().getFileSize() <= 0) {
FilerProto.FuseAttributes.Builder attrBuilder = entry.getAttributes().toBuilder();
attrBuilder.setFileSize(fileSize);
entryBuilder.setAttributes(attrBuilder);
}
return entryBuilder.build(); return entryBuilder.build();
} }
}
public boolean mkdirs(String path, int mode) { public boolean mkdirs(String path, int mode) {
String currentUser = System.getProperty("user.name"); String currentUser = System.getProperty("user.name");

Loading…
Cancel
Save