1
// -*- Mode: Go; indent-tabs-mode: t -*-
4
* Copyright (C) 2014-2015 Canonical Ltd
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 3 as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
30
"launchpad.net/snappy/helpers"
33
// Snap is the squashfs based snap
38
// Name returns the Name of the backing file
39
func (s *Snap) Name() string {
40
return filepath.Base(s.path)
43
// New returns a new Snapfs snap
44
func New(path string) *Snap {
45
return &Snap{path: path}
48
// Close is not doing anything for snapfs - COMPAT
49
func (s *Snap) Close() error {
53
// ControlMember extracts from meta/ - COMPAT
54
func (s *Snap) ControlMember(controlMember string) ([]byte, error) {
55
return s.ReadFile(filepath.Join("DEBIAN", controlMember))
58
// MetaMember extracts from meta/ - COMPAT
59
func (s *Snap) MetaMember(metaMember string) ([]byte, error) {
60
return s.ReadFile(filepath.Join("meta", metaMember))
63
// ExtractHashes does notthing for snapfs snaps - COMAPT
64
func (s *Snap) ExtractHashes(dir string) error {
68
// UnpackWithDropPrivs unpacks the meta and puts stuff in place - COMAPT
69
func (s *Snap) UnpackWithDropPrivs(instDir, rootdir string) error {
70
// FIXME: actually drop privs
71
return s.Unpack("*", instDir)
74
// UnpackMeta unpacks just the meta/* directory of the given snap
75
func (s *Snap) UnpackMeta(dst string) error {
76
if err := s.Unpack("meta/*", dst); err != nil {
80
return s.Unpack(".click/*", dst)
83
var runCommand = func(args ...string) error {
84
cmd := exec.Command(args[0], args[1:]...)
85
if output, err := cmd.CombinedOutput(); err != nil {
86
return fmt.Errorf("cmd: %q failed: %v (%q)", strings.Join(args, " "), err, output)
92
// Unpack unpacks the src (which may be a glob into the given target dir
93
func (s *Snap) Unpack(src, dstDir string) error {
94
return runCommand("unsquashfs", "-f", "-i", "-d", dstDir, s.path, src)
97
// ReadFile returns the content of a single file inside a snapfs snap
98
func (s *Snap) ReadFile(path string) (content []byte, err error) {
99
tmpdir, err := ioutil.TempDir("", "read-file")
103
defer os.RemoveAll(tmpdir)
105
unpackDir := filepath.Join(tmpdir, "unpack")
106
if err := runCommand("unsquashfs", "-i", "-d", unpackDir, s.path, path); err != nil {
110
return ioutil.ReadFile(filepath.Join(unpackDir, path))
113
// CopyBlob copies the snap to a new place
114
func (s *Snap) CopyBlob(targetFile string) error {
115
// FIXME: helpers.CopyFile() has no preserve attribute flag yet
116
return runCommand("cp", "-a", s.path, targetFile)
119
// Verify verifies the snap
120
func (s *Snap) Verify(unauthOk bool) error {
121
// FIXME: there is no verification yet for snapfs packages, this
122
// will be done via assertions later for now we rely on
123
// the https security
127
// Build builds the snap
128
func (s *Snap) Build(buildDir string) error {
129
fullSnapPath, err := filepath.Abs(s.path)
134
return helpers.ChDir(buildDir, func() error {