From 6b71fd1e4edd46b7caf47135740c961d5d4f051c Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Sat, 04 Apr 2009 23:28:48 +0000 Subject: make upload directory if it doesn't exist Signed-off-by: Michael Krelin --- (limited to 'src') diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc index 30c06fa..97cb33b 100644 --- a/src/eyefiservice.cc +++ b/src/eyefiservice.cc @@ -120,7 +120,6 @@ int eyefiService::UploadPhoto( umask(eyekinfig.get_umask()); std::string td = eyekinfig.get_targetdir(); - /* TODO: try to create, if needed */ tmpdir_t indir(td+"/.incoming.XXXXXX"); for(soap_multipart::iterator i=mime.begin(),ie=mime.end();i!=ie;++i) { diff --git a/src/eyetil.cc b/src/eyetil.cc index d00c2ee..2fbd687 100644 --- a/src/eyetil.cc +++ b/src/eyetil.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -51,7 +52,22 @@ binary_t binary_t::md5() const { return rv; } +static void make_path_for_template(const std::string& p,mode_t m) { + struct stat st; + std::string pp; + for(std::string::size_type sl=p.find('/',1); + sl!=std::string::npos; + sl=p.find('/',sl+1)) { + if(stat( (pp=p.substr(0,sl)).c_str() ,&st) + || !S_ISDIR(st.st_mode)) { + if(mkdir(pp.c_str(),m)) + throw std::runtime_error("failed to mkdir()"); + } + } +} + tmpdir_t::tmpdir_t(const std::string& dt) : dir(dt) { + make_path_for_template(dt,0777); if(!mkdtemp((char*)dir.data())) throw std::runtime_error("failed to mkdtmp()"); } -- cgit v0.9.0.2