forked from TrueCloudLab/restic
Return context error in mem backend
This commit is contained in:
parent
4707bdb204
commit
fef408a8bd
1 changed files with 10 additions and 6 deletions
|
@ -47,10 +47,10 @@ func (be *MemoryBackend) Test(ctx context.Context, h restic.Handle) (bool, error
|
|||
debug.Log("Test %v", h)
|
||||
|
||||
if _, ok := be.data[h]; ok {
|
||||
return true, nil
|
||||
return true, ctx.Err()
|
||||
}
|
||||
|
||||
return false, nil
|
||||
return false, ctx.Err()
|
||||
}
|
||||
|
||||
// IsNotExist returns true if the file does not exist.
|
||||
|
@ -83,7 +83,7 @@ func (be *MemoryBackend) Save(ctx context.Context, h restic.Handle, rd restic.Re
|
|||
be.data[h] = buf
|
||||
debug.Log("saved %v bytes at %v", len(buf), h)
|
||||
|
||||
return nil
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
// Load runs fn with a reader that yields the contents of the file at h at the
|
||||
|
@ -124,7 +124,7 @@ func (be *MemoryBackend) openReader(ctx context.Context, h restic.Handle, length
|
|||
buf = buf[:length]
|
||||
}
|
||||
|
||||
return ioutil.NopCloser(bytes.NewReader(buf)), nil
|
||||
return ioutil.NopCloser(bytes.NewReader(buf)), ctx.Err()
|
||||
}
|
||||
|
||||
// Stat returns information about a file in the backend.
|
||||
|
@ -147,7 +147,7 @@ func (be *MemoryBackend) Stat(ctx context.Context, h restic.Handle) (restic.File
|
|||
return restic.FileInfo{}, errNotFound
|
||||
}
|
||||
|
||||
return restic.FileInfo{Size: int64(len(e)), Name: h.Name}, nil
|
||||
return restic.FileInfo{Size: int64(len(e)), Name: h.Name}, ctx.Err()
|
||||
}
|
||||
|
||||
// Remove deletes a file from the backend.
|
||||
|
@ -163,7 +163,7 @@ func (be *MemoryBackend) Remove(ctx context.Context, h restic.Handle) error {
|
|||
|
||||
delete(be.data, h)
|
||||
|
||||
return nil
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
// List returns a channel which yields entries from the backend.
|
||||
|
@ -213,6 +213,10 @@ func (be *MemoryBackend) Delete(ctx context.Context) error {
|
|||
be.m.Lock()
|
||||
defer be.m.Unlock()
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
be.data = make(memMap)
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue