Skip to content

Commit

Permalink
Merge pull request #38 from AleksArt000/main
Browse files Browse the repository at this point in the history
changes
  • Loading branch information
ilovethensa authored Dec 5, 2023
2 parents 9e5f3aa + 38f7aad commit 8488974
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 43 deletions.
2 changes: 0 additions & 2 deletions include/libspm.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ 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
Expand Down
42 changes: 1 addition & 41 deletions src/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void move_binaries(char** locations, long loc_size) {
}

// Move the files from the build directory to the destination location
switch (better_mvsp(build_loc, dest_loc))
switch (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);
Expand All @@ -64,44 +64,4 @@ void move_binaries(char** locations, long loc_size) {
}
}
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);

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

0 comments on commit 8488974

Please sign in to comment.