mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
log: close log file before calling truncate on windows
If you truncate an open file in Windows, access is denied. how about close the file before truncation?
This commit is contained in:
parent
e9e69d6e29
commit
c4fb2d89b1
1 changed files with 8 additions and 1 deletions
|
|
@ -125,7 +125,14 @@ func prepFile(path string) (*countingWriter, error) {
|
|||
return nil, err
|
||||
}
|
||||
ns := fi.Size() - cut
|
||||
if err = f.Truncate(ns); err != nil {
|
||||
if err := f.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = os.Truncate(path, ns); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err = os.OpenFile(path, os.O_RDWR|os.O_APPEND, 0600)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &countingWriter{w: f, count: uint(ns)}, nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue