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 &s, const Path &d):
24 announce(pkg.get_name(), "COPY", dest[-1]);
25 if(builder.get_verbose()>=2)
26 cout<<s<<" -> "<<d<<'\n';
28 if(!builder.get_dry_run())
29 worker=new Worker(*this);
33 Copy::Worker::Worker(Copy &c):
39 void Copy::Worker::main()
41 mkpath(copy.dest.subpath(0, copy.dest.size()-1), 0755);
45 // Remove old file. Not doing this would cause Bad Stuff when installing libraries.
48 catch(const SystemError &e)
50 if(e.get_error_code()!=ENOENT)
58 ifstream in(copy.src.str().c_str());
61 cerr<<"Can't open "<<copy.src<<" for reading\n";
66 ofstream out(copy.dest.str().c_str());
69 cerr<<"Can't open "<<copy.dest<<" for writing\n";
74 // Actual transfer loop
78 in.read(buf, sizeof(buf));
79 out.write(buf, in.gcount());
82 // Preserve file permissions
83 struct stat st=stat(copy.src);
84 chmod(copy.dest.str().c_str(), st.st_mode&0777);