Skip to content
Permalink
Browse files

Add a port command check before restoring

  • Loading branch information
umeshksingla authored and neverpanic committed Sep 2, 2017
1 parent 7ebf3a6 commit 1509f0141e9482651c1700dab4b71d4aa490d45e
Showing with 32 additions and 16 deletions.
  1. +2 −4 src/macports1.0/macports.tcl
  2. +2 −2 src/macports1.0/migrate.tcl
  3. +20 −0 src/macports1.0/restore.tcl
  4. +2 −1 src/macports1.0/snapshot.tcl
  5. +6 −9 src/port/port.tcl
@@ -4505,8 +4505,7 @@ proc macports::snapshot_main {opts} {
# Returns:
# 0 on successful execution.

snapshot::main $opts
return 0
return [snapshot::main $opts]
}

# restores a snapshot.
@@ -4519,8 +4518,7 @@ proc macports::restore_main {opts} {
# Returns:
# 0 on successful execution.

restore::main $opts
return 0
return [restore::main $opts]
}

proc macports::migrate_main {opts} {
@@ -55,7 +55,7 @@ namespace eval migrate {
ui_msg "Done: snapshot '$id':'$note' created at $datetime"

if {[info exists macports::ui_options(questions_yesno)]} {
set msg "Migration will first uninstall all the installed ports and then reinstall."
set msg "Migration will first uninstall all the installed ports, upgrade MacPorts and then reinstall them again."
set retvalue [$macports::ui_options(questions_yesno) $msg "MigrationPrompt" "" {y} 0 "Would you like to continue?"]
if {$retvalue == 1} {
# quit as user answered 'no'
@@ -67,7 +67,7 @@ namespace eval migrate {
ui_msg "Uninstalling all ports.."
uninstall_installed [registry::entry imaged]

ui_msg "Upgrading macports.."
ui_msg "Upgrading MacPorts.."
upgrade_port_command

ui_msg "Fetching ports to install.."
@@ -54,13 +54,33 @@ namespace eval restore {
}
}

if {![check_port_command]} {
return -code error "OS platform mismatch"
}

ui_msg ":: Deactivating all ports installed.."
deactivate_all

ui_msg ":: Restoring the selected snapshot.."
restore_state [$snapshot ports]
}

proc check_port_command {} {

global tcl_platform
set os_version $tcl_platform(osVersion)
set os_major [lindex [split $os_version .] 0]
set os_platform [string tolower $tcl_platform(os)]

# Check that the current pla tform is the one we were configured for, otherwise need to do migration
if {($os_platform ne $macports::autoconf::os_platform) || ($os_major != $macports::autoconf::os_major)} {
ui_error "Current platform \"$os_platform $os_major\" does not match expected platform \"$macports::autoconf::os_platform $macports::autoconf::os_major\""
ui_error "If you upgraded your OS or changed the hardware architecture, you need to run 'port migrate' instead."
return 0
}
return 1
}

proc fetch_snapshot {snapshot_id} {
return [registry::snapshot get_by_id $snapshot_id]
}
@@ -35,7 +35,7 @@ package require registry 1.0

namespace eval snapshot {
proc main {opts} {
# The main function. Handles all the calls to the correct functions.
# Function to create a snapshot of the current state of ports.
#
# Args:
# opts - The options passed in.
@@ -52,6 +52,7 @@ namespace eval snapshot {
} else {
set note "snapshot created for migration"
}
# TODO: catch
set snapshot [registry::snapshot create $note]
}
return $snapshot
@@ -2826,19 +2826,16 @@ proc action_reclaim { action portlist opts } {

}

proc action_snapshot { action portlist opts} {
macports::snapshot_main $opts
return 0
proc action_snapshot { action portlist opts } {
return [macports::snapshot_main $opts]
}

proc action_restore { action portlist opts} {
macports::restore_main $opts
return 0
proc action_restore { action portlist opts } {
return [macports::restore_main $opts]
}

proc action_migrate { action portlist opts} {
macports::migrate_main $opts
return 0
proc action_migrate { action portlist opts } {
return [macports::migrate_main $opts]
}

proc action_upgrade { action portlist opts } {

0 comments on commit 1509f01

Please sign in to comment.
You can’t perform that action at this time.