2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-04 01:50:48 +00:00

Correctly deal with empty files

This commit is contained in:
Alexander Neumann 2014-11-30 16:06:37 +01:00
parent 6d56d7d4c6
commit c0b3021494
3 changed files with 6 additions and 6 deletions

View File

@ -167,13 +167,13 @@ func (arch *Archiver) SaveFile(node *Node) error {
buf := GetChunkBuf("blob single file") buf := GetChunkBuf("blob single file")
defer FreeChunkBuf("blob single file", buf) defer FreeChunkBuf("blob single file", buf)
n, err := io.ReadFull(file, buf) n, err := io.ReadFull(file, buf)
if err != nil && err != io.ErrUnexpectedEOF { if err != nil && err != io.ErrUnexpectedEOF && err != io.EOF {
return err return arrar.Annotate(err, "SaveFile() read small file")
} }
blob, err := arch.ch.Save(backend.Data, buf[:n]) blob, err := arch.ch.Save(backend.Data, buf[:n])
if err != nil { if err != nil {
return err return arrar.Annotate(err, "SaveFile() save chunk")
} }
arch.update(arch.SaveStats, Stats{Bytes: blob.Size}) arch.update(arch.SaveStats, Stats{Bytes: blob.Size})
@ -195,7 +195,7 @@ func (arch *Archiver) SaveFile(node *Node) error {
if err != nil { if err != nil {
FreeChunkBuf("blob chunker", buf) FreeChunkBuf("blob chunker", buf)
return err return arrar.Annotate(err, "SaveFile() chunker.Next()")
} }
// acquire token, start goroutine to save chunk // acquire token, start goroutine to save chunk
@ -231,7 +231,7 @@ func (arch *Archiver) SaveFile(node *Node) error {
arch.bl.Insert(blob) arch.bl.Insert(blob)
} }
return err return nil
} }
func (arch *Archiver) loadTree(dir string) (*Tree, error) { func (arch *Archiver) loadTree(dir string) (*Tree, error) {

2
key.go
View File

@ -374,7 +374,7 @@ func (k *Key) Encrypt(ciphertext, plaintext []byte) (int, error) {
// IV || Ciphertext || HMAC. // IV || Ciphertext || HMAC.
func (k *Key) decrypt(ks *keys, ciphertext []byte) ([]byte, error) { func (k *Key) decrypt(ks *keys, ciphertext []byte) ([]byte, error) {
// check for plausible length // check for plausible length
if len(ciphertext) <= ivSize+hmacSize { if len(ciphertext) < ivSize+hmacSize {
panic("trying to decryipt invalid data: ciphertext too small") panic("trying to decryipt invalid data: ciphertext too small")
} }

Binary file not shown.