3 #include <msp/fs/dir.h>
4 #include <msp/fs/stat.h>
5 #include <msp/fs/utils.h>
6 #include <msp/io/file.h>
7 #include <msp/io/print.h>
15 Copy::Copy(Builder &b, const Package &pkg, const FS::Path &s, const FS::Path &d):
20 announce(pkg.get_name(), "COPY", dest.str());
21 if(builder.get_verbose()>=2)
22 IO::print("%s -> %s\n", s, d);
24 if(!builder.get_dry_run())
25 worker = new Worker(*this);
29 Copy::Worker::Worker(Copy &c):
35 void Copy::Worker::main()
37 FS::mkpath(FS::dirname(copy.dest), 0755);
39 // Remove old file. Not doing this would cause Bad Stuff when installing libraries.
40 if(FS::exists(copy.dest))
46 catch(const exception &e)
48 IO::print(IO::cerr, "%s\n", e.what());
56 IO::File in(copy.src.str());
57 IO::File out(copy.dest.str(), IO::M_WRITE);
59 // Actual transfer loop
63 unsigned len = in.read(buf, sizeof(buf));
67 catch(const exception &e)
69 IO::print(IO::cerr, "%s\n", e.what());
74 // Preserve file permissions
76 if(stat(copy.src.str().c_str(), &st)==0)
77 chmod(copy.dest.str().c_str(), st.st_mode&0777);