3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
11 #include <msp/path/utils.h>
19 Copy::Copy(Builder &b, const Package &pkg, const Path::Path &s, const Path::Path &d):
25 announce(pkg.get_name(), "COPY", dest[-1]);
26 if(builder.get_verbose()>=2)
27 cout<<s<<" -> "<<d<<'\n';
29 if(!builder.get_dry_run())
30 worker=new Worker(*this);
35 if(!worker) // True for dry run
41 if(worker->get_done())
45 return worker->get_error()?1:0;
56 void Copy::Worker::main()
58 Path::mkpath(copy.dest.subpath(0, copy.dest.size()-1), 0755);
60 // Remove old file. Not doing this would cause Bad Stuff when installing libraries.
61 if(unlink(copy.dest.str().c_str())<0 && errno!=ENOENT)
64 cerr<<"Can't unlink "<<copy.dest<<": "<<strerror(err)<<'\n';
69 ifstream in(copy.src.str().c_str());
72 cerr<<"Can't open "<<copy.src<<" for reading\n";
77 ofstream out(copy.dest.str().c_str());
80 cerr<<"Can't open "<<copy.dest<<" for writing\n";
85 // Actual transfer loop
89 in.read(buf, sizeof(buf));
90 out.write(buf, in.gcount());
93 // Preserve file permissions
95 Path::stat(copy.src, st);
96 chmod(copy.dest.str().c_str(), st.st_mode&0777);