treewide: when copying a backup file always specify dest name
[openwrt/openwrt.git] / target / linux / x86 / base-files / lib / upgrade / platform.sh
index 4fa71999be7be3972676a1019488972dccd57fa2..855752b5d704401fd5a73534e89ada0c79495aa8 100644 (file)
@@ -39,7 +39,7 @@ platform_copy_config() {
 
        if export_partdevice partdev 1; then
                mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt
-               cp -af "$CONF_TAR" /mnt/
+               cp -af "$CONF_TAR" "/mnt/$BACKUP_FILE"
                umount /mnt
        fi
 }
@@ -54,7 +54,7 @@ platform_do_upgrade() {
 
        sync
 
-       if [ "$SAVE_PARTITIONS" = "1" ]; then
+       if [ "$UPGRADE_OPT_SAVE_PARTITIONS" = "1" ]; then
                get_partitions "/dev/$diskdev" bootdisk
 
                #extract the boot sector from the image
@@ -70,6 +70,12 @@ platform_do_upgrade() {
 
        if [ -n "$diff" ]; then
                get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync
+
+               # Separate removal and addtion is necessary; otherwise, partition 1
+               # will be missing if it overlaps with the old partition 2
+               partx -d - "/dev/$diskdev"
+               partx -a - "/dev/$diskdev"
+
                return 0
        fi