-r is working

This commit is contained in:
elvis
2022-04-27 21:18:25 +02:00
parent 5151418090
commit 8841ca95a0
8 changed files with 65 additions and 43 deletions

View File

@ -601,13 +601,13 @@ int cmd_W(char *filelist, char *Dir, int print) {
opened = 1;
}
if (opened && writeFile(token, Dir) == -1) {
if (opened && (writeFile(token, Dir) == -1)) {
ok = 0;
}
if (opened && !ok) { // errore precedente -> elimino il file vuoto
removeFile(token);
} else if (opened && closeFile(token) == -1) { // chiudo il file
} else if (opened && (closeFile(token) == -1)) { // chiudo il file
ok = 0;
}
@ -671,9 +671,11 @@ int cmd_r(char *filelist, char *dir, int print) {
void *buf = NULL;
size_t size = -1;
// printInfo(0, stdout);
printInfo(0, stdout);
// read the content of the file
if (ok && readFile(token, &buf, &size) == -1) {
fprintf(stdout, "\nreadFile\n");
fflush(stdout);
ok = 0;
}
if (print) {
@ -689,6 +691,8 @@ int cmd_r(char *filelist, char *dir, int print) {
// close the file
if (opened && closeFile(token) == -1) {
fprintf(stdout, "\ncloseFile\n");
fflush(stdout);
ok = 0;
}
if (print) {
@ -696,9 +700,7 @@ int cmd_r(char *filelist, char *dir, int print) {
if (ok) {
printf("ok");
}
else {
} else {
printf("errore");
perror("-r");
}