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/config.c b/src/config.c index 299fedf..7863c0c 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 }; @@ -71,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); diff --git a/src/move.c b/src/move.c index 022d62b..6aeb6a1 100755 --- a/src/move.c +++ b/src/move.c @@ -38,9 +38,20 @@ void move_binaries(char** locations, long loc_size) { } // Move the files from the build directory to the destination location - mvsp(build_loc, dest_loc); + switch (better_mvsp(build_loc, 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; + } - 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]); @@ -54,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