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, const FS::Path &l):
21 announce(pkg.get_name(), "COPY", dest.str());
22 if(builder.get_verbose()>=2)
23 IO::print("%s -> %s\n", s, d);
25 if(!builder.get_dry_run())
26 worker = new Worker(*this);
30 Copy::Worker::Worker(Copy &c):
36 void Copy::Worker::main()
38 FS::mkpath(FS::dirname(copy.dest), 0755);
40 // Remove old file. Not doing this would cause Bad Stuff when installing libraries.
41 if(FS::exists(copy.dest))
47 catch(const exception &e)
49 IO::print(IO::cerr, "%s\n", e.what());
57 IO::File in(copy.src.str());
58 IO::File out(copy.dest.str(), IO::M_WRITE);
60 // Actual transfer loop
64 unsigned len = in.read(buf, sizeof(buf));
68 catch(const exception &e)
70 IO::print(IO::cerr, "%s\n", e.what());
75 // Preserve file permissions
77 if(stat(copy.src.str().c_str(), &st)==0)
78 chmod(copy.dest.str().c_str(), st.st_mode&0777);
80 if(!copy.link.empty())
82 FS::Path relpath = FS::relative(copy.dest, FS::dirname(copy.link));
83 symlink(relpath.str().c_str(), copy.link.str().c_str());