last bug fixes and test2 & test3

This commit is contained in:
elvis
2022-05-03 23:14:39 +02:00
parent 3fb7c1e886
commit 4b7f15c555
13 changed files with 141 additions and 40 deletions

View File

@ -339,7 +339,7 @@ void readFile(char *filepath, queueT *q, long fd_c, taglia_t *taglia) {
return;
}
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readFile sul file \"%s\" e' terminata con successo\n", fd_c, filepath);
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readFile sul file \"%s\" di dimensione = %ld e' terminata con successo\n", fd_c, filepath, f->valid);
sendMessageFile(MEOK, f, fd_c, taglia, tmp_buf);
destroyFile(f); // f is a copy so we need to cleen up
return;
@ -366,6 +366,7 @@ void readNFiles(int num, queueT *q, long fd_c, taglia_t *taglia){
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readNFile (n = %d) e' terminata con successo. File inviati:\n", fd_c, num);
// extract n files, we dont check if the client can actually modify
// the files since we add them back immediatly
size_t tot = 0;
for(int i=0;i<ntosend;++i) {
toSend[i] = dequeue(q);
if(!toSend[i]) {
@ -383,8 +384,10 @@ void readNFiles(int num, queueT *q, long fd_c, taglia_t *taglia){
serror(MESE, fd_c, taglia, tmp_buf);
return;
}
n += snprintf(tmp_buf+n, m-n, "\t%d) \"%s\"\n", i, toSend[i]->filepath);
tot += toSend[i]->valid;
n += snprintf(tmp_buf+n, m-n, "\t%d) \"%s\" dim = %ld\n", i, toSend[i]->filepath, toSend[i]->valid);
}
n += snprintf(tmp_buf+n, m-n, "readNFile dimensione totale = %ld\n", tot);
sendMessageFileN(MEOK, toSend, ntosend, fd_c, taglia, tmp_buf);
free(toSend);
@ -434,6 +437,13 @@ void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *tagl
}
destroyFile(f); // not needed anymore
if(trueSizeAdded > q->maxSize) { // removing all files would not be enought
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld ma il file e' piu' grande della dimensione massima\n", fd_c, append, filepath, size);
errno = EFBIG;
serror(MENT, fd_c, taglia, tmp_buf);
return;
}
if(trueSizeAdded + getSize(q) > q->maxSize) {
// writing would be more than capacity
fileT **removed = NULL; // array that may (worst case) hold all files to be sent to the client