3 #include <msp/path/utils.h>
11 Copy::Copy(Builder &b, const Package &pkg, const Path::Path &s, const Path::Path &d):
17 announce(pkg.get_name(), "COPY", dest[-1]);
18 if(builder.get_verbose()>=2)
19 cout<<s<<" -> "<<d<<'\n';
21 if(!builder.get_dry_run())
22 worker=new Worker(*this);
30 if(worker->get_done())
34 return worker->get_error()?1:0;
45 void Copy::Worker::main()
47 Path::mkpath(copy.dest.subpath(0, copy.dest.size()-1), 0755);
49 if(unlink(copy.dest.str().c_str())<0 && errno!=ENOENT)
52 cerr<<"Can't unlink "<<copy.dest<<": "<<strerror(err)<<'\n';
57 ifstream in(copy.src.str().c_str());
60 cerr<<"Can't open "<<copy.src<<" for reading\n";
65 ofstream out(copy.dest.str().c_str());
68 cerr<<"Can't open "<<copy.dest<<" for writing\n";
76 in.read(buf, sizeof(buf));
77 out.write(buf, in.gcount());
81 Path::stat(copy.src, st);
82 chmod(copy.dest.str().c_str(), st.st_mode&0777);