Don't preflight zoom levels for potential as-needed dropping (#40)

* Working on eliminating preflighting

* Adjust for the map/images schema change

* Avoid generating duplicate tiles with the detail reduction strategy

* Do error checking if tiles in a directory can't be written

* Update changelog and version

* Revert unintentional code reordering

* Neglected to add the exit on error here
This commit is contained in:
Erica Fischer
2022-11-29 12:42:30 -08:00
committed by GitHub
parent 3095adb467
commit 5c647cdb83
7 changed files with 176 additions and 56 deletions
+69 -3
View File
@@ -24,13 +24,19 @@ std::string dir_read_tile(std::string base, struct zxy tile) {
}
void dir_write_tile(const char *outdir, int z, int tx, int ty, std::string const &pbf) {
// Don't check mkdir error returns, since most of these calls to
// mkdir will be creating directories that already exist.
mkdir(outdir, S_IRWXU | S_IRWXG | S_IRWXO);
std::string curdir(outdir);
std::string slash("/");
std::string newdir = curdir + slash + std::to_string(z);
mkdir(newdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
newdir = newdir + "/" + std::to_string(tx);
mkdir(newdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
newdir = newdir + "/" + std::to_string(ty) + ".pbf";
struct stat st;
@@ -39,9 +45,21 @@ void dir_write_tile(const char *outdir, int z, int tx, int ty, std::string const
exit(EXIT_EXISTS);
}
std::ofstream pbfFile(newdir, std::ios::out | std::ios::binary);
pbfFile.write(pbf.data(), pbf.size());
pbfFile.close();
FILE *fp = fopen(newdir.c_str(), "wb");
if (fp == NULL) {
fprintf(stderr, "%s: %s\n", newdir.c_str(), strerror(errno));
exit(EXIT_WRITE);
}
if (fwrite(pbf.c_str(), sizeof(char), pbf.size(), fp) != pbf.size()) {
fprintf(stderr, "%s: %s\n", newdir.c_str(), strerror(errno));
exit(EXIT_WRITE);
}
if (fclose(fp) != 0) {
fprintf(stderr, "%s: %s\n", newdir.c_str(), strerror(errno));
exit(EXIT_CLOSE);
}
}
static bool numeric(const char *s) {
@@ -160,6 +178,54 @@ std::vector<zxy> enumerate_dirtiles(const char *fname, int minzoom, int maxzoom)
return tiles;
}
void dir_erase_zoom(const char *fname, int zoom) {
DIR *d1 = opendir(fname);
if (d1 != NULL) {
struct dirent *dp;
while ((dp = readdir(d1)) != NULL) {
if (numeric(dp->d_name) && atoi(dp->d_name) == zoom) {
std::string z = std::string(fname) + "/" + dp->d_name;
DIR *d2 = opendir(z.c_str());
if (d2 == NULL) {
perror(z.c_str());
exit(EXIT_OPEN);
}
struct dirent *dp2;
while ((dp2 = readdir(d2)) != NULL) {
if (numeric(dp2->d_name)) {
std::string x = z + "/" + dp2->d_name;
DIR *d3 = opendir(x.c_str());
if (d3 == NULL) {
perror(x.c_str());
exit(EXIT_OPEN);
}
struct dirent *dp3;
while ((dp3 = readdir(d3)) != NULL) {
if (pbfname(dp3->d_name)) {
std::string y = x + "/" + dp3->d_name;
if (unlink(y.c_str()) != 0) {
perror(y.c_str());
exit(EXIT_UNLINK);
}
}
}
closedir(d3);
}
}
closedir(d2);
}
}
closedir(d1);
}
}
sqlite3 *dirmeta2tmp(const char *fname) {
sqlite3 *db;
char *err = NULL;