-
Notifications
You must be signed in to change notification settings - Fork 0
/
sharing_utils.go
31 lines (24 loc) · 1.01 KB
/
sharing_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package cmd
import (
"fmt"
paths "path"
"github.com/spf13/cobra"
"github.com/archivekeep/archivekeep/archive"
"github.com/archivekeep/archivekeep/internal/cli/currentarchive"
"github.com/archivekeep/archivekeep/internal/util"
"github.com/archivekeep/archivekeep/x/archive/wrapper/readonly"
"github.com/archivekeep/archivekeep/x/operations/sharing"
)
func openForSharing(cmd *cobra.Command, allowWrite bool) (string, *sharing.SingleArchive, error) {
currentArchive, err := currentarchive.OpenAndUnlockKeyring(util.PasswordPrompt(cmd, "Enter keyring password: "))
if err != nil {
return "", nil, fmt.Errorf("open current archive: %w", err)
}
currentArchiveName := paths.Base(currentArchive.Location())
var currentArchiveAccessor archive.ReadWriter = currentArchive
if !allowWrite {
currentArchiveAccessor = &readonly.Archive{Base: currentArchiveAccessor}
}
sharingArchiveManager := sharing.NewSingleArchive(currentArchiveAccessor, currentArchive.Keyring())
return currentArchiveName, sharingArchiveManager, nil
}