Exemple #1
0
func loadConfig() *config.Config {
	// We do not use guessRepoFolder() here. It might abort
	folder := repo.GuessFolder()
	cfg, err := repoconfig.LoadConfig(filepath.Join(folder, ".brig", "config"))
	if err != nil {
		log.Warningf("Could not load config: %v", err)
		log.Warningf("Falling back on config defaults...")
		return repoconfig.CreateDefaultConfig()
	}

	return cfg
}
Exemple #2
0
// NewRepository creates a new repository at filesystem level
// and returns a Repository interface
func NewRepository(ID, pwd, folder string) (*Repository, error) {
	absFolderPath, err := filepath.Abs(folder)
	if err != nil {
		return nil, err
	}

	if _, err = os.Stat(absFolderPath); os.IsExist(err) {
		return nil, err
	}

	if err := createRepositoryTree(absFolderPath); err != nil {
		return nil, err
	}

	brigPath := filepath.Join(absFolderPath, ".brig")
	if err := createShadowFile(brigPath, ID, pwd); err != nil {
		return nil, err
	}

	cfg := config.CreateDefaultConfig()

	configDefaults := map[string]interface{}{
		"repository.id": ID,
		"ipfs.path":     filepath.Join(brigPath, "ipfs"),
	}

	for key, value := range configDefaults {
		if err = cfg.Set(key, value); err != nil {
			return nil, err
		}
	}

	if err := initIntoGlobal(brigPath, cfg); err != nil {
		return nil, err
	}

	configPath := filepath.Join(brigPath, "config")
	if _, err := config.SaveConfig(configPath, cfg); err != nil {
		return nil, err
	}

	return loadRepository(pwd, absFolderPath)
}