(ctx context.Context, required bool)
| 40 | } |
| 41 | |
| 42 | func (c *App) openRepository(ctx context.Context, required bool) (repo.Repository, error) { |
| 43 | if _, err := os.Stat(c.repositoryConfigFileName()); os.IsNotExist(err) { |
| 44 | if !required { |
| 45 | return nil, nil |
| 46 | } |
| 47 | |
| 48 | return nil, errors.New("repository is not connected. See https://kopia.io/docs/repositories/") |
| 49 | } |
| 50 | |
| 51 | c.maybePrintUpdateNotification(ctx) |
| 52 | |
| 53 | pass, err := c.getPasswordFromFlags(ctx, false, true) |
| 54 | if err != nil { |
| 55 | return nil, errors.Wrap(err, "get password") |
| 56 | } |
| 57 | |
| 58 | r, err := repo.Open(ctx, c.repositoryConfigFileName(), pass, c.optionsFromFlags(ctx)) |
| 59 | if os.IsNotExist(err) { |
| 60 | return nil, errors.New("not connected to a repository, use 'kopia connect'") |
| 61 | } |
| 62 | |
| 63 | return r, errors.Wrap(err, "unable to open repository") |
| 64 | } |
| 65 | |
| 66 | func (c *App) optionsFromFlags(ctx context.Context) *repo.Options { |
| 67 | return &repo.Options{ |
no test coverage detected