diff options
Diffstat (limited to '')
-rw-r--r-- | src/conditionfiletime.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/conditionfiletime.cpp b/src/conditionfiletime.cpp new file mode 100644 index 0000000..224caf1 --- /dev/null +++ b/src/conditionfiletime.cpp | |||
@@ -0,0 +1,73 @@ | |||
1 | #include "conditionfiletime.h" | ||
2 | #include "target.h" | ||
3 | |||
4 | #include <sys/types.h> | ||
5 | #include <sys/stat.h> | ||
6 | #include <unistd.h> | ||
7 | |||
8 | #include <bu/sio.h> | ||
9 | using namespace Bu; | ||
10 | |||
11 | ConditionFileTime::ConditionFileTime() | ||
12 | { | ||
13 | } | ||
14 | |||
15 | ConditionFileTime::~ConditionFileTime() | ||
16 | { | ||
17 | } | ||
18 | |||
19 | bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget ) | ||
20 | { | ||
21 | for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ ) | ||
22 | { | ||
23 | if( access( (*j).getStr(), F_OK ) ) | ||
24 | { | ||
25 | //sio << "-- Target processed because '" << *j << "' doesn't exist." | ||
26 | // << sio.nl; | ||
27 | // Output doesn't exist | ||
28 | return true; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | time_t tOut = 0; | ||
33 | struct stat s; | ||
34 | for( StrList::const_iterator j = rTarget.getOutputList().begin(); | ||
35 | j; j++ ) | ||
36 | { | ||
37 | stat( (*j).getStr(), &s ); | ||
38 | if( tOut == 0 || tOut > s.st_mtime ) | ||
39 | { | ||
40 | tOut = s.st_mtime; | ||
41 | } | ||
42 | } | ||
43 | for( StrList::const_iterator j = rTarget.getInputList().begin(); | ||
44 | j; j++ ) | ||
45 | { | ||
46 | stat( (*j).getStr(), &s ); | ||
47 | if( tOut < s.st_mtime ) | ||
48 | { | ||
49 | //sio << "-- Target processed because '" << *j | ||
50 | // << "' is newer than output." << sio.nl; | ||
51 | return true; | ||
52 | } | ||
53 | } | ||
54 | rTarget.buildRequires( r ); | ||
55 | for( StrList::const_iterator j = rTarget.getRequiresList().begin(); | ||
56 | j; j++ ) | ||
57 | { | ||
58 | stat( (*j).getStr(), &s ); | ||
59 | if( tOut < s.st_mtime ) | ||
60 | { | ||
61 | //sio << "-- Target processed because '" << *j | ||
62 | // << "' is newer than output." << sio.nl; | ||
63 | return true; | ||
64 | } | ||
65 | } | ||
66 | return false; | ||
67 | } | ||
68 | |||
69 | Condition *ConditionFileTime::clone() | ||
70 | { | ||
71 | return new ConditionFileTime(); | ||
72 | } | ||
73 | |||