Logic for -l, -u and -c
This commit is contained in:
139
src/client.c
139
src/client.c
@ -574,11 +574,11 @@ int cmd_W(char *filelist, char *Dir, int print) {
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
while ((token = strsep(&string, ",")) != NULL) {
|
||||
while ((token = strsep_gnu(&string, ",")) != NULL) {
|
||||
int ok = 1;
|
||||
int opened = 0;
|
||||
if (print == 1) {
|
||||
printf("%s\n", token);
|
||||
printf("%s [", token);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
@ -609,7 +609,7 @@ int cmd_W(char *filelist, char *Dir, int print) {
|
||||
perror("-w");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printf("]\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
@ -627,13 +627,146 @@ int cmd_R(char *numStr, char *dir, int print) {
|
||||
}
|
||||
|
||||
int cmd_l(char *filelist, int print) {
|
||||
if (!filelist) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// we copy filelist because we are nice
|
||||
char *tofree = malloc(strnlen(filelist, MAXARGLENGTH)+1);
|
||||
if(!tofree) {
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH));
|
||||
|
||||
char *token;
|
||||
char *string = tofree;
|
||||
|
||||
if (print) {
|
||||
printf("l - Acquisisco la mutua esclusione sui seguenti file:\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
while ((token = strsep_gnu(&string, ",")) != NULL) {
|
||||
if (print != 0) {
|
||||
printf("%s [Esito: ", token);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if (lockFile(token) == -1) {
|
||||
if (print != 0) {
|
||||
printf("errore");
|
||||
perror("-l");
|
||||
}
|
||||
} else if(print != 0) {
|
||||
printf("ok");
|
||||
}
|
||||
|
||||
if (print != 0) {
|
||||
printf("]\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
free(tofree);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_u(char *filelist, int print) {
|
||||
if (!filelist) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// we copy filelist because we are nice
|
||||
char *tofree = malloc(strnlen(filelist, MAXARGLENGTH)+1);
|
||||
if(!tofree) {
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH));
|
||||
|
||||
char *token;
|
||||
char *string = tofree;
|
||||
|
||||
if (print) {
|
||||
printf("u - Rilascio la mutua esclusione sui seguenti file:\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
while ((token = strsep_gnu(&string, ",")) != NULL) {
|
||||
if (print != 0) {
|
||||
printf("%s [Esito: ", token);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if (unlockFile(token) == -1) {
|
||||
if (print != 0) {
|
||||
printf("errore");
|
||||
perror("-u");
|
||||
}
|
||||
} else if(print != 0) {
|
||||
printf("ok");
|
||||
}
|
||||
|
||||
if (print != 0) {
|
||||
printf("]\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
free(tofree);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_c(char *filelist, int print) {
|
||||
if (!filelist) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// we copy filelist because we are nice
|
||||
char *tofree = malloc(strnlen(filelist, MAXARGLENGTH)+1);
|
||||
if(!tofree) {
|
||||
perror("malloc");
|
||||
return -1;
|
||||
}
|
||||
strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH));
|
||||
|
||||
char *token;
|
||||
char *string = tofree;
|
||||
|
||||
if (print) {
|
||||
printf("c - Cancello i seguenti file dal server:\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
while ((token = strsep_gnu(&string, ",")) != NULL) {
|
||||
if (print != 0) {
|
||||
printf("%s [Esito: ", token);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
if (lockFile(token) == -1) {
|
||||
if (print) {
|
||||
printf("errore");
|
||||
perror("-c");
|
||||
}
|
||||
} else {
|
||||
if (removeFile(token) == -1) {
|
||||
if (print) {
|
||||
printf("errore");
|
||||
perror("-c");
|
||||
}
|
||||
} else if (print) {
|
||||
printf("ok");
|
||||
}
|
||||
}
|
||||
|
||||
if (print != 0) {
|
||||
printf("]\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
free(tofree);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user