diff --git a/CHANGELOG.md b/CHANGELOG.md index 990a0ba..f97dcfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.20.1 + +* Close mbtiles file properly when there are no valid features in the input + ## 1.20.0 * Add long options to tippecanoe-decode and tile-join. Add --quiet to tile-join. diff --git a/main.cpp b/main.cpp index fb5fbe7..8ed0695 100644 --- a/main.cpp +++ b/main.cpp @@ -1023,7 +1023,7 @@ void choose_first_zoom(long long *file_bbox, struct reader *reader, unsigned *iz } } -int read_input(std::vector &sources, char *fname, int &maxzoom, int minzoom, int basezoom, double basezoom_marker_width, sqlite3 *outdb, const char *outdir, std::set *exclude, std::set *include, int exclude_all, double droprate, int buffer, const char *tmpdir, double gamma, int read_parallel, int forcetable, const char *attribution, bool uses_gamma, long long *file_bbox, const char *description, bool guess_maxzoom, std::map const *attribute_types) { +int read_input(std::vector &sources, char *fname, int &maxzoom, int minzoom, int basezoom, double basezoom_marker_width, sqlite3 *outdb, const char *outdir, std::set *exclude, std::set *include, int exclude_all, double droprate, int buffer, const char *tmpdir, double gamma, int read_parallel, int forcetable, const char *attribution, bool uses_gamma, long long *file_bbox, const char *description, bool guess_maxzoom, std::map const *attribute_types, const char *pgm) { int ret = EXIT_SUCCESS; struct reader reader[CPUS]; @@ -1600,6 +1600,9 @@ int read_input(std::vector &sources, char *fname, int &maxzoom, int minz if (indexpos == 0) { fprintf(stderr, "Did not read any valid geometries\n"); + if (outdb != NULL) { + mbtiles_close(outdb, pgm); + } exit(EXIT_FAILURE); } @@ -1636,6 +1639,9 @@ int read_input(std::vector &sources, char *fname, int &maxzoom, int minz if (count == 0 && dist_count == 0) { fprintf(stderr, "Can't guess maxzoom (-zg) without at least two distinct feature locations\n"); + if (outdb != NULL) { + mbtiles_close(outdb, pgm); + } exit(EXIT_FAILURE); } @@ -2557,10 +2563,10 @@ int main(int argc, char **argv) { long long file_bbox[4] = {UINT_MAX, UINT_MAX, 0, 0}; - ret = read_input(sources, name ? name : out_mbtiles ? out_mbtiles : out_dir, maxzoom, minzoom, basezoom, basezoom_marker_width, outdb, out_dir, &exclude, &include, exclude_all, droprate, buffer, tmpdir, gamma, read_parallel, forcetable, attribution, gamma != 0, file_bbox, description, guess_maxzoom, &attribute_types); + ret = read_input(sources, name ? name : out_mbtiles ? out_mbtiles : out_dir, maxzoom, minzoom, basezoom, basezoom_marker_width, outdb, out_dir, &exclude, &include, exclude_all, droprate, buffer, tmpdir, gamma, read_parallel, forcetable, attribution, gamma != 0, file_bbox, description, guess_maxzoom, &attribute_types, argv[0]); if (outdb != NULL) { - mbtiles_close(outdb, argv); + mbtiles_close(outdb, argv[0]); } #ifdef MTRACE diff --git a/mbtiles.cpp b/mbtiles.cpp index ed9b6c9..ddaaf22 100644 --- a/mbtiles.cpp +++ b/mbtiles.cpp @@ -526,15 +526,15 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fnam } } -void mbtiles_close(sqlite3 *outdb, char **argv) { +void mbtiles_close(sqlite3 *outdb, const char *pgm) { char *err; if (sqlite3_exec(outdb, "ANALYZE;", NULL, NULL, &err) != SQLITE_OK) { - fprintf(stderr, "%s: ANALYZE failed: %s\n", argv[0], err); + fprintf(stderr, "%s: ANALYZE failed: %s\n", pgm, err); exit(EXIT_FAILURE); } if (sqlite3_close(outdb) != SQLITE_OK) { - fprintf(stderr, "%s: could not close database: %s\n", argv[0], sqlite3_errmsg(outdb)); + fprintf(stderr, "%s: could not close database: %s\n", pgm, sqlite3_errmsg(outdb)); exit(EXIT_FAILURE); } } diff --git a/mbtiles.hpp b/mbtiles.hpp index 2c7cd03..efc0a97 100644 --- a/mbtiles.hpp +++ b/mbtiles.hpp @@ -41,7 +41,7 @@ void mbtiles_write_tile(sqlite3 *outdb, int z, int tx, int ty, const char *data, void mbtiles_write_metadata(sqlite3 *outdb, const char *outdir, const char *fname, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, int forcetable, const char *attribution, std::map const &layermap, bool vector, const char *description); -void mbtiles_close(sqlite3 *outdb, char **argv); +void mbtiles_close(sqlite3 *outdb, const char *pgm); void aprintf(std::string *buf, const char *format, ...); diff --git a/tile-join.cpp b/tile-join.cpp index e43c64d..73ff74a 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -1185,7 +1185,7 @@ int main(int argc, char **argv) { mbtiles_write_metadata(outdb, out_dir, name.c_str(), st.minzoom, st.maxzoom, st.minlat, st.minlon, st.maxlat, st.maxlon, st.midlat, st.midlon, 0, attribution.size() != 0 ? attribution.c_str() : NULL, layermap, true, description.c_str()); if (outdb != NULL) { - mbtiles_close(outdb, argv); + mbtiles_close(outdb, argv[0]); } return 0; diff --git a/version.hpp b/version.hpp index d426ced..3936e9f 100644 --- a/version.hpp +++ b/version.hpp @@ -1,6 +1,6 @@ #ifndef VERSION_HPP #define VERSION_HPP -#define VERSION "tippecanoe v1.20.0\n" +#define VERSION "tippecanoe v1.20.1\n" #endif