// checkSnap ensures that the snap can be installed. func checkSnap(st *state.State, snapFilePath string, si *snap.SideInfo, curInfo *snap.Info, flags Flags) error { // This assumes that the snap was already verified or --dangerous was used. s, _, err := openSnapFile(snapFilePath, si) if err != nil { return err } if s.NeedsDevMode() && !flags.DevModeAllowed() { return fmt.Errorf("snap %q requires devmode or confinement override", s.Name()) } // verify we have a valid architecture if !arch.IsSupportedArchitecture(s.Architectures) { return fmt.Errorf("snap %q supported architectures (%s) are incompatible with this system (%s)", s.Name(), strings.Join(s.Architectures, ", "), arch.UbuntuArchitecture()) } // check assumes err = checkAssumes(s) if err != nil { return err } st.Lock() defer st.Unlock() for _, check := range checkSnapCallbacks { err := check(st, s, curInfo, flags) if err != nil { return err } } return nil }
// checkSnap ensures that the snap can be installed. func checkSnap(st *state.State, snapFilePath string, curInfo *snap.Info, flags Flags) error { // This assumes that the snap was already verified or --dangerous was used. s, _, err := openSnapFile(snapFilePath, nil) if err != nil { return err } if s.NeedsDevMode() && !flags.DevModeAllowed() { return fmt.Errorf("snap %q requires devmode or confinement override", s.Name()) } // verify we have a valid architecture if !arch.IsSupportedArchitecture(s.Architectures) { return fmt.Errorf("snap %q supported architectures (%s) are incompatible with this system (%s)", s.Name(), strings.Join(s.Architectures, ", "), arch.UbuntuArchitecture()) } // check assumes err = checkAssumes(s) if err != nil { return err } if s.Type != snap.TypeGadget { return nil } // gadget specific checks if release.OnClassic { // for the time being return fmt.Errorf("cannot install a gadget snap on classic") } st.Lock() defer st.Unlock() currentGadget, err := GadgetInfo(st) // in firstboot we have no gadget yet - that is ok if err == state.ErrNoState && !firstboot.HasRun() { return nil } if err != nil { return fmt.Errorf("cannot find original gadget snap") } // TODO: actually compare snap ids, from current gadget and candidate if currentGadget.Name() != s.Name() { return fmt.Errorf("cannot replace gadget snap with a different one") } return nil }