Preparation for removeOldIcons thread
This commit is contained in:
parent
324196c7f9
commit
573b15bc2f
2 changed files with 23 additions and 9 deletions
|
@ -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 <boost/filesystem.hpp>
|
||||
#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<std::string> 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
|
||||
|
||||
|
|
23
src/util.cpp
23
src/util.cpp
|
@ -48,16 +48,21 @@ void removeEverythingOlderThan(const std::vector<std::string> &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<std::string> 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<std::string> nextDirs;
|
||||
nextDirs.push_back(itr->path().string());
|
||||
removeEverythingOlderThan(nextDirs, t);
|
||||
if (is_empty(itr->path())) {
|
||||
remove_all(itr->path());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const filesystem_error& ex) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue