diff --git a/mapproxy/src/mapproxy/generator.hpp b/mapproxy/src/mapproxy/generator.hpp index 8317212..3b4cc8f 100644 --- a/mapproxy/src/mapproxy/generator.hpp +++ b/mapproxy/src/mapproxy/generator.hpp @@ -246,6 +246,10 @@ class Generator : boost::noncopyable { template ProviderType* getProvider() const; + /** Purges resource from disk. Be careful! + */ + void purge(); + protected: Generator(const Params ¶ms, const Properties &props = Properties()); @@ -330,9 +334,10 @@ class Generator : boost::noncopyable { class Generators : public boost::noncopyable { public: struct Config : Generator::Config { - int resourceUpdatePeriod; + int resourceUpdatePeriod = 100; + bool purgeRemovedResources = false; - Config() : resourceUpdatePeriod(100) {} + Config() {} }; /** Creates generator set. diff --git a/mapproxy/src/mapproxy/generator/generator.cpp b/mapproxy/src/mapproxy/generator/generator.cpp index 22819ce..76ed5b4 100644 --- a/mapproxy/src/mapproxy/generator/generator.cpp +++ b/mapproxy/src/mapproxy/generator/generator.cpp @@ -313,3 +313,10 @@ void Generator::updateRevision(unsigned int revision) { resource_.revision = std::max(resource_.revision, revision); } + +void Generator::purge() +{ + boost::system::error_code ec; + fs::remove_all(root(), ec); +} + diff --git a/mapproxy/src/mapproxy/generator/generators.cpp b/mapproxy/src/mapproxy/generator/generators.cpp index 5c368a6..8544a9a 100644 --- a/mapproxy/src/mapproxy/generator/generators.cpp +++ b/mapproxy/src/mapproxy/generator/generators.cpp @@ -426,6 +426,9 @@ void Generators::Detail::update(const Resource::map &resources) for (const auto &generator : toRemove) { { std::unique_lock lock(lock_); + if (config_.purgeRemovedResources) { + generator->purge(); + } serving_.erase(generator); } } diff --git a/mapproxy/src/mapproxy/main.cpp b/mapproxy/src/mapproxy/main.cpp index afa7003..9cdd07e 100644 --- a/mapproxy/src/mapproxy/main.cpp +++ b/mapproxy/src/mapproxy/main.cpp @@ -230,6 +230,10 @@ void Daemon::configuration(po::options_description &cmdline "of resource types (available types: " , enumerationString(Resource::Generator::Type{}) , ").").c_str()) + ("resource-backend.purgeRemoved" + , po::value(&generatorsConfig_.purgeRemovedResources) + ->default_value(generatorsConfig_.purgeRemovedResources)->required() + , "Removed resources are purged from store if true. Use with care.") ("vts.builtinBrowserUrl" , po::value(&variables_["VTS_BUILTIN_BROWSER_URL"]) @@ -324,6 +328,8 @@ void Daemon::configure(const po::variables_map &vars) << "\n\tresource-backend.freeze = [" << utility::join(generatorsConfig_.freezeResourceTypes, ",") << "]\n" + << "\n\tresource-backend.purgeRemoved = " + << generatorsConfig_.purgeRemovedResources << '\n' << "\thttp.externalUrl = " << generatorsConfig_.externalUrl << '\n' << utility::LManip([&](std::ostream &os) { ResourceBackend::printConfig(os, "\t" + RBPrefixDotted