From b9a82317961f6bc89855bf19d9ed71db8d383da9 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Thu, 17 Jan 2013 09:44:57 +0100 Subject: [PATCH] another try to fix createDirectories compilation for oneiric --- include/transport/util.h | 2 +- spectrum/src/main.cpp | 28 +++++++++++++++++++++++++++- src/util.cpp | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/transport/util.h b/include/transport/util.h index 5e7e4f4d..490724bf 100644 --- a/include/transport/util.h +++ b/include/transport/util.h @@ -33,7 +33,7 @@ namespace Transport { namespace Util { -void createDirectories(Transport::Config *config, boost::filesystem::path ph); +void createDirectories(Transport::Config *config, const boost::filesystem::path& ph); void removeEverythingOlderThan(const std::vector &dirs, time_t t); diff --git a/spectrum/src/main.cpp b/spectrum/src/main.cpp index 2397766b..a024138e 100644 --- a/spectrum/src/main.cpp +++ b/spectrum/src/main.cpp @@ -131,6 +131,32 @@ static void daemonize(const char *cwd, const char *lock_file) { } #endif +static void _createDirectories(Transport::Config *config, boost::filesystem::path ph) { + if (ph.empty() || exists(ph)) { + return; + } + + // First create branch, by calling ourself recursively + _createDirectories(config, ph.branch_path()); + + // Now that parent's path exists, create the directory + boost::filesystem::create_directory(ph); + +#ifndef WIN32 + if (!CONFIG_STRING(config, "service.group").empty() && !CONFIG_STRING(config, "service.user").empty()) { + struct group *gr; + if ((gr = getgrnam(CONFIG_STRING(config, "service.group").c_str())) == NULL) { + std::cerr << "Invalid service.group name " << CONFIG_STRING(config, "service.group") << "\n"; + } + struct passwd *pw; + if ((pw = getpwnam(CONFIG_STRING(config, "service.user").c_str())) == NULL) { + std::cerr << "Invalid service.user name " << CONFIG_STRING(config, "service.user") << "\n"; + } + chown(ph.string().c_str(), pw->pw_uid, gr->gr_gid); + } +#endif +} + int mainloop() { #ifndef WIN32 @@ -400,7 +426,7 @@ int main(int argc, char **argv) // create directories try { - Transport::Util::createDirectories(&config, boost::filesystem::path(CONFIG_STRING(&config, "service.working_dir"))); + _createDirectories(&config, boost::filesystem::path(CONFIG_STRING(&config, "service.working_dir"))); } catch (...) { std::cerr << "Can't create service.working_dir directory " << CONFIG_STRING(&config, "service.working_dir") << ".\n"; diff --git a/src/util.cpp b/src/util.cpp index d96da239..b8c3adc5 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -49,7 +49,7 @@ namespace Transport { namespace Util { -void createDirectories(Transport::Config *config, path ph) { +void createDirectories(Transport::Config *config, const boost::filesystem::path& ph) { if (ph.empty() || exists(ph)) { return; }