MCPcopy
hub / github.com/containers/toolbox / migrate

Function migrate

src/cmd/root.go:220–332  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

218}
219
220func migrate(cmd *cobra.Command, args []string) error {
221 logrus.Debug("Migrating to newer Podman")
222
223 if utils.IsInsideContainer() {
224 logrus.Debug("Migration not needed: running inside a container")
225 return nil
226 }
227
228 if cmdName, completionCmdName := cmd.Name(), completionCmd.Name(); cmdName == completionCmdName {
229 logrus.Debugf("Migration not needed: command %s doesn't need it", cmdName)
230 return nil
231 }
232
233 configDir, err := os.UserConfigDir()
234 if err != nil {
235 logrus.Debugf("Migrating to newer Podman: failed to get the user config directory: %s", err)
236 return errors.New("failed to get the user config directory")
237 }
238
239 toolboxConfigDir := configDir + "/toolbox"
240 stampPath := toolboxConfigDir + "/podman-system-migrate"
241 logrus.Debugf("Toolbx config directory is %s", toolboxConfigDir)
242
243 podmanVersion, err := podman.GetVersion()
244 if err != nil {
245 logrus.Debugf("Migrating to newer Podman: failed to get the Podman version: %s", err)
246 return errors.New("failed to get the Podman version")
247 }
248
249 logrus.Debugf("Current Podman version is %s", podmanVersion)
250
251 err = os.MkdirAll(toolboxConfigDir, 0775)
252 if err != nil {
253 logrus.Debugf("Migrating to newer Podman: failed to create configuration directory %s: %s",
254 toolboxConfigDir,
255 err)
256 return errors.New("failed to create configuration directory")
257 }
258
259 toolboxRuntimeDirectory, err := utils.GetRuntimeDirectory(currentUser)
260 if err != nil {
261 return err
262 }
263
264 migrateLock := toolboxRuntimeDirectory + "/migrate.lock"
265
266 migrateLockFile, err := utils.Flock(migrateLock, syscall.LOCK_EX)
267 if err != nil {
268 logrus.Debugf("Migrating to newer Podman: %s", err)
269
270 var errFlock *utils.FlockError
271
272 if errors.As(err, &errFlock) {
273 if errors.Is(err, utils.ErrFlockAcquire) {
274 err = utils.ErrFlockAcquire
275 } else if errors.Is(err, utils.ErrFlockCreate) {
276 err = utils.ErrFlockCreate
277 } else {

Callers 1

preRunFunction · 0.85

Calls 2

IsMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…