Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[config] Ignore legacy config after settings migration. Fixes JB#48375
Once usb-moded has migrated settings from legacy config file at
/etc/usb-moded/usb-moded.ini, the file is removed. However, if the
file originates from some package, it can get reinstated during
upgrade and override usb-mode selection made by the user.

Instead of relying solely on file removal, ignore legacy config file
altogether if dynamic settings file has already been created.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Sep 25, 2020
1 parent 798b8c9 commit b1be9d4
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/usb_moded-config.c
Expand Up @@ -903,8 +903,33 @@ static bool config_load_legacy_config(GKeyFile *ini)
LOG_REGISTER_CONTEXT;

bool ack = false;
if( access(USB_MODED_STATIC_CONFIG_FILE, F_OK) != -1 )
ack = config_merge_from_file(ini, USB_MODED_STATIC_CONFIG_FILE);

/* If the legacy config file does not exist, there is
* no need to do anything about it.
*/
if( access(USB_MODED_STATIC_CONFIG_FILE, F_OK) == -1 )
goto EXIT;

/* If we have also dynamic settings file, it means that
* the legacy config file has re-appeared after migration.
*
* This could happen e.g. during sw upgrades as long as
* there are packages that contain the legacy config file.
*
* The content must be ignored to avoid overriding user
* settings, but emit a warning to help diagnosing when
* and why it might be happening (the legacy file will be
* removed later on - when there are settings changes to
* commit).
*/
if( access(USB_MODED_DYNAMIC_CONFIG_FILE, F_OK) == 0 ) {
log_warning("%s: has reappeared after settings migration",
USB_MODED_STATIC_CONFIG_FILE);
goto EXIT;
}

if( !config_merge_from_file(ini, USB_MODED_STATIC_CONFIG_FILE) )
goto EXIT;

/* A mode=ask setting in legacy config can be either
* something user has selected, or merely configured
Expand All @@ -922,6 +947,9 @@ static bool config_load_legacy_config(GKeyFile *ini)
g_free(val);
}

ack = true;

EXIT:
return ack;
}

Expand Down

0 comments on commit b1be9d4

Please sign in to comment.