summaryrefslogtreecommitdiffabout
path: root/lib/file_factory.cc
blob: c22fac2f9b8bd09311b78e79a95f13d3975646a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifdef USE_PCH
 #include "pch.h"
#else
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <konforka/exception.h>
 using namespace std;
 #include "sitecing/file_factory.h"
#endif

namespace sitecing {

    bool file_factory::is_uptodate(const string& dst,file_list_t* deps) {
	file_list_t deplist;
	file_list_t *fl = deps?deps:&deplist;
	get_dependencies(dst,*fl);
	struct stat stdst;
	if(stat(dst.c_str(),&stdst))
	    return false;
	for(file_list_t::const_iterator i=fl->begin();i!=fl->end();++i) {
	    struct stat stdep;
	    if(stat(i->c_str(),&stdep))
		return false;
	    if(stdst.st_mtime<stdep.st_mtime)
		return false;
	    if(!is_uptodate(*i))
		return false;
	}
	return true;
    }

    void file_factory::make(const string& dst) {
	try {
	    depth++;
	    if(depth>25)
		throw konforka::exception(CODEPOINT,"recursed too deeply.");
	    file_list_t deps;
	    if(!is_uptodate(dst,&deps)) {
		for(file_list_t::const_iterator i=deps.begin();i!=deps.end();i++)
		    make(*i);
		if(!is_uptodate(dst,&deps))
		    build(dst);
	    }
	    depth--;
	}catch(konforka::exception& ke) {
	    depth--;
	    ke.see(CODEPOINT);
	    throw;
	}catch(...) {
	    depth--;
	    throw;
	}
    }

}