fix seek error for 0 file size records file

by add extra check for file size = 0 in cleanlast()
- (http://mantis.tokeek.de/view.php?id=411)
This commit is contained in:
reger 2014-07-06 20:49:01 +02:00
parent 1f2eba977d
commit 2b8cc5832c

View File

@ -399,10 +399,14 @@ public final class Records {
return;
}
// read entry from the file
final long endpos = this.raf.length() - this.recordsize;
long endpos = this.raf.length() - this.recordsize;
if (endpos >= 0) { // prevent seek error for 0 size file
this.raf.seek(endpos);
this.raf.readFully(b, start, this.recordsize);
} else {
endpos = 0;
System.arraycopy(this.zero, 0, b, start, this.recordsize);
}
// write zero bytes to the cache and to the file
this.raf.seek(endpos);
this.raf.write(this.zero, 0, this.recordsize);
@ -434,6 +438,7 @@ public final class Records {
return;
}
// shrink file
if (this.raf.length() > 0) // already 0 length, nothing to shrink (prevent seek io error)
this.raf.setLength(this.raf.length() - this.recordsize);
}