func ReadCharmDir(path string) (*CharmDir, error) {
	b := &CharmDir{
		Path:      path,
		charmBase: &charmBase{},
	}
	reader, err := os.Open(b.join("metadata.yaml"))
	if err != nil {
		return nil, errors.Annotatef(err, `reading "metadata.yaml" file`)
	}
	b.meta, err = ReadMeta(reader)
	_ = reader.Close()
	if err != nil {
		return nil, errors.Annotatef(err, `parsing "metadata.yaml" file`)
	}

	// Try to read the optional manifest.yaml, it's required to determine if
	// this charm is v1 or not.
	reader, err = os.Open(b.join("manifest.yaml"))
	if _, ok := err.(*os.PathError); ok {
		b.manifest = nil
	} else if err != nil {
		return nil, errors.Annotatef(err, `reading "manifest.yaml" file`)
	} else {
		b.manifest, err = ReadManifest(reader)
		_ = reader.Close()
		if err != nil {
			return nil, errors.Annotatef(err, `parsing "manifest.yaml" file`)
		}
	}

	reader, err = os.Open(b.join("config.yaml"))
	if _, ok := err.(*os.PathError); ok {
		b.config = NewConfig()
	} else if err != nil {
		return nil, errors.Annotatef(err, `reading "config.yaml" file`)
	} else {
		b.config, err = ReadConfig(reader)
		_ = reader.Close()
		if err != nil {
			return nil, errors.Annotatef(err, `parsing "config.yaml" file`)
		}
	}

	reader, err = os.Open(b.join("metrics.yaml"))
	if err == nil {
		b.metrics, err = ReadMetrics(reader)
		_ = reader.Close()
		if err != nil {
			return nil, errors.Annotatef(err, `parsing "metrics.yaml" file`)
		}
	} else if !os.IsNotExist(err) {
		return nil, errors.Annotatef(err, `reading "metrics.yaml" file`)
	}

	if b.actions, err = getActions(
		func(file string) (io.ReadCloser, error) {
			return os.Open(b.join(file))
		},
		func(err error) bool {
			_, ok := err.(*os.PathError)
			return ok
		},
	); err != nil {
		return nil, err
	}

	if reader, err = os.Open(b.join("revision")); err == nil {
		_, err = fmt.Fscan(reader, &b.revision)
		_ = reader.Close()
		if err != nil {
			return nil, errors.New("invalid revision file")
		}
	}

	reader, err = os.Open(b.join("lxd-profile.yaml"))
	if _, ok := err.(*os.PathError); ok {
		b.lxdProfile = NewLXDProfile()
	} else if err != nil {
		return nil, errors.Annotatef(err, `reading "lxd-profile.yaml" file`)
	} else {
		b.lxdProfile, err = ReadLXDProfile(reader)
		_ = reader.Close()
		if err != nil {
			return nil, errors.Annotatef(err, `parsing "lxd-profile.yaml" file`)
		}
	}

	reader, err = os.Open(b.join("version"))
	if err != nil {
		if _, ok := err.(*os.PathError); !ok {
			return nil, errors.Annotatef(err, `reading "version" file`)
		}
	} else {
		b.version, err = ReadVersion(reader)
		_ = reader.Close()
		if err != nil {
			return nil, errors.Annotatef(err, `parsing "version" file`)
		}
	}

	return b, nil
}
// ReadCharmDir returns a CharmDir representing an expanded charm directory.
ReadCharmDir returns a CharmDir representing an expanded charm directory.
// ReadCharmDir returns a CharmDir representing an expanded charm directory .
func ReadCharmDir(path string) (*CharmDir, error) {
	b := &CharmDir{
		Path:      path,
		charmBase: &charmBase{},
	}
	reader, err := os.Open(b.join("metadata.yaml"))
	if err != nil {
		return nil, errors.Annotatef(err, `reading "metadata.yaml" file`)
	}
	b.meta, err = ReadMeta(reader)
	_ = reader.Close()
	if err != nil {
		return nil, errors.Annotatef(err, `parsing "metadata.yaml" file`)
	}
	reader, err = os.Open(b.join("manifest.yaml"))
	if _, ok := err.(*os.PathError); ok {
		b.manifest = nil
	} else if err != nil {
		return nil, errors.Annotatef(err, `reading "manifest.yaml" file`)
	} else {
		b.manifest, err = ReadManifest(reader)
		_ = reader.Close()
		if err != nil {
			return nil, errors.Annotatef(err, `parsing "manifest.yaml" file`)
		}
	}
	reader, err = os.Open(b.join("config.yaml"))
	if _, ok := err.(*os.PathError); ok {
		b.config = NewConfig()
	} else if err != nil {
		return nil, errors.Annotatef(err, `reading "config.yaml" file`)
	} else {
		b.config, err = ReadConfig(reader)
		_ = reader.Close()
		if err != nil {
			return nil, errors.Annotatef(err, `parsing "config.yaml" file`)
		}
	}
	reader, err = os.Open(b.join("metrics.yaml"))
	if err == nil {
		b.metrics, err = ReadMetrics(reader)
		_ = reader.Close()
		if err != nil {
			return nil, errors.Annotatef(err, `parsing "metrics.yaml" file`)
		}
	} else if !os.IsNotExist(err) {
		return nil, errors.Annotatef(err, `reading "metrics.yaml" file`)
	}
	if b.actions, err = getActions(
		func(file string) (io.ReadCloser, error) {
			return os.Open(b.join(file))
		},
		func(err error) bool {
			_, ok := err.(*os.PathError)
			return ok
		},
	); err != nil {
		return nil, err
	}
	if reader, err = os.Open(b.join("revision")); err == nil {
		_, err = fmt.Fscan(reader, &b.revision)
		_ = reader.Close()
		if err != nil {
			return nil, errors.New("invalid revision file")
		}
	}
	reader, err = os.Open(b.join("lxd-profile.yaml"))
	if _, ok := err.(*os.PathError); ok {
		b.lxdProfile = NewLXDProfile()
	} else if err != nil {
		return nil, errors.Annotatef(err, `reading "lxd-profile.yaml" file`)
	} else {
		b.lxdProfile, err = ReadLXDProfile(reader)
		_ = reader.Close()
		if err != nil {
			return nil, errors.Annotatef(err, `parsing "lxd-profile.yaml" file`)
		}
	}
	reader, err = os.Open(b.join("version"))
	if err != nil {
		if _, ok := err.(*os.PathError); !ok {
			return nil, errors.Annotatef(err, `reading "version" file`)
		}
	} else {
		b.version, err = ReadVersion(reader)
		_ = reader.Close()
		if err != nil {
			return nil, errors.Annotatef(err, `parsing "version" file`)
		}
	}
	return b, nil
}
func ReadCharmDir ( path string ) ( * CharmDir , error ) { b := & CharmDir { Path : path , charmBase : & charmBase { } , } reader , err := os . Open ( b . join ( " " ) ) if err != nil { return nil , errors . Annotatef ( err , `reading "metadata.yaml" file` ) } b . meta , err = ReadMeta ( reader ) _ = reader . Close ( ) if err != nil { return nil , errors . Annotatef ( err , `parsing "metadata.yaml" file` ) } reader , err = os . Open ( b . join ( " " ) ) if _ , ok := err . ( * os . PathError ) ; ok { b . manifest = nil } else if err != nil { return nil , errors . Annotatef ( err , `reading "manifest.yaml" file` ) } else { b . manifest , err = ReadManifest ( reader ) _ = reader . Close ( ) if err != nil { return nil , errors . Annotatef ( err , `parsing "manifest.yaml" file` ) } } reader , err = os . Open ( b . join ( " " ) ) if _ , ok := err . ( * os . PathError ) ; ok { b . config = NewConfig ( ) } else if err != nil { return nil , errors . Annotatef ( err , `reading "config.yaml" file` ) } else { b . config , err = ReadConfig ( reader ) _ = reader . Close ( ) if err != nil { return nil , errors . Annotatef ( err , `parsing "config.yaml" file` ) } } reader , err = os . Open ( b . join ( " " ) ) if err == nil { b . metrics , err = ReadMetrics ( reader ) _ = reader . Close ( ) if err != nil { return nil , errors . Annotatef ( err , `parsing "metrics.yaml" file` ) } } else if ! os . IsNotExist ( err ) { return nil , errors . Annotatef ( err , `reading "metrics.yaml" file` ) } if b . actions , err = getActions ( func ( file string ) ( io . ReadCloser , error ) { return os . Open ( b . join ( file ) ) } , func ( err error ) bool { _ , ok := err . ( * os . PathError ) return ok } , ) ; err != nil { return nil , err } if reader , err = os . Open ( b . join ( " " ) ) ; err == nil { _ , err = fmt . Fscan ( reader , & b . revision ) _ = reader . Close ( ) if err != nil { return nil , errors . New ( " " ) } } reader , err = os . Open ( b . join ( " " ) ) if _ , ok := err . ( * os . PathError ) ; ok { b . lxdProfile = NewLXDProfile ( ) } else if err != nil { return nil , errors . Annotatef ( err , `reading "lxd-profile.yaml" file` ) } else { b . lxdProfile , err = ReadLXDProfile ( reader ) _ = reader . Close ( ) if err != nil { return nil , errors . Annotatef ( err , `parsing "lxd-profile.yaml" file` ) } } reader , err = os . Open ( b . join ( " " ) ) if err != nil { if _ , ok := err . ( * os . PathError ) ; ! ok { return nil , errors . Annotatef ( err , `reading "version" file` ) } } else { b . version , err = ReadVersion ( reader ) _ = reader . Close ( ) if err != nil { return nil , errors . Annotatef ( err , `parsing "version" file` ) } } return b , nil }
ReadCharmDir returns a CharmDir representing an expanded charm directory.
ReadCharmDir returns a CharmDir representing an expanded charm directory .
// Try to read the optional manifest.yaml, it's required to determine if // this charm is v1 or not.