]> git.tdb.fi Git - builder.git/blob - source/lib/task.cpp
Associate targets with FileTargets instead of paths
[builder.git] / source / lib / task.cpp
1 #include <msp/fs/dir.h>
2 #include <msp/fs/stat.h>
3 #include <msp/fs/utils.h>
4 #include "filetarget.h"
5 #include "task.h"
6
7 using namespace std;
8 using namespace Msp;
9
10 void Task::add_target(const FileTarget &t)
11 {
12         targets.push_back(&t);
13 }
14
15 void Task::set_unlink(bool u)
16 {
17         unlink = u;
18 }
19
20 void Task::prepare()
21 {
22         for(const FileTarget *t: targets)
23         {
24                 const FS::Path &f = t->get_path();
25                 if(FS::exists(f))
26                 {
27                         // If the file exists, the directory it's in must exist too
28                         FS::unlink(f);
29                 }
30                 else
31                 {
32                         FS::Path dir = FS::dirname(f);
33                         if(!FS::exists(dir))
34                                 FS::mkpath(dir, 0755);
35                 }
36         }
37 }