fix: follow file not updating when file is trunc

feat/muzan
Evan Chen 2021-11-04 10:01:20 +08:00
parent 04580e4672
commit 0aa278efa0
2 changed files with 4 additions and 6 deletions

View File

@ -71,10 +71,7 @@ func (cui *ConfigUI) GetDelta(w http.ResponseWriter, r *http.Request) {
panic(err)
}
if delta > stat.Size() {
panic(fmt.Errorf("delta(%d) is larger than file size(%d)", delta, stat.Size()))
}
if stat.Size() < delta {
panic(fmt.Errorf("delta(%d) is smaller than file size(%d)", delta, stat.Size()))
panic(fmt.Errorf("delta(%d) is larger than file size(%d), the file might have been changed", delta, stat.Size()))
}
buf := make([]byte, stat.Size()-delta)
_, err = f.ReadAt(buf, delta)

View File

@ -83,11 +83,12 @@ async function FileDelta(){
else {
const res = await fetch('{{.BaseUrl}}api/delta?f=true&name=' + Active+'&delta='+LastDelta)
.catch(err=>{console.log(err);return;});
const body = await res.json();
if(!res.ok){
Catch(res)
await Catch(res)
FileGet()
return
}
const body = await res.json();
LastDelta = body.delta;
editor.session.setValue(editor.getValue()+body.data);
}