Example #1
0
// NewSnapFile loads a snap from the given snapFile
func NewSnapFile(snapFile string, origin string, unsignedOk bool) (*SnapFile, error) {
	d, err := snap.Open(snapFile)
	if err != nil {
		return nil, err
	}

	yamlData, err := d.MetaMember("package.yaml")
	if err != nil {
		return nil, err
	}

	_, err = d.MetaMember("hooks/config")
	hasConfig := err == nil

	m, err := parsePackageYamlData(yamlData, hasConfig)
	if err != nil {
		return nil, err
	}

	targetDir := dirs.SnapSnapsDir
	if origin == SideloadedOrigin {
		m.Version = helpers.NewSideloadVersion()
	}

	fullName := m.qualifiedName(origin)
	instDir := filepath.Join(targetDir, fullName, m.Version)

	return &SnapFile{
		instdir: instDir,
		origin:  origin,
		m:       m,
		deb:     d,
	}, nil
}
Example #2
0
func (s *SortTestSuite) TestSideloadVersion(c *C) {
	n := 1000
	vs := make(ByVersion, n)

	for i := 0; i < n; i++ {
		vs[i] = helpers.NewSideloadVersion()
	}

	c.Check(sort.IsSorted(vs), Equals, true)
}
Example #3
0
// NewSnapPartFromSnapFile loads a snap from the given (clickdeb) snap file.
// Caller should call Close on the pkg.
// TODO: expose that Close.
func NewSnapPartFromSnapFile(snapFile string, origin string, unauthOk bool) (*SnapPart, error) {
	d, err := OpenPackageFile(snapFile)
	if err != nil {
		return nil, err
	}

	if err := d.Verify(unauthOk); err != nil {
		return nil, err
	}

	yamlData, err := d.MetaMember("package.yaml")
	if err != nil {
		return nil, err
	}

	_, err = d.MetaMember("hooks/config")
	hasConfig := err == nil

	m, err := parsePackageYamlData(yamlData, hasConfig)
	if err != nil {
		return nil, err
	}

	targetDir := dirs.SnapAppsDir
	// the "oem" parts are special
	if m.Type == pkg.TypeOem {
		targetDir = dirs.SnapOemDir
	}

	if origin == SideloadedOrigin {
		m.Version = helpers.NewSideloadVersion()
	}

	fullName := m.qualifiedName(origin)
	instDir := filepath.Join(targetDir, fullName, m.Version)

	return &SnapPart{
		basedir: instDir,
		origin:  origin,
		m:       m,
		deb:     d,
	}, nil
}