2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 06:46:34 +00:00

backend: Throw error when Close() is called twice

This commit is contained in:
Alexander Neumann 2015-02-16 00:24:02 +01:00
parent 259389f7d1
commit b816192d1c
2 changed files with 15 additions and 2 deletions

View File

@ -187,12 +187,19 @@ type localBlob struct {
tpe Type tpe Type
id ID id ID
size uint size uint
closed bool
} }
func (lb *localBlob) Close() error { func (lb *localBlob) Close() error {
if lb.closed {
return errors.New("Close() called on closed file")
}
lb.closed = true
err := lb.f.Close() err := lb.f.Close()
if err != nil { if err != nil {
return err return fmt.Errorf("local: file.Close: %v", err)
} }
// get ID // get ID

View File

@ -297,12 +297,18 @@ type sftpBlob struct {
tpe Type tpe Type
id ID id ID
size uint size uint
closed bool
} }
func (sb *sftpBlob) Close() error { func (sb *sftpBlob) Close() error {
if sb.closed {
return errors.New("Close() called on closed file")
}
sb.closed = true
err := sb.f.Close() err := sb.f.Close()
if err != nil { if err != nil {
return err return fmt.Errorf("sftp: file.Close: %v", err)
} }
// get ID // get ID