Close original geometry temp files as soon as they are no longer needed

This commit is contained in:
Eric Fischer 2016-03-07 16:43:10 -08:00
parent bf585a5849
commit cf5082122a

View File

@ -1548,8 +1548,8 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
}
for (i = 0; i < nmerges; i++) {
if (!quiet) {
fprintf(stderr, "Reordering geometry: part %d of %d \r", i, nmerges);
if (!quiet && nmerges > 1) {
fprintf(stderr, "Reordering geometry: part %d of %d \r", i + 1, nmerges);
}
long long j;
@ -1566,7 +1566,7 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
ix->end = geompos;
}
}
if (!quiet) {
if (!quiet && nmerges > 1) {
fprintf(stderr, "\n");
}
@ -1579,7 +1579,7 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
exit(EXIT_FAILURE);
}
FILE *f = fopen(indexname, "w");
FILE *f = fopen(indexname, "wb");
if (f == NULL) {
perror(indexname);
exit(EXIT_FAILURE);
@ -1597,6 +1597,17 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
exit(EXIT_FAILURE);
}
for (i = 0; i < CPUS; i++) {
if (reader[i].geomst.st_size > 0) {
if (munmap(reader[i].geom_map, reader[i].geomst.st_size) != 0) {
perror("unmap unsorted geometry");
}
}
if (close(reader[i].geomfd) != 0) {
perror("close unsorted geometry");
}
}
geompos = 0;
/* initial tile is 0/0/0 */
@ -1809,16 +1820,6 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
perror("unmap sorted index");
}
for (i = 0; i < CPUS; i++) {
if (reader[i].geomst.st_size > 0) {
if (munmap(reader[i].geom_map, reader[i].geomst.st_size) != 0) {
perror("unmap unsorted geometry");
}
}
if (close(reader[i].geomfd) != 0) {
perror("close unsorted geometry");
}
}
if (close(indexfd) != 0) {
perror("close sorted index");
}