From a5393e71234f3d32736f0dc52af98f3194b32ede Mon Sep 17 00:00:00 2001 From: AleksArt Date: Sun, 3 Dec 2023 01:24:45 +0100 Subject: [PATCH 1/4] added default for MAKE_FLAGS --- src/config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.c b/src/config.c index 299fedf..5729cf5 100755 --- a/src/config.c +++ b/src/config.c @@ -25,6 +25,7 @@ ConfigEntry configEntries[] = { { "ALL_DB", "/var/cccp/data/all.db" }, { "CONFIG_FILE", DEFAULT_CONFIG_FILE }, { "SOVIET_REPOS", "/var/cccp/repos" }, + { "MAKE_FLAGS", "-j1" }, { "SOVIET_FORMATS", "ecmp" }, // Add more key-value pairs with default values as needed }; From e3a8f6d537fd8b34586588f5a026fbcd2565b620 Mon Sep 17 00:00:00 2001 From: AleksArt Date: Sun, 3 Dec 2023 01:47:41 +0100 Subject: [PATCH 2/4] added a test to see if moving was succesful --- src/move.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/move.c b/src/move.c index 022d62b..5c4e8cb 100755 --- a/src/move.c +++ b/src/move.c @@ -38,9 +38,15 @@ void move_binaries(char** locations, long loc_size) { } // Move the files from the build directory to the destination location - mvsp(build_loc, dest_loc); + if(mvsp(build_loc, dest_loc)!= 0) + { + msg(FATAL, "Moving %s/%s to %s, failed", getenv("SOVIET_BUILD_DIR"), locations[i], dest_loc); + } + else + { + msg(WARNING, "Moved %s/%s to %s", getenv("SOVIET_BUILD_DIR"), locations[i], dest_loc); + } - msg(WARNING, "Moved %s/%s to %s", getenv("SOVIET_BUILD_DIR"), locations[i], dest_loc); } else { msg(WARNING, "%s is already here, use --overwrite?", locations[i]); From aaa9ba506bbb1f41eb636162296710ac99142635 Mon Sep 17 00:00:00 2001 From: AleksArt Date: Sun, 3 Dec 2023 17:56:22 +0100 Subject: [PATCH 3/4] fixed a bug --- include/libspm.h | 3 ++- src/move.c | 57 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/include/libspm.h b/include/libspm.h index 4b8e0fc..c45e640 100755 --- a/include/libspm.h +++ b/include/libspm.h @@ -54,7 +54,8 @@ int count_installed(); int search(char* in); int update(); int upgrade(); - +int better_mvsp(char* old_path,char* new_path); +int mkdir_parent(const char *path, mode_t mode); //end test // package info diff --git a/src/move.c b/src/move.c index 5c4e8cb..6aeb6a1 100755 --- a/src/move.c +++ b/src/move.c @@ -38,15 +38,20 @@ void move_binaries(char** locations, long loc_size) { } // Move the files from the build directory to the destination location - if(mvsp(build_loc, dest_loc)!= 0) + switch (better_mvsp(build_loc, dest_loc)) { - msg(FATAL, "Moving %s/%s to %s, failed", getenv("SOVIET_BUILD_DIR"), locations[i], dest_loc); - } - else - { - msg(WARNING, "Moved %s/%s to %s", getenv("SOVIET_BUILD_DIR"), locations[i], dest_loc); + case -1: + msg(FATAL, "Moving %s/%s to %s failed, could not create dir", getenv("SOVIET_BUILD_DIR"), locations[i], dest_loc); + break; + case -2: + msg(FATAL, "Moving %s/%s to %s failed, destination not a dir", getenv("SOVIET_BUILD_DIR"), locations[i], dest_loc); + break; + case 0: + msg(WARNING, "Moved %s/%s to %s", getenv("SOVIET_BUILD_DIR"), locations[i], dest_loc); + break; } + } else { msg(WARNING, "%s is already here, use --overwrite?", locations[i]); @@ -60,3 +65,43 @@ void move_binaries(char** locations, long loc_size) { } return; } + +int better_mvsp(char* old_path,char* new_path) +{ + char* parent_path = calloc(strlen(new_path)+1,sizeof(char)); + strncpy(parent_path,new_path,strrchr(new_path, '/')-new_path); + + switch (isdir(parent_path)) + { + case 1: + if (mkdir_parent(parent_path, 0777) != 0) return -1; + break; + case 2: + return -2; + case 0: + break; + } + free(parent_path); + // move file + return rename(old_path,new_path); +} + +int mkdir_parent(const char *path, mode_t mode) { + char tmp[256]; + char *p = NULL; + size_t len; + + snprintf(tmp, sizeof(tmp),"%s", path); + len = strlen(tmp); + if(tmp[len - 1] == '/') + tmp[len - 1] = 0; + for(p = tmp + 1; *p; p++) + if(*p == '/') { + *p = 0; + mkdir(tmp, mode); + *p = '/'; + } + mkdir(tmp, mode); + + return 0; +} \ No newline at end of file From cc5eda56ceaeeda7a9ae521c5394286755bbc1a2 Mon Sep 17 00:00:00 2001 From: AleksArt Date: Sun, 3 Dec 2023 19:41:19 +0100 Subject: [PATCH 4/4] stuff --- src/config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index 5729cf5..7863c0c 100755 --- a/src/config.c +++ b/src/config.c @@ -72,14 +72,14 @@ int readConfig(const char* configFilePath) line[strlen(line) - 1] = 0; char* key = strtok(line, "="); - char* value = strtok(NULL, "="); + char* value = strchr(line, '\0') + 1; if (key == NULL || value == NULL) { msg(ERROR, "Invalid config file"); fclose(file); return 1; } - dbg(3, "Key: %s Value: %s", key, value); + dbg(2, "Key: %s Value: %s", key, value); // Set environment variables based on the key-value pairs in the config file setenv(key, value, 1);