// BuildSnapfsSnap the given sourceDirectory and return the generated snap file func BuildSnapfsSnap(sourceDir, targetDir string) (string, error) { // create build dir buildDir, err := ioutil.TempDir("", "snappy-build-") if err != nil { return "", err } defer os.RemoveAll(buildDir) snapName, err := prepare(sourceDir, targetDir, buildDir) if err != nil { return "", err } d := snapfs.New(snapName) if err = d.Build(buildDir); err != nil { return "", err } return snapName, nil }
// OpenPackageFile opens a given snap file with the right backend func OpenPackageFile(path string) (PackageFile, error) { f, err := os.Open(path) if err != nil { return nil, err } defer f.Close() // look, libmagic! header := make([]byte, 20) if _, err := f.Read(header); err != nil { return nil, err } // note that we only support little endian squashfs for now if bytes.HasPrefix(header, []byte{'h', 's', 'q', 's'}) { return snapfs.New(path), nil } if strings.HasPrefix(string(header), "!<arch>\ndebian") { return clickdeb.Open(path) } return nil, fmt.Errorf("unknown header %v", header) }