Skip to content

Commit

Permalink
Add uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
konect-V committed Jun 17, 2024
1 parent bae92d8 commit ff951a6
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sources/core/apps/store/source/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../apps/apps.h"
#include "../update/update.h"
#include "../install/install.h"
#include "../uninstall/uninstall.h"

void print_help(){
printf("For help: ./store --help\n");
Expand Down Expand Up @@ -115,6 +116,9 @@ int main(int argc, char *argv[]){
}else if(!strcmp(argv[1], "--update") && argc == 3){
char* name = argv[2];
update_app(curl, name);
}else if(!strcmp(argv[1], "--uninstall") && argc == 3){
char* name = argv[2];
uninstall_app(name);
}else{
print_help();
}
Expand Down
45 changes: 45 additions & 0 deletions sources/core/apps/store/source/uninstall/uninstall.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <ftw.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/stat.h>

#include "uninstall.h"

static bool is_dir_exist(char* path){
struct stat sb;
return (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode));
}

static int delete(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf){
return remove(fpath);
}

int rmrf(char* path){
return nftw(path, delete, 64, FTW_DEPTH | FTW_PHYS);
}

int uninstall_app(char* name){
printf("Uninstalling %s...\n", name);
char* path_store = getenv("PATHSTORE");
if(is_dir_exist(path_store)){
char* path_store_app = malloc(strlen(path_store) + sizeof((char)'/') + strlen(name) + sizeof((char)'/') + 1);
strcpy(path_store_app, path_store);
strcat(path_store_app, "/");
strcat(path_store_app, name);
strcat(path_store_app, "/");

if(is_dir_exist(path_store_app)){
printf("Done uninstall %s\n", name);
rmrf(path_store_app);
rmdir(path_store_app);
return 0;
}
}

printf("Can't uninstall %s\n", name);

return -1;
}
6 changes: 6 additions & 0 deletions sources/core/apps/store/source/uninstall/uninstall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef UNINSTALL_H
#define UNINSTALL_H

int uninstall_app(char* name);

#endif // UNINSTALL_H
5 changes: 5 additions & 0 deletions sources/core/apps/store/source/update/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "update.h"
#include "../install/install.h"
#include "../uninstall/uninstall.h"

static bool is_dir_exist(char* path){
struct stat sb;
Expand Down Expand Up @@ -179,6 +180,10 @@ int update_app(CURL* curl, char* name){
}else if(result == 1 && url != NULL){
printf("%s : is not up-to-date\n", name);
printf("Updating...\n");
printf("Removing old files...\n");
uninstall_app(name);

printf("Installing new files...\n");
int r = install_app(curl, url, name, true);
if(!r){
printf("Update finish with success\n");
Expand Down

0 comments on commit ff951a6

Please sign in to comment.