]> git.tdb.fi Git - builder.git/blob - source/task.cpp
Refactor transitive dependencies to work on all targets
[builder.git] / source / task.cpp
1 #include <msp/fs/dir.h>
2 #include <msp/fs/stat.h>
3 #include <msp/fs/utils.h>
4 #include "task.h"
5
6 using namespace std;
7 using namespace Msp;
8
9 Task::Task():
10         unlink(false)
11 { }
12
13 void Task::add_file(const FS::Path &f)
14 {
15         files.push_back(f);
16 }
17
18 void Task::set_unlink(bool u)
19 {
20         unlink = u;
21 }
22
23 void Task::prepare()
24 {
25         for(list<FS::Path>::const_iterator i=files.begin(); i!=files.end(); ++i)
26         {
27                 if(FS::exists(*i))
28                 {
29                         // If the file exists, the directory it's in must exist too
30                         FS::unlink(*i);
31                 }
32                 else
33                 {
34                         FS::Path dir = FS::dirname(*i);
35                         if(!FS::exists(dir))
36                                 FS::mkpath(dir, 0755);
37                 }
38         }
39 }