From 0aa278efa03df3b23d0afdf205574c9ca712827d Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Thu, 4 Nov 2021 10:01:20 +0800 Subject: [PATCH] fix: follow file not updating when file is trunc --- handler.go | 5 +---- templates/base/script.tmpl | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/handler.go b/handler.go index e9541e0..88b6455 100644 --- a/handler.go +++ b/handler.go @@ -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) diff --git a/templates/base/script.tmpl b/templates/base/script.tmpl index abf725b..71d6cfe 100644 --- a/templates/base/script.tmpl +++ b/templates/base/script.tmpl @@ -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); }