Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Fix filehandling for windows #392

Merged
merged 3 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fileutil/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Rename(from, to string) error {
// It is not atomic.
func Replace(from, to string) error {
if err := os.RemoveAll(to); err != nil {
return nil
return err
}
if err := os.Rename(from, to); err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,6 @@ func MigrateWAL(logger log.Logger, dir string) (err error) {
if err != nil {
return errors.Wrap(err, "open old WAL")
}
defer w.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's an error, below removing this could mean the wal is left open


rdr := w.Reader()

Expand Down Expand Up @@ -1309,6 +1308,9 @@ func MigrateWAL(logger log.Logger, dir string) (err error) {
if err := repl.Close(); err != nil {
return errors.Wrap(err, "close new WAL")
}
if err := w.Close(); err != nil {
return errors.Wrap(err, "close old WAL")
}
if err := fileutil.Replace(tmpdir, dir); err != nil {
return errors.Wrap(err, "replace old WAL")
}
Expand Down
6 changes: 4 additions & 2 deletions wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,18 @@ func (w *WAL) Repair(origErr error) error {
if err != nil {
return errors.Wrap(err, "open segment")
}
defer f.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

r := NewReader(bufio.NewReader(f))

for r.Next() {
if err := w.Log(r.Record()); err != nil {
return errors.Wrap(err, "insert record")
}
}
// We expect an error here, so nothing to handle.
// We expect an error here from r.Err(), so nothing to handle.

if err := f.Close(); err != nil {
return errors.Wrap(err, "close corrupted file")
}
if err := os.Remove(tmpfn); err != nil {
return errors.Wrap(err, "delete corrupted segment")
}
Expand Down