summaryrefslogtreecommitdiffabout
path: root/lib/file_factory.cc
Unidiff
Diffstat (limited to 'lib/file_factory.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/file_factory.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/file_factory.cc b/lib/file_factory.cc
new file mode 100644
index 0000000..c6b5748
--- a/dev/null
+++ b/lib/file_factory.cc
@@ -0,0 +1,55 @@
1#ifdef USE_PCH
2 #include "pch.h"
3#else
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <unistd.h>
7 #include <konforka/exception.h>
8 using namespace std;
9 #include "sitecing/file_factory.h"
10#endif
11
12namespace sitecing {
13
14 bool file_factory::is_uptodate(const string& dst,file_list_t* deps) {
15 file_list_t deplist;
16 file_list_t *fl = deps?deps:&deplist;
17 get_dependencies(dst,*fl);
18 struct stat stdst;
19 if(stat(dst.c_str(),&stdst))
20 return false;
21 for(file_list_t::const_iterator i=fl->begin();i!=fl->end();i++) {
22 struct stat stdep;
23 if(stat(i->c_str(),&stdep))
24 return false;
25 if(stdst.st_mtime<stdep.st_mtime)
26 return false;
27 if(!is_uptodate(*i))
28 return false;
29 }
30 return true;
31 }
32
33 void file_factory::make(const string& dst) {
34 try {
35 depth++;
36 if(depth>25)
37 throw konforka::exception(CODEPOINT,"recursed too deeply.");
38 file_list_t deps;
39 if(!is_uptodate(dst,&deps)) {
40 for(file_list_t::const_iterator i=deps.begin();i!=deps.end();i++)
41 make(*i);
42 build(dst);
43 }
44 depth--;
45 }catch(konforka::exception& ke) {
46 depth--;
47 ke.see(CODEPOINT);
48 throw;
49 }catch(...) {
50 depth--;
51 throw;
52 }
53 }
54
55}