// makeTestSnap here can also be used to produce broken snaps (differently from snaptest.MakeTestSnapWithFiles)! func makeTestSnap(c *C, yaml string) string { tmp := c.MkDir() snapSource := filepath.Join(tmp, "snapsrc") err := os.MkdirAll(filepath.Join(snapSource, "meta"), 0755) // our regular snap.yaml err = ioutil.WriteFile(filepath.Join(snapSource, "meta", "snap.yaml"), []byte(yaml), 0644) c.Assert(err, IsNil) dest := filepath.Join(tmp, "foo.snap") snap := squashfs.New(dest) err = snap.Build(snapSource) c.Assert(err, IsNil) return dest }
func downloadUnpackGadget(sto Store, model *asserts.Model, opts *Options, local *localInfos) error { if err := os.MkdirAll(opts.GadgetUnpackDir, 0755); err != nil { return fmt.Errorf("cannot create gadget unpack dir %q: %s", opts.GadgetUnpackDir, err) } dlOpts := &DownloadOptions{ TargetDir: opts.GadgetUnpackDir, Channel: opts.Channel, } snapFn, _, err := acquireSnap(sto, model.Gadget(), dlOpts, local) if err != nil { return err } // FIXME: jumping through layers here, we need to make // unpack part of the container interface (again) snap := squashfs.New(snapFn) return snap.Unpack("*", opts.GadgetUnpackDir) }
// BuildSquashfsSnap the given sourceDirectory and return the generated // snap file func BuildSquashfsSnap(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 := squashfs.New(snapName) if err = d.Build(buildDir); err != nil { return "", err } return snapName, nil }
Install(targetPath, mountDir string) error // Unpack unpacks the src parts to the dst directory Unpack(src, dst string) error } // backend implements a specific snap format type snapFormat struct { magic []byte open func(fn string) (Container, error) } // formatHandlers is the registry of known formats, squashfs is the only one atm. var formatHandlers = []snapFormat{ {squashfs.Magic, func(p string) (Container, error) { return squashfs.New(p), nil }}, } // Open opens a given snap file with the right backend func Open(path string) (Container, error) { // see if it's a snapdir first if osutil.FileExists(filepath.Join(path, "meta", "snap.yaml")) { return snapdir.New(path), nil } // open the file and check magic f, err := os.Open(path) if err != nil { return nil, fmt.Errorf("cannot open snap: %v", err)