another try to fix createDirectories compilation for oneiric

This commit is contained in:
Jan Kaluza 2013-01-17 09:44:57 +01:00
parent 2fda71965d
commit b9a8231796
3 changed files with 29 additions and 3 deletions

View file

@ -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<std::string> &dirs, time_t t);

View file

@ -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";

View file

@ -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;
}