func newLogWriter(file desc.File) (p *logWriter, err error) { w := new(logWriter) w.file = file w.writer, err = file.Create() if err != nil { return } w.log = log.NewWriter(w.writer) return w, nil }
func newLogReader(file desc.File, checksum bool, dropf log.DropFunc) (p *logReader, err error) { r := new(logReader) r.file = file r.reader, err = file.Open() if err != nil { return } r.log = log.NewReader(r.reader, checksum, dropf) return r, nil }
func (h *dbCorruptHarness) corrupt(ft desc.FileType, offset, n int) { p := &h.dbHarness t := p.t var file desc.File for _, f := range p.desc.GetFiles(ft) { if file == nil || f.Num() > file.Num() { file = f } } if file == nil { t.Fatalf("no such file with type %q", ft) } r, err := file.Open() if err != nil { t.Fatal("cannot open file: ", err) } x, err := file.Size() if err != nil { t.Fatal("cannot query file size: ", err) } m := int(x) if offset < 0 { if -offset > m { offset = 0 } else { offset = m + offset } } if offset > m { offset = m } if offset+n > m { n = m - offset } buf := make([]byte, m) _, err = io.ReadFull(r, buf) if err != nil { t.Fatal("cannot read file: ", err) } r.Close() for i := 0; i < n; i++ { buf[offset+i] ^= 0x80 } err = file.Remove() if err != nil { t.Fatal("cannot remove old file: ", err) } w, err := file.Create() if err != nil { t.Fatal("cannot create new file: ", err) } _, err = w.Write(buf) if err != nil { t.Fatal("cannot write new file: ", err) } w.Close() }