mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
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:
parent
1f2eba977d
commit
2b8cc5832c
|
@ -116,7 +116,7 @@ public final class Records {
|
|||
this.buffer = new byte[buffersize];
|
||||
this.buffercount = 0;
|
||||
}
|
||||
|
||||
|
||||
public void clear() {
|
||||
try {
|
||||
this.raf.setLength(0);
|
||||
|
@ -399,10 +399,14 @@ public final class Records {
|
|||
return;
|
||||
}
|
||||
// read entry from the file
|
||||
final long endpos = this.raf.length() - this.recordsize;
|
||||
this.raf.seek(endpos);
|
||||
this.raf.readFully(b, start, 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,7 +438,8 @@ public final class Records {
|
|||
return;
|
||||
}
|
||||
// shrink file
|
||||
this.raf.setLength(this.raf.length() - this.recordsize);
|
||||
if (this.raf.length() > 0) // already 0 length, nothing to shrink (prevent seek io error)
|
||||
this.raf.setLength(this.raf.length() - this.recordsize);
|
||||
}
|
||||
|
||||
public final void deleteOnExit() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user