Skip to content

Commit

Permalink
Fix reading files from tar
Browse files Browse the repository at this point in the history
  • Loading branch information
emilienthomas committed Feb 27, 2019
1 parent 558204c commit 6b7f3a8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions xva/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Validate(xvaFileName string, verbosity uint) (isValid bool, validationIssue
}

sums := make(map[string]string)
fileContent := make([]byte, 1048576) // Build a 1MB array
fileContent := make([]byte, 1048576) // Build a 1MB array, since vm disks are store in 1MB chunks
checksumFromFile := make([]byte, 40)

if verbosity >= 2 {
Expand Down Expand Up @@ -102,11 +102,15 @@ func Validate(xvaFileName string, verbosity uint) (isValid bool, validationIssue
if verbosity >= 3 {
log.Println("It is a block file")
}
i, err := tarReader.Read(fileContent)
if err != nil && err != io.EOF {
// Read the complete file into fileContent
for i, j := 0, 0; err == nil; {
j, err = tarReader.Read(fileContent[i:header.Size])
i = i + j
}
if err != io.EOF {
return false, "", err
}
fileSum := sha1.Sum(fileContent[:i])
fileSum := sha1.Sum(fileContent[:header.Size])
fileSumAsHex := hex.EncodeToString(fileSum[:])

if len(sums[header.Name]) == 0 {
Expand Down

0 comments on commit 6b7f3a8

Please sign in to comment.