3 This file is part of builder
4 Copyright © 2006-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
9 #include <msp/fs/dir.h>
10 #include <msp/fs/stat.h>
11 #include <msp/fs/utils.h>
12 #include <msp/io/file.h>
13 #include <msp/io/print.h>
21 Copy::Copy(Builder &b, const Package &pkg, const FS::Path &s, const FS::Path &d):
26 announce(pkg.get_name(), "COPY", dest.str());
27 if(builder.get_verbose()>=2)
28 IO::print("%s -> %s\n", s, d);
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);
45 // Remove old file. Not doing this would cause Bad Stuff when installing libraries.
46 if(FS::exists(copy.dest))
52 catch(const Exception &e)
54 IO::print(IO::cerr, "%s\n", e.what());
62 IO::File in(copy.src.str());
63 IO::File out(copy.dest.str(), IO::M_WRITE);
65 // Actual transfer loop
69 unsigned len = in.read(buf, sizeof(buf));
73 catch(const Exception &e)
75 IO::print(IO::cerr, "%s\n", e.what());
80 // Preserve file permissions
81 struct stat st = FS::stat(copy.src);
82 chmod(copy.dest.str().c_str(), st.st_mode&0777);