-w, -W, -r all working

This commit is contained in:
elvis
2022-04-29 01:26:31 +02:00
parent 59814f06db
commit b0b9310acc
4 changed files with 40 additions and 14 deletions

View File

@ -96,16 +96,18 @@ int sendFile(fileT *f, long fd_c, taglia_t *taglia) {
perror("writen");
return -1;
}
if (writen(fd_c, f->data, f->valid) < 0) {
perror("writen");
return -1;
if(validLength != 0) { // if file has length 0 dont write
if (writen(fd_c, f->data, validLength) < 0) {
perror("writen");
return -1;
}
}
char tmp_log[LOGBUFSIZE];
int n = 0;
size_t m = sizeof(tmp_log);
n += snprintf(tmp_log+n, m-n, "File \"%s\", di dimensione %"PRId64" Bytes al client %ld .\n", f->filepath, validLength, fd_c);
n += snprintf(tmp_log+n, m-n, "Inviato file \"%s\", di dimensione %"PRId64" Bytes al client %ld .\n", f->filepath, validLength, fd_c);
if(taglia_write(taglia, tmp_log) < 0) {
perror("taglia_write");
return 1;
@ -132,7 +134,7 @@ void sendMessageFile(char *m, fileT *f, long fd_c, taglia_t *taglia, char *mlog)
}
int64_t *n = calloc(1, sizeof(*n));
if(n==NULL) {
if(!n) {
perror("calloc");
goto _sendMF_cleanup;
}
@ -275,7 +277,7 @@ void openFile(char *filepath, int flags, queueT *q, long fd_c, taglia_t *taglia)
taglia_update(taglia, q, 1); // removed only one file
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" ha causato una capacity miss. File espulso \"%s\"\n", fd_c, flags, filepath, removed->filepath);
sendMessageFile(MEFP, removed, fd_c, taglia, tmp_buf);
free(removed);
destroyFile(removed);
return;
}