#include "main.h"
#include "srvctrl.h"
+#include "atomic.h"
#include <stdio.h>
#include <stdlib.h>
+#include <inttypes.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
static int scan_complete;
+
+static uint64_t stat_num_files;
+static uint64_t stat_copied_files;
+static uint64_t stat_error_files;
+static uint64_t stat_total_size;
+static uint64_t stat_copied_size;
+
int main(int argc, char** argv) {
int ret = 1;
SrcFile *f = calloc(1, sizeof(SrcFile));
f->path = util_concat_path(elm->path, name);
f->isdir = S_ISDIR(s.st_mode);
+ f->size = s.st_size;
f->mode = s.st_mode;
f->depends_on = elm;
// TODO: error?
fprintf(stderr, "enqueue failed\n");
break;
+ } else {
+ mz_atomic_inc64(&stat_num_files);
+ int64_t sz = s.st_size;
+ mz_atomic_add64(&stat_total_size, sz);
}
// put dir on stack
return 1;
}
+ int64_t copied = 0;
ssize_t r;
while((r = read(fin, buffer, bufsize)) > 0) {
- if(write(fout, buffer, r) != r) {
+ ssize_t w = write(fout, buffer, r);
+ if(w > 0) {
+ mz_atomic_add64(&stat_copied_size, w);
+ copied += w;
+ }
+ if(w != r) {
ret = 1;
break;
}
close(fin);
close(fout);
- file_set_status(file, !ret ? 1 : -1);
+ if(!ret) {
+ file_set_status(file, 1);
+ mz_atomic_inc64(&stat_copied_files);
+ if(copied != file->size) {
+ // size changed after scan -> readjust total size
+ int64_t filesz_diff = copied - file->size;
+ mz_atomic_add64(&stat_total_size, filesz_diff);
+ }
+ } else {
+ file_set_status(file, -1);
+ mz_atomic_inc64(&stat_error_files);
+ if(copied != file->size) {
+ // count the full file size as copied, although we had an error
+ int64_t filesz_diff = file->size - copied;
+ mz_atomic_add64(&stat_copied_size, filesz_diff);
+ }
+ }
return ret;
}