Skip to content

Commit

Permalink
修复 saveETagIndex 可能写入不全的问题 (#2926)
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo authored Mar 14, 2024
1 parent c083846 commit b88d7c4
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,12 @@ public void saveETagIndex() throws IOException {
ETagIndex indexOnDisk = JsonUtils.fromMaybeMalformedJson(new String(IOUtils.readFullyWithoutClosing(Channels.newInputStream(channel)), UTF_8), ETagIndex.class);
Map<String, ETagItem> newIndex = joinETagIndexes(indexOnDisk == null ? null : indexOnDisk.eTag, index.values());
channel.truncate(0);
ETagIndex writeTo = new ETagIndex(newIndex.values());
channel.write(ByteBuffer.wrap(JsonUtils.GSON.toJson(writeTo).getBytes(UTF_8)));
ByteBuffer writeTo = ByteBuffer.wrap(JsonUtils.GSON.toJson(new ETagIndex(newIndex.values())).getBytes(UTF_8));
while (writeTo.hasRemaining()) {
if (channel.write(writeTo) == 0) {
throw new IOException("No value is written");
}
}
this.index = newIndex;
} finally {
lock.release();
Expand Down

0 comments on commit b88d7c4

Please sign in to comment.