]> git.tdb.fi Git - builder.git/blobdiff - source/task.cpp
Handle directory creation and unlinking in Task
[builder.git] / source / task.cpp
diff --git a/source/task.cpp b/source/task.cpp
new file mode 100644 (file)
index 0000000..f6fa7b2
--- /dev/null
@@ -0,0 +1,38 @@
+#include <msp/fs/dir.h>
+#include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
+#include "task.h"
+
+using namespace Msp;
+
+Task::Task():
+       unlink(false)
+{ }
+
+void Task::set_file(const FS::Path &f)
+{
+       file = f;
+}
+
+void Task::set_unlink(bool u)
+{
+       unlink = u;
+}
+
+void Task::prepare()
+{
+       if(!file.empty())
+       {
+               if(FS::exists(file))
+               {
+                       // If the file exists, the directory it's in must exist too
+                       FS::unlink(file);
+               }
+               else
+               {
+                       FS::Path dir = FS::dirname(file);
+                       if(!FS::exists(dir))
+                               FS::mkpath(dir, 0755);
+               }
+       }
+}