diff --git a/spectrum/src/main.cpp b/spectrum/src/main.cpp index b27d6db8..ef210343 100644 --- a/spectrum/src/main.cpp +++ b/spectrum/src/main.cpp @@ -7,6 +7,7 @@ #include "transport/userregistration.h" #include "transport/networkpluginserver.h" #include "transport/admininterface.h" +#include "transport/util.h" #include "Swiften/EventLoop/SimpleEventLoop.h" #include #ifndef WIN32 @@ -47,6 +48,13 @@ static void spectrum_sigterm_handler(int sig) { eventLoop_->postEvent(&stop_spectrum); } +static void removeOldIcons(std::string iconDir) { + std::vector dirs; + dirs.push_back(iconDir); + + boost::thread thread(boost::bind(Util::removeEverythingOlderThan, dirs, time(NULL) - 3600*24*14)); +} + #ifndef WIN32 static void daemonize(const char *cwd, const char *lock_file) { pid_t pid, sid; @@ -195,6 +203,7 @@ int main(int argc, char **argv) // daemonize daemonize(CONFIG_STRING(&config, "service.working_dir").c_str(), CONFIG_STRING(&config, "service.pidfile").c_str()); +// removeOldIcons(CONFIG_STRING(&config, "service.working_dir") + "/icons"); } #endif diff --git a/src/util.cpp b/src/util.cpp index 5d60c47b..322d06ad 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -48,16 +48,21 @@ void removeEverythingOlderThan(const std::vector &dirs, time_t t) { directory_iterator end_itr; for (directory_iterator itr(p); itr != end_itr; ++itr) { if (last_write_time(itr->path()) < t) { - if (is_regular(itr->path())) { - remove(itr->path()); - } - else if (is_directory(itr->path())) { - std::vector nextDirs; - nextDirs.push_back(itr->path().string()); - removeEverythingOlderThan(nextDirs, t); - if (is_empty(itr->path())) { - remove_all(itr->path()); + try { + if (is_regular(itr->path())) { + remove(itr->path()); } + else if (is_directory(itr->path())) { + std::vector nextDirs; + nextDirs.push_back(itr->path().string()); + removeEverythingOlderThan(nextDirs, t); + if (is_empty(itr->path())) { + remove_all(itr->path()); + } + } + } + catch (const filesystem_error& ex) { + } } }