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):
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 Path::mkpath(copy.dest.subpath(0, copy.dest.size()-1), 0755);
43 // Remove old file. Not doing this would cause Bad Stuff when installing libraries.
44 if(unlink(copy.dest.str().c_str())<0 && errno!=ENOENT)
47 cerr<<"Can't unlink "<<copy.dest<<": "<<strerror(err)<<'\n';
52 ifstream in(copy.src.str().c_str());
55 cerr<<"Can't open "<<copy.src<<" for reading\n";
60 ofstream out(copy.dest.str().c_str());
63 cerr<<"Can't open "<<copy.dest<<" for writing\n";
68 // Actual transfer loop
72 in.read(buf, sizeof(buf));
73 out.write(buf, in.gcount());
76 // Preserve file permissions
78 Path::stat(copy.src, st);
79 chmod(copy.dest.str().c_str(), st.st_mode&0777);