Remove extra slash from paths

This commit removes the extra slash '/' from the path from:
- the update_boot function
- the verifytime script

Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit is contained in:
Castulo Martinez
2020-03-30 13:39:04 -07:00
committed by Otavio Pontes
parent e9739d9eb3
commit da0ef3e05e
6 changed files with 45 additions and 9 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ static void update_boot(void)
if (strcmp("/", globals.path_prefix) == 0) {
run_script_if_exists("/usr/bin/clr-boot-manager", "update", NULL);
} else {
string_or_die(&scriptname, "%s/usr/bin/clr-boot-manager", globals.path_prefix);
scriptname = sys_path_join("%s/%s", globals.path_prefix, "/usr/bin/clr-boot-manager");
run_script_if_exists(scriptname, "update", "--path", globals.path_prefix, NULL);
free_and_clear_pointer(&scriptname);
}
+40 -4
View File
@@ -24,6 +24,7 @@
#include "lib/log.h"
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -31,6 +32,44 @@
#include <time.h>
#define DAY_SECONDS 86400
#define PATH_SEPARATOR '/'
/* this function is a copy from sys_path_join() from lib/sys.c */
static char *path_join(const char *fmt, ...)
{
char *path;
va_list ap;
int len;
int i, j;
/* merge arguments into one path */
va_start(ap, fmt);
if (vasprintf(&path, fmt, ap) < 0) {
abort();
}
va_end(ap);
len = strlen(path);
char *pretty_path = malloc(strlen(path) + 1);
if (!pretty_path) {
abort();
}
/* remove all duplicated PATH_SEPARATOR from the path */
for (i = j = 0; i < len; i++) {
if (path[i] == PATH_SEPARATOR && path[i + 1] == PATH_SEPARATOR) {
/* duplicated PATH_SEPARATOR, throw it away */
continue;
}
pretty_path[j] = path[i];
j++;
}
pretty_path[j] = '\0';
free(path);
return pretty_path;
}
static unsigned long int get_versionstamp(char *path_prefix)
{
@@ -39,10 +78,7 @@ static unsigned long int get_versionstamp(char *path_prefix)
char *filename;
unsigned long int version_num;
if (asprintf(&filename, "%s/usr/share/clear/versionstamp", path_prefix ? path_prefix : "") < 0) {
error("Failed to get the versionstamp\n");
return 0;
}
filename = path_join("%s/usr/share/clear/versionstamp", path_prefix ? path_prefix : "");
errno = 0;
fp = fopen(filename, "r");
+1 -1
View File
@@ -61,7 +61,7 @@ test_setup() {
{ "type" : "info", "msg" : " 0 of 2 missing files were not installed" },
{ "type" : "progress", "currentStep" : 9, "totalSteps" : 9, "stepCompletion" : -1, "stepDescription" : "run_postupdate_scripts" },
{ "type" : "info", "msg" : "Calling post-update helper scripts" },
{ "type" : "warning", "msg" : "helper script ($TEST_DIRNAME/testfs/target-dir//usr/bin/clr-boot-manager) not found, it will be skipped" },
{ "type" : "warning", "msg" : "helper script ($TEST_DIRNAME/testfs/target-dir/usr/bin/clr-boot-manager) not found, it will be skipped" },
{ "type" : "info", "msg" : " Installation successful" },
{ "type" : "progress", "currentStep" : 9, "totalSteps" : 9, "stepCompletion" : 100, "stepDescription" : "run_postupdate_scripts" },
{ "type" : "end", "section" : "os-install", "status" : 0 }
+1 -1
View File
@@ -36,7 +36,7 @@ test_setup() {
1 of 1 files were repaired
0 of 1 files were not repaired
Calling post-update helper scripts
Warning: helper script ($PATH_PREFIX//usr/bin/clr-boot-manager) not found, it will be skipped
Warning: helper script ($PATH_PREFIX/usr/bin/clr-boot-manager) not found, it will be skipped
Repair successful
EOM
)
+1 -1
View File
@@ -153,7 +153,7 @@ test_setup() {
{ "type" : "progress", "currentStep" : 9, "totalSteps" : 10, "stepCompletion" : 100, "stepDescription" : "remove_extra_files" },
{ "type" : "progress", "currentStep" : 10, "totalSteps" : 10, "stepCompletion" : -1, "stepDescription" : "run_postupdate_scripts" },
{ "type" : "info", "msg" : "Calling post-update helper scripts" },
{ "type" : "warning", "msg" : "helper script ($PATH_PREFIX//usr/bin/clr-boot-manager) not found, it will be skipped" },
{ "type" : "warning", "msg" : "helper script ($PATH_PREFIX/usr/bin/clr-boot-manager) not found, it will be skipped" },
{ "type" : "info", "msg" : " Repair successful" },
{ "type" : "progress", "currentStep" : 10, "totalSteps" : 10, "stepCompletion" : 100, "stepDescription" : "run_postupdate_scripts" },
{ "type" : "end", "section" : "repair", "status" : 0 }
+1 -1
View File
@@ -32,7 +32,7 @@ test_setup() {
Installing files...
Update was applied
Calling post-update helper scripts
Warning: helper script ($TEST_DIRNAME/testfs/target-dir//usr/bin/clr-boot-manager) not found, it will be skipped
Warning: helper script ($TEST_DIRNAME/testfs/target-dir/usr/bin/clr-boot-manager) not found, it will be skipped
Update successful - System updated from version 10 to version 100
EOM
)