mirror of
https://github.com/octoleo/restic.git
synced 2025-01-03 07:12:28 +00:00
Add nil-receiver awareness to all Reader/Writer
This commit is contained in:
parent
dbc41bb805
commit
98dc811536
@ -115,6 +115,10 @@ func (l *blobReader) Read(p []byte) (int, error) {
|
||||
}
|
||||
|
||||
func (l *blobReader) Close() error {
|
||||
if l == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !l.closed {
|
||||
err := l.f.Close()
|
||||
l.closed = true
|
||||
|
@ -554,6 +554,10 @@ func (r *SFTP) ID() string {
|
||||
|
||||
// Close closes the sftp connection and terminates the underlying command.
|
||||
func (s *SFTP) Close() error {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
s.c.Close()
|
||||
// TODO: add timeout after which the process is killed
|
||||
return s.cmd.Wait()
|
||||
|
@ -24,6 +24,10 @@ func NewHashAppendWriter(w io.Writer, h hash.Hash) *HashAppendWriter {
|
||||
}
|
||||
|
||||
func (h *HashAppendWriter) Close() error {
|
||||
if h == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !h.closed {
|
||||
h.closed = true
|
||||
|
||||
|
@ -30,7 +30,7 @@ func (d *decryptReader) free() {
|
||||
}
|
||||
|
||||
func (d *decryptReader) Close() error {
|
||||
if d.buf == nil {
|
||||
if d == nil || d.buf == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -72,14 +72,15 @@ func DecryptFrom(ks *Key, rd io.Reader) (io.ReadCloser, error) {
|
||||
buf := bytes.NewBuffer(getBuffer()[:0])
|
||||
_, err := buf.ReadFrom(rd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return (*decryptReader)(nil), err
|
||||
}
|
||||
|
||||
ciphertext := buf.Bytes()
|
||||
|
||||
ciphertext, err = Decrypt(ks, ciphertext, ciphertext)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
freeBuffer(ciphertext)
|
||||
return (*decryptReader)(nil), err
|
||||
}
|
||||
|
||||
return &decryptReader{buf: ciphertext, rd: bytes.NewReader(ciphertext)}, nil
|
||||
|
@ -17,6 +17,10 @@ type encryptWriter struct {
|
||||
}
|
||||
|
||||
func (e *encryptWriter) Close() error {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if e.closed {
|
||||
return errors.New("Close() called on already closed writer")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user