working -w
This commit is contained in:
@ -541,6 +541,7 @@ int writeFile(const char* pathname, const char* dirname) {
|
|||||||
size_t lung = 0;
|
size_t lung = 0;
|
||||||
size_t incr = 0;
|
size_t incr = 0;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
if ((fdi = open(pathname, O_RDONLY)) == -1) {
|
if ((fdi = open(pathname, O_RDONLY)) == -1) {
|
||||||
perror("open");
|
perror("open");
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
./client -t 200 -f socket -w test -D Wdir -W test/filepesante -r test/filepesante -d Rdir -R n=3 -l test/filepesante -u test/filepesante -c test/filepesante -p
|
./client -t 200 -f socket -w testFiles -D Wdir -W testFiles/6/f1 -r testFiles/6/f1 -d Rdir -R n=3 -l testFiles/6/f1 -u testFiles/6/f1 -c testFiles/6/f1 -p
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
40
src/client.c
40
src/client.c
@ -533,6 +533,9 @@ int cmd_w(char *dirname, char *Dir, int print) {
|
|||||||
|
|
||||||
fhandle = fts_open(&firstArg, FTS_COMFOLLOW, &compare);
|
fhandle = fts_open(&firstArg, FTS_COMFOLLOW, &compare);
|
||||||
|
|
||||||
|
char **listFiles = calloc(0, sizeof(char *));
|
||||||
|
int numFiles = 0;
|
||||||
|
|
||||||
if(fhandle != NULL) {
|
if(fhandle != NULL) {
|
||||||
// we check for num == 0 so that -1 yields all files in folder
|
// we check for num == 0 so that -1 yields all files in folder
|
||||||
while (num!=0 && (parent = fts_read(fhandle)) != NULL) {
|
while (num!=0 && (parent = fts_read(fhandle)) != NULL) {
|
||||||
@ -540,17 +543,24 @@ int cmd_w(char *dirname, char *Dir, int print) {
|
|||||||
|
|
||||||
while (num!=0 && (child != NULL)) { // for all children in folder
|
while (num!=0 && (child != NULL)) { // for all children in folder
|
||||||
if(child->fts_info == FTS_F) { // if child is a file
|
if(child->fts_info == FTS_F) { // if child is a file
|
||||||
char *tmp = malloc(child->fts_namelen + child->fts_pathlen + 2);
|
++numFiles;
|
||||||
snprintf(tmp, child->fts_namelen + child->fts_pathlen + 2, "%s/%s", child->fts_path, child->fts_name);
|
listFiles = realloc(listFiles, numFiles * sizeof(char *));
|
||||||
|
listFiles[numFiles-1] = calloc(child->fts_namelen + child->fts_pathlen + 2, sizeof(char));
|
||||||
if(print) {
|
snprintf(listFiles[numFiles-1], child->fts_namelen + child->fts_pathlen + 2, "%s/%s", child->fts_path, child->fts_name);
|
||||||
printf("%s [", tmp);
|
--num;
|
||||||
|
}
|
||||||
|
child = child->fts_link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fts_close(fhandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we send the file with the other function but set print to
|
for(int i=0; i<numFiles; ++i) {
|
||||||
// 0 since we do the printing before
|
if(print) {
|
||||||
int r = cmd_W(tmp, Dir, 0);
|
printf("%s [", listFiles[i]);
|
||||||
|
}
|
||||||
|
// we send the file with the other function but set print to 0
|
||||||
|
int r = cmd_W(listFiles[i], Dir, 0);
|
||||||
if(print && !r) {
|
if(print && !r) {
|
||||||
printf("Esito: ok");
|
printf("Esito: ok");
|
||||||
} else if(print && r) {
|
} else if(print && r) {
|
||||||
@ -561,14 +571,10 @@ int cmd_w(char *dirname, char *Dir, int print) {
|
|||||||
printf("]\n");
|
printf("]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
free(tmp);
|
free(listFiles[i]);
|
||||||
--num;
|
|
||||||
}
|
|
||||||
child = child->fts_link;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fts_close(fhandle);
|
|
||||||
}
|
}
|
||||||
|
free(listFiles);
|
||||||
|
|
||||||
free(tofree);
|
free(tofree);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -786,7 +792,7 @@ int cmd_l(char *filelist, int print) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we copy filelist because we are nice
|
// we copy filelist because we are nice
|
||||||
char *tofree = malloc(strnlen(filelist, MAXARGLENGTH)+1);
|
char *tofree = calloc(strnlen(filelist, MAXARGLENGTH)+1, sizeof(char));
|
||||||
if(!tofree) {
|
if(!tofree) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user