3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
10 #include <msp/fs/dir.h>
11 #include <msp/fs/stat.h>
12 #include <msp/fs/utils.h>
13 #include <msp/io/file.h>
14 #include <msp/io/print.h>
22 Copy::Copy(Builder &b, const Package &pkg, const FS::Path &s, const FS::Path &d):
27 announce(pkg.get_name(), "COPY", dest.str());
28 if(builder.get_verbose()>=2)
29 IO::print("%s -> %s\n", s, d);
31 if(!builder.get_dry_run())
32 worker = new Worker(*this);
36 Copy::Worker::Worker(Copy &c):
42 void Copy::Worker::main()
44 FS::mkpath(FS::dirname(copy.dest), 0755);
46 // Remove old file. Not doing this would cause Bad Stuff when installing libraries.
47 if(FS::exists(copy.dest))
53 catch(const exception &e)
55 IO::print(IO::cerr, "%s\n", e.what());
63 IO::File in(copy.src.str());
64 IO::File out(copy.dest.str(), IO::M_WRITE);
66 // Actual transfer loop
70 unsigned len = in.read(buf, sizeof(buf));
74 catch(const exception &e)
76 IO::print(IO::cerr, "%s\n", e.what());
81 // Preserve file permissions
83 if(stat(copy.src.str().c_str(), &st)==0)
84 chmod(copy.dest.str().c_str(), st.st_mode&0777);