338 |
return true; |
return true; |
339 |
} |
} |
340 |
|
|
341 |
static int merge(Coverage * coverage, const char * path, size_t size) __attribute__((warn_unused_result)); |
static int merge(Coverage * coverage, FILE * f) __attribute__((warn_unused_result)); |
342 |
|
|
343 |
static int merge(Coverage * coverage, const char * path, size_t size) { |
static int merge(Coverage * coverage, FILE * f) { |
344 |
FILE * f = fopen(path, "r"); |
Stream * stream = Stream_new(0); |
345 |
if (f == NULL) { |
Stream_write_file_contents(stream, f); |
|
return -1; |
|
|
} |
|
|
uint8_t * buffer = xmalloc(size); |
|
|
if (fread(buffer, 1, size, f) != size) { |
|
|
fclose(f); |
|
|
free(buffer); |
|
|
return -1; |
|
|
} |
|
|
fclose(f); |
|
346 |
|
|
347 |
pthread_mutex_lock(&javascript_mutex); |
pthread_mutex_lock(&javascript_mutex); |
348 |
int result = jscoverage_parse_json(coverage, buffer, size); |
int result = jscoverage_parse_json(coverage, stream->data, stream->length); |
349 |
pthread_mutex_unlock(&javascript_mutex); |
pthread_mutex_unlock(&javascript_mutex); |
350 |
|
|
351 |
free(buffer); |
Stream_delete(stream); |
352 |
return result; |
return result; |
353 |
} |
} |
354 |
|
|
515 |
|
|
516 |
mkdir_if_necessary(report_directory); |
mkdir_if_necessary(report_directory); |
517 |
char * path = make_path(report_directory, "jscoverage.json"); |
char * path = make_path(report_directory, "jscoverage.json"); |
518 |
struct stat buf; |
FILE * f = fopen(path, "r"); |
519 |
if (stat(path, &buf) == 0) { |
if (f != NULL) { |
520 |
/* it exists: merge */ |
/* it exists: merge */ |
521 |
result = merge(coverage, path, buf.st_size); |
result = merge(coverage, f); |
522 |
|
if (fclose(f) == EOF) { |
523 |
|
result = 1; |
524 |
|
} |
525 |
if (result != 0) { |
if (result != 0) { |
526 |
free(path); |
free(path); |
527 |
Coverage_delete(coverage); |
Coverage_delete(coverage); |
541 |
/* copy other files */ |
/* copy other files */ |
542 |
jscoverage_copy_resources(report_directory); |
jscoverage_copy_resources(report_directory); |
543 |
path = make_path(report_directory, "jscoverage.js"); |
path = make_path(report_directory, "jscoverage.js"); |
544 |
FILE * f = fopen(path, "ab"); |
f = fopen(path, "ab"); |
545 |
free(path); |
free(path); |
546 |
if (f == NULL) { |
if (f == NULL) { |
547 |
send_response(exchange, 500, "Could not write to file: jscoverage.js\n"); |
send_response(exchange, 500, "Could not write to file: jscoverage.js\n"); |