author | Michael Krelin <hacker@klever.net> | 2009-04-04 23:28:48 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2009-04-05 00:40:46 (UTC) |
commit | 6b71fd1e4edd46b7caf47135740c961d5d4f051c (patch) (side-by-side diff) | |
tree | 03dbdfb8fdbdf1c823af1a5bd32611d736f5ddf1 | |
parent | aadaa8b5d7eda23e72dbded9d6437b40358353f3 (diff) | |
download | iii-6b71fd1e4edd46b7caf47135740c961d5d4f051c.zip iii-6b71fd1e4edd46b7caf47135740c961d5d4f051c.tar.gz iii-6b71fd1e4edd46b7caf47135740c961d5d4f051c.tar.bz2 |
make upload directory if it doesn't exist
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | src/eyefiservice.cc | 1 | ||||
-rw-r--r-- | src/eyetil.cc | 16 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/eyefiservice.cc b/src/eyefiservice.cc index 30c06fa..97cb33b 100644 --- a/src/eyefiservice.cc +++ b/src/eyefiservice.cc @@ -122,3 +122,2 @@ int eyefiService::UploadPhoto( std::string td = eyekinfig.get_targetdir(); - /* TODO: try to create, if needed */ tmpdir_t indir(td+"/.incoming.XXXXXX"); diff --git a/src/eyetil.cc b/src/eyetil.cc index d00c2ee..2fbd687 100644 --- a/src/eyetil.cc +++ b/src/eyetil.cc @@ -1,2 +1,3 @@ #include <stdlib.h> +#include <sys/stat.h> #include <syslog.h> @@ -53,3 +54,18 @@ binary_t binary_t::md5() const { +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())) |