aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-06 21:30:36 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-06 21:30:36 +0000
commit0b83cebe78a906410c7d57195710d74abc40c8e5 (patch)
tree255198dd58887a8c29652e9659ee4841f68fb376
parente6f5c377749851dfefcf86a7dcd32a1068c9919e (diff)
downloadpaludis-0b83cebe78a906410c7d57195710d74abc40c8e5.tar.gz
paludis-0b83cebe78a906410c7d57195710d74abc40c8e5.tar.xz
Make merge much faster
-rw-r--r--ebuild/utils/merge.cc29
1 files changed, 18 insertions, 11 deletions
diff --git a/ebuild/utils/merge.cc b/ebuild/utils/merge.cc
index af8083b..e074520 100644
--- a/ebuild/utils/merge.cc
+++ b/ebuild/utils/merge.cc
@@ -103,10 +103,12 @@ namespace
{
private:
const int _fd;
+ const bool _sync;
public:
- FDHolder(const int fd) :
- _fd(fd)
+ FDHolder(const int fd, bool sync = true) :
+ _fd(fd),
+ _sync(sync)
{
}
@@ -114,7 +116,8 @@ namespace
{
if (-1 != _fd)
{
- ::fsync(_fd);
+ if (_sync)
+ ::fsync(_fd);
::close(_fd);
}
}
@@ -174,6 +177,15 @@ namespace
}
void
+ copy_file_contents(int input_fd, int fd)
+ {
+ char buf[4096];
+ ssize_t count;
+ while ((count = read(input_fd, buf, 4096)) > 0)
+ write(fd, buf, 4096);
+ }
+
+ void
do_obj(const FSEntry & root, const FSEntry & src,
const FSEntry & dst, ofstream * const contents)
{
@@ -195,8 +207,8 @@ namespace
{
FSEntry real_dst(dst);
- ifstream input_file(stringify(src).c_str());
- if (! input_file)
+ FDHolder input_fd(::open(stringify(src).c_str(), O_RDONLY), false);
+ if (-1 == input_fd)
throw Failure("Cannot read '" + stringify(src) + "'");
if (dst.exists())
@@ -242,12 +254,7 @@ namespace
throw Failure("Cannot fchmod '" + stringify(real_dst) + "': " +
stringify(::strerror(errno)));
- FDOutputStream output_file(fd);
- if (! output_file)
- throw Failure("Cannot write '" + stringify(dst) + "'");
-
- std::copy((istreambuf_iterator<char>(input_file)), istreambuf_iterator<char>(),
- ostreambuf_iterator<char>(output_file));
+ copy_file_contents(input_fd, fd);
}
ifstream dst_file(stringify(dst).c_str());