Esempio n. 1
0
func writeDB(jirix *jiri.X, db *profiles.DB, installer, path string) error {
	// Do nothing if the installer is not supplied. This will generally
	// happen when/if writeDB is called from the top-level profile driver
	// command rather than from a subcommand.
	if installer == "" {
		return nil
	}
	fi, err := os.Stat(path)
	if err != nil {
		if !os.IsNotExist(err) {
			return err
		}
		// New setup, but the directory doesn't exist yet.
		if err := os.MkdirAll(path, os.FileMode(0755)); err != nil {
			return err
		}
	} else {
		if !fi.IsDir() {
			return fmt.Errorf("%s exists but is not a directory", path)
		}
	}
	// New setup with installers writing their own file in a directory
	return db.Write(jirix, installer, path)
}