]> git.tdb.fi Git - builder.git/blob - source/task.cpp
Handle directory creation and unlinking in Task
[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 Msp;
7
8 Task::Task():
9         unlink(false)
10 { }
11
12 void Task::set_file(const FS::Path &f)
13 {
14         file = f;
15 }
16
17 void Task::set_unlink(bool u)
18 {
19         unlink = u;
20 }
21
22 void Task::prepare()
23 {
24         if(!file.empty())
25         {
26                 if(FS::exists(file))
27                 {
28                         // If the file exists, the directory it's in must exist too
29                         FS::unlink(file);
30                 }
31                 else
32                 {
33                         FS::Path dir = FS::dirname(file);
34                         if(!FS::exists(dir))
35                                 FS::mkpath(dir, 0755);
36                 }
37         }
38 }