Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

Commit

Permalink
fix: LDC-03 Lock Not Released in Error Scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyWh1te committed Feb 20, 2023
1 parent 7a391fa commit 961f0e2
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions cmd/airgapped/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,23 +449,33 @@ func (p *prompt) run() error {
if err = p.enterEncryptionPasswordIfNeeded(); err != nil {
return err
}
p.airgapped.Lock()

p.currentCommand = clearCommand

// we need to "turn off" terminal lib during command execution to be able to handle OS notifications inside
// commands and to read data from stdin without terminal features
p.restoreTerminal()
if err := handler.commandHandler(); err != nil {
p.printf("failed to execute command %s: %v \n", command, err)
}
// after command done, we turning terminal lib back on
if err = p.makeTerminal(); err != nil {
return err
terExe := func(prompt *prompt) error {
prompt.airgapped.Lock()
defer func() {
prompt.currentCommand = ""
prompt.airgapped.Unlock()
}()

prompt.currentCommand = clearCommand

// we need to "turn off" terminal lib during command execution to be able to handle OS notifications inside
// commands and to read data from stdin without terminal features
prompt.restoreTerminal()
if err := handler.commandHandler(); err != nil {
prompt.printf("failed to execute command %s: %v \n", command, err)
}
// after command done, we turning terminal lib back on
if err = prompt.makeTerminal(); err != nil {
return err
}

return nil
}

p.currentCommand = ""
p.airgapped.Unlock()
if termErr := terExe(p); termErr != nil {
return termErr
}
}
}
}
Expand Down

0 comments on commit 961f0e2

Please sign in to comment.