niacdoial cdda40db36
Improve fsck handling and output (#2492)
* Fsck: Improved message handling and decreased commit spam.

* Merge upstream changes with local changes (part 2: manual fixes)

* pgp keyring: Do not import a pgp public key into the user's private keyring if the key there is identical to the one in the store's keyring

* fsck.go: made the code more go-idiomatic

* more changes to make code more go-idiomatic

* Fsck: fixed misleading messages caused by previous refactor

(also clarified the roles of the values in ErrorSeverity)

* Fsck: even smoother git use (pubkey updates now in the same git commit as the rest of fsck's changes)

Also removed dupeicate check of public keys, and added more tests around commit messages

* Ctxutil: Pruning unused functions, more go idiomaticity (and some tweaks regarding errors)

* Formatted files with gofmt

* fixed misc. error management

* More fixes and formatting

(plus one fixed text for the `link` action)

* unblock CI (attempt 1)

* fix problems discovered by CI

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
Co-authored-by: Dominik Schulz <dominik.schulz@gauner.org>
2023-01-01 14:52:55 +01:00

47 lines
1.1 KiB
Go

package leaf
import (
"context"
"errors"
"fmt"
"github.com/gopasspw/gopass/internal/queue"
"github.com/gopasspw/gopass/internal/store"
"github.com/gopasspw/gopass/pkg/debug"
)
// Link creates a symlink.
func (s *Store) Link(ctx context.Context, from, to string) error {
if !s.Exists(ctx, from) {
return fmt.Errorf("source %q does not exists", from)
}
if s.Exists(ctx, to) {
return fmt.Errorf("destination %q already exists", to)
}
if err := s.storage.Link(ctx, s.Passfile(from), s.Passfile(to)); err != nil {
return fmt.Errorf("failed to create symlink from %q to %q: %w", from, to, err)
}
debug.Log("created symlink from %q to %q", from, to)
if err := s.storage.Add(ctx, s.Passfile(to)); err != nil {
if errors.Is(err, store.ErrGitNotInit) {
return nil
}
return fmt.Errorf("failed to add %q to git: %w", to, err)
}
// try to enqueue this task, if the queue is not available
// it will return the task and we will execute it inline
t := queue.GetQueue(ctx).Add(func(ctx context.Context) (context.Context, error) {
return nil, s.gitCommitAndPush(ctx, to)
})
_, err := t(ctx)
return err
}