Skip to content

Commit

Permalink
fix: properly detect token not found error
Browse files Browse the repository at this point in the history
It can have 2 different message kinds.

Signed-off-by: Artem Chernyshev <[email protected]>
  • Loading branch information
Unix4ever committed Jul 4, 2023
1 parent 3e08968 commit fbb01f7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion blockdevice/encryption/luks/luks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"errors"
"fmt"
"os"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -328,6 +329,8 @@ func (l *LUKS) RemoveToken(devname string, slot int) error {
return err
}

var notFoundMatcher = regexp.MustCompile("(is not in use|Failed to get token)")

// runCommand executes cryptsetup with arguments.
func (l *LUKS) runCommand(args []string, stdin []byte) (string, error) {
stdout, err := cmd.RunContext(cmd.WithStdin(
Expand All @@ -343,7 +346,7 @@ func (l *LUKS) runCommand(args []string, stdin []byte) (string, error) {
return "", encryption.ErrEncryptionKeyRejected
}

if strings.Contains(string(exitError.Output), "is not in use") {
if notFoundMatcher.Match(exitError.Output) {
return "", encryption.ErrTokenNotFound
}
case 2:
Expand Down

0 comments on commit fbb01f7

Please sign in to comment.