continued work on encryption

This commit is contained in:
ston1th 2022-04-07 00:54:13 +02:00
commit 880e2f06b3
14 changed files with 362 additions and 39 deletions

View file

@ -59,6 +59,12 @@ func (f *File) Preload(ctx context.Context, unlock func()) {
log.V(2).Info("skipped preload for fully cached file")
return
}
// TODO
//fi, _ := f.Stat()
//s := fi.Size()
//log.V(2).Info("preload started", "size", s, "crypto.Size", crypto.Size(s), "crypto.RealSize", crypto.RealSize(crypto.Size(s)))
log.V(2).Info("preload started")
p := &preload{f: f, ctx: ctx}
_, err := io.Copy(Discard, p)
@ -69,7 +75,10 @@ func (f *File) Preload(ctx context.Context, unlock func()) {
if err != nil && err != io.EOF {
log.Error(err, "error preloading file")
}
f.md.Close()
err = f.md.Close()
if err != nil {
log.Error(err, "error closing cache file")
}
log.V(2).Info("preload finished", "skipped", p.skipped, "written", p.written)
}
@ -77,6 +86,9 @@ func (f *File) Read(p []byte) (n int, err error) {
log := f.log
if f.hasChunk(len(p)) {
n, err = f.md.ReadAt(p, f.offset)
if err == io.EOF {
return
}
if err != nil {
if !IsIOErr(err) {
log.Error(err, "error reading cache file")