Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
CodeUnableToDeletePasswordFile Code = 30
CodeUnableToDetermineIsDirectoryEmpty Code = 31
CodeUnableToDeleteEmptyDirectory Code = 32
CodeUnableToCommitPasswordFile Code = 33
)

// Field extra field in the error response params
Expand Down
18 changes: 18 additions & 0 deletions helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,21 @@ func IsDirectoryEmpty(dirPath string) (bool, error) {

return false, err
}

func GitAddAndCommit(storePath string, filePath string, message string) error {
cmd := exec.Command("git", "add", filePath)
cmd.Dir = storePath
_, err := cmd.Output()
if err != nil {
return err
}

cmd = exec.Command("git", "commit", "-m", message, "-o", filePath) // Only commit the file we added
cmd.Dir = storePath
_, err = cmd.Output()
if err != nil {
return err
}

return nil
}
21 changes: 21 additions & 0 deletions request/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package request
import (
"path/filepath"
"strings"
"fmt"

"github.com/browserpass/browserpass-native/errors"
"github.com/browserpass/browserpass-native/helpers"
Expand Down Expand Up @@ -149,5 +150,25 @@ func saveEncryptedContents(request *request) {
)
}

err = helpers.GitAddAndCommit(store.Path, filePath, fmt.Sprintf("browserpass: save %s", request.File))
if err != nil {
log.Errorf(
"Unable to commit the password file '%v' in the password store '%+v': %+v",
request.File, store, err,
)
response.SendErrorAndExit(
errors.CodeUnableToCommitPasswordFile,
&map[errors.Field]string{
errors.FieldMessage: "Unable to commit the password file",
errors.FieldAction: "save",
errors.FieldError: err.Error(),
errors.FieldFile: request.File,
errors.FieldStoreID: store.ID,
errors.FieldStoreName: store.Name,
errors.FieldStorePath: store.Path,
},
)
}

response.SendOk(responseData)
}