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);
28 if(!worker) // True for dry run
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 // Remove old file. Not doing this would cause Bad Stuff when installing libraries.
54 if(unlink(copy.dest.str().c_str())<0 && errno!=ENOENT)
57 cerr<<"Can't unlink "<<copy.dest<<": "<<strerror(err)<<'\n';
62 ifstream in(copy.src.str().c_str());
65 cerr<<"Can't open "<<copy.src<<" for reading\n";
70 ofstream out(copy.dest.str().c_str());
73 cerr<<"Can't open "<<copy.dest<<" for writing\n";
78 // Actual transfer loop
82 in.read(buf, sizeof(buf));
83 out.write(buf, in.gcount());
86 // Preserve file permissions
88 Path::stat(copy.src, st);
89 chmod(copy.dest.str().c_str(), st.st_mode&0777);