Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed a bug where some directories where not created successfuly #36

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/libspm.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
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
Expand Down Expand Up @@ -203,7 +204,7 @@


// update the system
int update();

Check warning on line 207 in include/libspm.h

View workflow job for this annotation

GitHub Actions / c-linter

/include/libspm.h:207:5 [readability-redundant-declaration]

redundant 'update' declaration

// Function to clean working directories
/*
Expand Down
5 changes: 3 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
const char* default_value;
} ConfigEntry;

ConfigEntry configEntries[] = {

Check warning on line 19 in src/config.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/config.c:19:13 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'configEntries' is non-const and globally accessible, consider making it const
{ "ROOT", "/" },
{ "SOVIET_DEFAULT_FORMAT", "ecmp" },
{ "MAIN_DIR", "/var/cccp" },
Expand All @@ -25,6 +25,7 @@
{ "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
};
Expand Down Expand Up @@ -71,14 +72,14 @@
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);
Expand Down
55 changes: 53 additions & 2 deletions src/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
// Iterate through locations and move the binaries to their correct locations
for (int i = 0; i < loc_size; i++) {
char dest_loc[PATH_MAX];
sprintf(dest_loc, "%s/%s", getenv("ROOT"), locations[i]);

Check warning on line 30 in src/move.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/move.c:30:9 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'sprintf' is insecure as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11
char build_loc[PATH_MAX];
sprintf(build_loc, "%s/%s", getenv("SOVIET_BUILD_DIR"), locations[i]);

Check warning on line 32 in src/move.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/move.c:32:9 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'sprintf' is insecure as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11

// Check if the destination location is empty
if (!(access(dest_loc, F_OK) == 0)) {
Expand All @@ -38,9 +38,20 @@
}

// Move the files from the build directory to the destination location
mvsp(build_loc, dest_loc);
switch (better_mvsp(build_loc, dest_loc))

Check warning on line 41 in src/move.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/move.c:41:21 [clang-diagnostic-implicit-function-declaration]

implicit declaration of function 'better_mvsp' is invalid in C99
{
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]);

Expand All @@ -52,5 +63,45 @@
}
}
}
return;

Check warning on line 66 in src/move.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/move.c:66:5 [readability-redundant-control-flow]

redundant return statement at the end of a function with a void return type
}

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);

Check warning on line 72 in src/move.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/move.c:72:5 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]

Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11

switch (isdir(parent_path))

Check warning on line 74 in src/move.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/move.c:74:13 [clang-diagnostic-implicit-function-declaration]

implicit declaration of function 'isdir' is invalid in C99
{
case 1:
if (mkdir_parent(parent_path, 0777) != 0) return -1;

Check warning on line 77 in src/move.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/move.c:77:17 [clang-diagnostic-implicit-function-declaration]

implicit declaration of function 'mkdir_parent' is invalid in C99

Check warning on line 77 in src/move.c

View workflow job for this annotation

GitHub Actions / c-linter

/src/move.c:77:54 [readability-braces-around-statements]

statement should be inside braces
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;
}
Loading