]> git.tdb.fi Git - builder.git/blob - source/copy.cpp
Add command line options (not all of them work yet)
[builder.git] / source / copy.cpp
1 #include <fstream>
2 #include <msp/path/utils.h>
3 #include "copy.h"
4 #include "package.h"
5
6 using namespace std;
7 using namespace Msp;
8
9 Copy::Copy(Builder &b, const Package &pkg, const Path::Path &s, const Path::Path &d):
10         Action(b),
11         src(s),
12         dest(d),
13         worker(*this)
14 {
15         announce(pkg.get_name(), "INST", dest[-1]);
16 }
17
18 int Copy::check()
19 {
20         if(worker.get_done())
21         {
22                 signal_done.emit();
23                 worker.join();
24                 return 0;
25         }
26         return -1;
27 }
28
29 void Copy::Worker::main()
30 {
31         Path::mkpath(copy.src.subpath(0, copy.src.size()-1), 0755);
32         unlink(copy.dest.str().c_str());
33         ifstream in(copy.src.str().c_str());
34         ofstream out(copy.dest.str().c_str());
35
36         char buf[16384];
37         while(!in.eof())
38         {
39                 in.read(buf, sizeof(buf));
40                 out.write(buf, in.gcount());
41         }
42
43         struct stat st;
44         Path::stat(copy.src, st);
45         chmod(copy.dest.str().c_str(), st.st_mode&0777);
46
47         done=true;
48 }