Add error check to avoid panic (#4584)
* Add error check to avoid panic Signed-off-by: Cookie Wang <luckymrwang@163.com> * Add error check to avoid panic Signed-off-by: Cookie Wang <luckymrwang@163.com> Co-authored-by: Cookie Wang <luckymrwang@163.com>
This commit is contained in:
parent
40edf1e566
commit
b881a1ef13
1 changed files with 4 additions and 1 deletions
|
@ -117,11 +117,14 @@ func (h *Hostsfile) readHosts() {
|
|||
defer file.Close()
|
||||
|
||||
stat, err := file.Stat()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
h.RLock()
|
||||
size := h.size
|
||||
h.RUnlock()
|
||||
|
||||
if err == nil && h.mtime.Equal(stat.ModTime()) && size == stat.Size() {
|
||||
if h.mtime.Equal(stat.ModTime()) && size == stat.Size() {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue