Open opens a Repository specified in the configuration file.
(ctx context.Context, configFile, password string, options *Options)
| 95 | |
| 96 | // Open opens a Repository specified in the configuration file. |
| 97 | func Open(ctx context.Context, configFile, password string, options *Options) (rep Repository, err error) { |
| 98 | ctx, span := tracer.Start(ctx, "OpenRepository") |
| 99 | defer span.End() |
| 100 | |
| 101 | defer func() { |
| 102 | if err != nil { |
| 103 | log(ctx).Errorf("failed to open repository: %v", err) |
| 104 | } |
| 105 | }() |
| 106 | |
| 107 | if options == nil { |
| 108 | options = &Options{} |
| 109 | } |
| 110 | |
| 111 | if options.OnFatalError == nil { |
| 112 | options.OnFatalError = func(err error) { |
| 113 | log(ctx).Errorf("FATAL: %v", err) |
| 114 | os.Exit(1) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | configFile, err = filepath.Abs(configFile) |
| 119 | if err != nil { |
| 120 | return nil, errors.Wrap(err, "error resolving config file path") |
| 121 | } |
| 122 | |
| 123 | lc, err := LoadConfigFromFile(configFile) |
| 124 | if err != nil { |
| 125 | return nil, err |
| 126 | } |
| 127 | |
| 128 | if lc.PermissiveCacheLoading && !lc.ReadOnly { |
| 129 | return nil, ErrCannotWriteToRepoConnectionWithPermissiveCacheLoading |
| 130 | } |
| 131 | |
| 132 | if lc.APIServer != nil { |
| 133 | return openAPIServer(ctx, lc.APIServer, lc.ClientOptions, lc.Caching, password, options) |
| 134 | } |
| 135 | |
| 136 | return openDirect(ctx, configFile, lc, password, options) |
| 137 | } |
| 138 | |
| 139 | func getContentCacheOrNil(ctx context.Context, si *APIServerInfo, opt *content.CachingOptions, password string, mr *metrics.Registry, timeNow func() time.Time) (*cache.PersistentCache, error) { |
| 140 | opt = opt.CloneOrDefault() |