Ejemplo n.º 1
0
func removeCurrentSymlink(info snap.PlaceInfo, inter interacter) error {
	var err1, err2 error

	// the snap "current" symlink
	currentActiveSymlink := filepath.Join(info.MountDir(), "..", "current")
	err1 = os.Remove(currentActiveSymlink)
	if err1 != nil && !os.IsNotExist(err1) {
		logger.Noticef("Failed to remove %q: %v", currentActiveSymlink, err1)
	} else {
		err1 = nil
	}

	// the data "current" symlink
	currentDataSymlink := filepath.Join(filepath.Dir(info.DataDir()), "current")
	err2 = os.Remove(currentDataSymlink)
	if err2 != nil && !os.IsNotExist(err2) {
		logger.Noticef("Failed to remove %q: %v", currentDataSymlink, err2)
	} else {
		err2 = nil
	}

	if err1 != nil && err2 != nil {
		return fmt.Errorf("cannot remove snap current symlink: %v and %v", err1, err2)
	} else if err1 != nil {
		return fmt.Errorf("cannot remove snap current symlink: %v", err1)
	} else if err2 != nil {
		return fmt.Errorf("cannot remove snap current symlink: %v", err2)
	}

	return nil
}
Ejemplo n.º 2
0
func (f *fakeSnappyBackend) UndoSetupSnap(s snap.PlaceInfo) error {
	f.ops = append(f.ops, fakeOp{
		op:   "undo-setup-snap",
		name: s.MountDir(),
	})
	return nil
}
Ejemplo n.º 3
0
func (f *fakeSnappyBackend) RemoveSnapFiles(s snap.PlaceInfo, meter progress.Meter) error {
	meter.Notify("remove-snap-files")
	f.ops = append(f.ops, fakeOp{
		op:   "remove-snap-files",
		name: s.MountDir(),
	})
	return nil
}
Ejemplo n.º 4
0
// removeKernelAssets removes the unpacked kernel/initrd for the given
// kernel snap
func removeKernelAssets(s snap.PlaceInfo, inter interacter) error {
	bootloader, err := findBootloader()
	if err != nil {
		return fmt.Errorf("no not remove kernel assets: %s", err)
	}

	// remove the kernel blob
	blobName := filepath.Base(s.MountFile())
	dstDir := filepath.Join(bootloader.Dir(), blobName)
	if err := os.RemoveAll(dstDir); err != nil {
		return err
	}

	return nil
}
Ejemplo n.º 5
0
// RemoveSnapFiles removes the snap files from the disk
func RemoveSnapFiles(s snap.PlaceInfo, meter progress.Meter) error {
	mountDir := s.MountDir()

	// XXX: nicer way to do this
	typ := snap.TypeApp
	content, err := ioutil.ReadFile(filepath.Join(mountDir, "meta", "/snap.yaml"))
	if err == nil {
		info, err := snap.InfoFromSnapYaml(content)
		if err == nil {
			typ = info.Type
		}
	}

	snapPath := s.MountFile()
	// this also ensures that the mount unit stops
	if err := removeSquashfsMount(mountDir, meter); err != nil {
		return err
	}

	if err := os.RemoveAll(mountDir); err != nil {
		return err
	}

	// best effort(?)
	os.Remove(filepath.Dir(mountDir))

	// remove the snap
	if err := os.RemoveAll(snapPath); err != nil {
		return err
	}

	// remove the kernel assets (if any)
	if typ == snap.TypeKernel {
		if err := removeKernelAssets(s, meter); err != nil {
			logger.Noticef("removing kernel assets failed with %s", err)
		}
	}

	return nil
}
Ejemplo n.º 6
0
func UndoSetupSnap(s snap.PlaceInfo, meter progress.Meter) {
	// SetupSnap did it not made far enough
	if !osutil.FileExists(s.MountDir()) {
		return
	}

	if err := RemoveSnapFiles(s, meter); err != nil {
		logger.Noticef("cannot remove snap files: %s", err)
	}

	mountDir := s.MountDir()
	snapPath := s.MountFile()

	// remove install dir and the snap blob itself
	for _, path := range []string{
		mountDir,
		snapPath,
	} {
		if err := os.RemoveAll(path); err != nil {
			logger.Noticef("cannot remove snap package at %v: %s", mountDir, err)
		}
	}

	// FIXME: do we need to undo installGadgetHardwareUdevRules via
	//        cleanupGadgetHardwareUdevRules ? it will go away
	//        and can only be used during install right now
}