-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix for a bug #2226 #2231
Merged
Merged
fix for a bug #2226 #2231
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6acebe1
fix for a bug #2226 I think
cb9ad42
got my go build working; added nil-safe check also
47da136
simplified code slightly by combining both edge cases into a single i…
39a5751
improved tests
e969e3b
Revert "improved tests"
0e2cbb1
improved tests
d7968d9
improved tests by removing unneeded code
58b5ce4
suppressed extraneous warning
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,18 +97,20 @@ func RunBackup(backupCmd *Command, log logrus.FieldLogger, updateFunc func(veler | |
select { | ||
case <-ticker.C: | ||
lastLine := getLastLine(stdoutBuf.Bytes()) | ||
stat, err := decodeBackupStatusLine(lastLine) | ||
if err != nil { | ||
log.WithError(err).Errorf("error getting restic backup progress") | ||
} | ||
|
||
// if the line contains a non-empty bytes_done field, we can update the | ||
// caller with the progress | ||
if stat.BytesDone != 0 { | ||
updateFunc(velerov1api.PodVolumeOperationProgress{ | ||
TotalBytes: stat.TotalBytes, | ||
BytesDone: stat.BytesDone, | ||
}) | ||
if len(lastLine) > 0 { | ||
stat, err := decodeBackupStatusLine(lastLine) | ||
if err != nil { | ||
log.WithError(err).Errorf("error getting restic backup progress") | ||
} | ||
|
||
// if the line contains a non-empty bytes_done field, we can update the | ||
// caller with the progress | ||
if stat.BytesDone != 0 { | ||
updateFunc(velerov1api.PodVolumeOperationProgress{ | ||
TotalBytes: stat.TotalBytes, | ||
BytesDone: stat.BytesDone, | ||
}) | ||
} | ||
} | ||
case <-quit: | ||
ticker.Stop() | ||
|
@@ -153,6 +155,9 @@ func decodeBackupStatusLine(lastLine []byte) (backupStatusLine, error) { | |
// have a newline at the end of it, so this returns the substring between the | ||
// last two newlines. | ||
func getLastLine(b []byte) []byte { | ||
if b == nil || len(b) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should be able to just do |
||
return []byte("") | ||
} | ||
// subslice the byte array to ignore the newline at the end of the string | ||
lastNewLineIdx := bytes.LastIndex(b[:len(b)-1], []byte("\n")) | ||
return b[lastNewLineIdx+1 : len(b)-1] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'd be more consistent with go style to invert this, so e.g.
so the main logic can be less indented. this is not a merge-blocking comment, though.