|
|
|
@ -17,6 +17,7 @@ |
|
|
|
|
package cmd |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"hash" |
|
|
|
|
"io" |
|
|
|
|
|
|
|
|
@ -35,12 +36,12 @@ type wholeBitrotWriter struct { |
|
|
|
|
func (b *wholeBitrotWriter) Write(p []byte) (int, error) { |
|
|
|
|
err := b.disk.AppendFile(b.volume, b.filePath, p) |
|
|
|
|
if err != nil { |
|
|
|
|
logger.LogIf(GlobalContext, err) |
|
|
|
|
logger.LogIf(GlobalContext, fmt.Errorf("Disk: %s returned %w", b.disk, err)) |
|
|
|
|
return 0, err |
|
|
|
|
} |
|
|
|
|
_, err = b.Hash.Write(p) |
|
|
|
|
if err != nil { |
|
|
|
|
logger.LogIf(GlobalContext, err) |
|
|
|
|
logger.LogIf(GlobalContext, fmt.Errorf("Disk: %s returned %w", b.disk, err)) |
|
|
|
|
return 0, err |
|
|
|
|
} |
|
|
|
|
return len(p), nil |
|
|
|
@ -69,9 +70,7 @@ func (b *wholeBitrotReader) ReadAt(buf []byte, offset int64) (n int, err error) |
|
|
|
|
if b.buf == nil { |
|
|
|
|
b.buf = make([]byte, b.tillOffset-offset) |
|
|
|
|
if _, err := b.disk.ReadFile(b.volume, b.filePath, offset, b.buf, b.verifier); err != nil { |
|
|
|
|
ctx := GlobalContext |
|
|
|
|
logger.GetReqInfo(ctx).AppendTags("disk", b.disk.String()) |
|
|
|
|
logger.LogIf(ctx, err) |
|
|
|
|
logger.LogIf(GlobalContext, fmt.Errorf("Disk: %s returned %w", b.disk, err)) |
|
|
|
|
return 0, err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|