Changeset - 573b15bc2f3b
[Not reviewed]
0 2 0
Jan Kaluza - 14 years ago 2011-09-13 14:57:28
hanzz.k@gmail.com
Preparation for removeOldIcons thread
2 files changed with 14 insertions and 0 deletions:
0 comments (0 inline, 0 general)
spectrum/src/main.cpp
Show inline comments
 
@@ -4,12 +4,13 @@
 
#include "transport/logger.h"
 
#include "transport/sqlite3backend.h"
 
#include "transport/mysqlbackend.h"
 
#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
 
#include "sys/signal.h"
 
#include <pwd.h>
 
#include <grp.h>
 
@@ -44,12 +45,19 @@ static void spectrum_sigint_handler(int sig) {
 
}
 
 
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;
 
	FILE* lock_file_f;
 
	char process_pid[20];
 
 
@@ -192,12 +200,13 @@ int main(int argc, char **argv)
 
			std::cerr << "Can't create service.pidfile directory " << boost::filesystem::path(CONFIG_STRING(&config, "service.pidfile")).parent_path().string() << ".\n";
 
			return 1;
 
		}
 
 
		// 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
 
 
	if (CONFIG_STRING(&config, "logging.config").empty()) {
 
		LoggerPtr root = log4cxx::Logger::getRootLogger();
 
#ifdef WIN32
src/util.cpp
Show inline comments
 
@@ -45,24 +45,29 @@ void removeEverythingOlderThan(const std::vector<std::string> &dirs, time_t t) {
 
				continue;
 
			}
 

	
 
			directory_iterator end_itr;
 
			for (directory_iterator itr(p); itr != end_itr; ++itr) {
 
				if (last_write_time(itr->path()) < t) {
 
					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) {
 
						
 
					}
 
				}
 
			}
 

	
 

	
 
		}
 
		catch (const filesystem_error& ex) {
 
			
0 comments (0 inline, 0 general)