3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
11 #include <msp/fs/dir.h>
12 #include <msp/fs/stat.h>
13 #include <msp/fs/utils.h>
21 Copy::Copy(Builder &b, const Package &pkg, const FS::Path &s, const FS::Path &d):
26 announce(pkg.get_name(), "COPY", dest[-1]);
27 if(builder.get_verbose()>=2)
28 cout<<s<<" -> "<<d<<'\n';
30 if(!builder.get_dry_run())
31 worker=new Worker(*this);
35 Copy::Worker::Worker(Copy &c):
41 void Copy::Worker::main()
43 FS::mkpath(FS::dirname(copy.dest), 0755);
47 // Remove old file. Not doing this would cause Bad Stuff when installing libraries.
50 catch(const SystemError &e)
52 if(e.get_error_code()!=ENOENT)
60 ifstream in(copy.src.str().c_str());
63 cerr<<"Can't open "<<copy.src<<" for reading\n";
68 ofstream out(copy.dest.str().c_str());
71 cerr<<"Can't open "<<copy.dest<<" for writing\n";
76 // Actual transfer loop
80 in.read(buf, sizeof(buf));
81 out.write(buf, in.gcount());
84 // Preserve file permissions
85 struct stat st=FS::stat(copy.src);
86 chmod(copy.dest.str().c_str(), st.st_mode&0777);