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:
kukugi 2020-01-14 18:10:59 +09:00
parent e9e69d6e29
commit c4fb2d89b1

View file

@ -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