-r is working
This commit is contained in:
@ -35,7 +35,7 @@ void serror(char *m, long fd_c, taglia_t *taglia, char *mlog) {
|
||||
errno = EINVAL;
|
||||
m = MESY;
|
||||
}
|
||||
if(writen(fd_c, m, strnlen(m, MAXLENMESS)+1) < 0) {
|
||||
if(writen(fd_c, m, strnlen(m, MAXLENMESS)) < 0) {
|
||||
perror("writen");
|
||||
goto _serror_cleanup;
|
||||
}
|
||||
@ -126,17 +126,25 @@ void sendMessageFile(char *m, fileT *f, long fd_c, taglia_t *taglia, char *mlog)
|
||||
m = MEFP;
|
||||
}
|
||||
|
||||
if(writen(fd_c, m, strnlen(m, MAXLENMESS)+1) < 0) {
|
||||
if(writen(fd_c, m, strnlen(m, MAXLENMESS)) < 0) {
|
||||
perror("writen");
|
||||
goto _sendMF_cleanup;
|
||||
}
|
||||
|
||||
int n = 1;
|
||||
if(writen(fd_c, &n, sizeof(n)) < 0) {
|
||||
int64_t *n = calloc(1, sizeof(*n));
|
||||
if(n==NULL) {
|
||||
perror("calloc");
|
||||
goto _sendMF_cleanup;
|
||||
}
|
||||
*n = 1;
|
||||
|
||||
if(writen(fd_c, n, sizeof(int64_t)) < 0) {
|
||||
perror("writen");
|
||||
goto _sendMF_cleanup;
|
||||
}
|
||||
|
||||
free(n);
|
||||
|
||||
if(sendFile(f, fd_c, taglia) < 0) {
|
||||
perror("sendFile");
|
||||
goto _sendMF_cleanup;
|
||||
@ -166,7 +174,7 @@ void sendMessageFileN(char *m, fileT **f, int n, long fd_c, taglia_t *taglia, ch
|
||||
m = MEFP;
|
||||
}
|
||||
|
||||
if(writen(fd_c, m, strnlen(m, MAXLENMESS)+1) < 0) {
|
||||
if(writen(fd_c, m, strnlen(m, MAXLENMESS)) < 0) {
|
||||
perror("writen");
|
||||
goto _sendMFN_cleanup;
|
||||
}
|
||||
@ -208,8 +216,8 @@ void openFile(char *filepath, int flags, queueT *q, long fd_c, taglia_t *taglia)
|
||||
}
|
||||
|
||||
int found = searchFile(q, filepath); // cerco il file nella queue
|
||||
int create = flags & 0x1; // also %2
|
||||
int lock = flags >> 1 & 0x1; // also >>1%2
|
||||
int create = (flags & C_CREATE)?1:0; // also %2
|
||||
int lock = (flags & C_LOCK)?1:0; // also >>1%2
|
||||
fileT *removed = NULL; // file che è stato rimosso
|
||||
|
||||
if(found && create) { // si vuole creare il file ma esiste già
|
||||
@ -321,8 +329,8 @@ void readFile(char *filepath, queueT *q, long fd_c, taglia_t *taglia) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(f->open != 0) { // file already open
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readFile sul file \"%s\" e' terminata con errore\n", fd_c, filepath);
|
||||
if(f->open == 0) { // file not already open
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readFile sul file \"%s\" e' terminata con errore, file non aperto\n", fd_c, filepath);
|
||||
errno = EPERM;
|
||||
serror(MENT, fd_c, taglia, tmp_buf);
|
||||
destroyFile(f); // f is a copy so we need to cleen up
|
||||
@ -395,9 +403,11 @@ void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *tagl
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// cerco il file
|
||||
fileT *f = NULL;
|
||||
f = find(q, filepath);
|
||||
|
||||
if(!f) { // file is not present
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con errore, file non trovato\n", fd_c, append, filepath, size);
|
||||
errno = ENOENT;
|
||||
|
||||
Reference in New Issue
Block a user