4 #include <msp/path/utils.h>
12 Copy::Copy(Builder &b, const Package &pkg, const Path::Path &s, const Path::Path &d):
18 announce(pkg.get_name(), "COPY", dest[-1]);
19 if(builder.get_verbose()>=2)
20 cout<<s<<" -> "<<d<<'\n';
22 if(!builder.get_dry_run())
23 worker=new Worker(*this);
34 if(worker->get_done())
38 return worker->get_error()?1:0;
49 void Copy::Worker::main()
51 Path::mkpath(copy.dest.subpath(0, copy.dest.size()-1), 0755);
53 if(unlink(copy.dest.str().c_str())<0 && errno!=ENOENT)
56 cerr<<"Can't unlink "<<copy.dest<<": "<<strerror(err)<<'\n';
61 ifstream in(copy.src.str().c_str());
64 cerr<<"Can't open "<<copy.src<<" for reading\n";
69 ofstream out(copy.dest.str().c_str());
72 cerr<<"Can't open "<<copy.dest<<" for writing\n";
80 in.read(buf, sizeof(buf));
81 out.write(buf, in.gcount());
85 Path::stat(copy.src, st);
86 chmod(copy.dest.str().c_str(), st.st_mode&0777);