<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,11 @@
 #!/usr/bin/env ruby
+ESSENTIALS = [
+	&quot;boost/detail/{limits,endian}.hpp&quot;,
+	&quot;boost/config/*&quot;,
+	&quot;boost/detail/sp_counted_*&quot;,
+	&quot;boost/detail/atomic_count*&quot;,
+	&quot;libs/thread/src/*&quot;
+]
 PROGRAM_SOURCE = %q{
 	#include &lt;boost/shared_ptr.hpp&gt;
 	#include &lt;boost/thread.hpp&gt;
@@ -6,13 +13,10 @@ PROGRAM_SOURCE = %q{
 	#include &lt;boost/bind.hpp&gt;
 	#include &lt;boost/date_time/posix_time/posix_time.hpp&gt;
 }
-
-boost_dir = ARGV[0]
+BOOST_DIR = ARGV[0]
 Dir.chdir(File.dirname(__FILE__) + &quot;/../ext&quot;)
-File.open(&quot;test.cpp&quot;, &quot;w&quot;) do |f|
-	f.write(PROGRAM_SOURCE)
-end
 
+# Run the given command, and abort on error.
 def sh(*command)
 	puts command.join(&quot; &quot;)
 	if !system(*command)
@@ -21,30 +25,78 @@ def sh(*command)
 	end
 end
 
-done = false
-while !done
-	missing_headers = `g++ test.cpp -c -I. 2&gt;&amp;1`.
-	  split(&quot;\n&quot;).
-	  grep(/error: .*: No such file/).
-	  map do |line|
-		file = line.sub(/.*error: (.*): .*/, '\1')
-		if file =~ /^boost\//
-			file
-		else
-			line =~ /(.*?):/
-			source = $1
-			File.dirname(source) + &quot;/&quot; + file
+def install(source_filename, target_filename)
+	command = [&quot;install&quot;, &quot;-D&quot;, &quot;--mode=u+rw,g+r,o+r&quot;, source_filename, target_filename]
+	sh(*command)
+end
+
+def copy_boost_files(*patterns)
+	patterns.each do |pattern|
+		Dir[&quot;#{BOOST_DIR}/#{pattern}&quot;].each do |source|
+			if File.directory?(source)
+				source.slice!(0 .. BOOST_DIR.size)
+				copy_boost_files(&quot;#{source}/*&quot;)
+			else
+				target = source.slice(BOOST_DIR.size + 1 .. source.size - 1)
+				target.sub!(%r{^libs/thread/}, 'boost/')
+				if !File.exist?(target)
+					install(source, target)
+				end
+			end
+		end
+	end
+end
+
+def copy_essential_files
+	copy_boost_files(*ESSENTIALS)
+end
+
+def prepare
+	File.open(&quot;test.cpp&quot;, &quot;w&quot;) do |f|
+		f.write(PROGRAM_SOURCE)
+	end
+end
+
+def cleanup
+	File.unlink(&quot;test.cpp&quot;) rescue nil
+end
+
+# Compile PROGRAM_SOURCE and copy whatever missing header files the compiler needs.
+def copy_dependencies
+	done = false
+	while !done
+		missing_headers = `g++ test.cpp -c -I. 2&gt;&amp;1`.
+		  split(&quot;\n&quot;).
+		  grep(/error: .*: No such file/).
+		  map do |line|
+			file = line.sub(/.*error: (.*): .*/, '\1')
+			if file =~ /^boost\//
+				file
+			else
+				line =~ /(.*?):/
+				source = $1
+				File.dirname(source) + &quot;/&quot; + file
+			end
 		end
+		missing_headers.each do |header|
+			install(&quot;#{BOOST_DIR}/#{header}&quot;, header)
+		end
+		done = missing_headers.empty?
+	end
+end
+
+def start
+	if BOOST_DIR.nil? || BOOST_DIR.empty?
+		puts &quot;Usage: copy_boost_headers.rb &lt;boost source directory&gt;&quot;
+		exit 1
 	end
-	missing_headers.each do |header|
-		command = [&quot;install&quot;, &quot;-D&quot;, &quot;--mode=u+rw,g+r,o+r&quot;, &quot;#{boost_dir}/#{header}&quot;, header]
-		sh(*command)
+	begin
+		prepare
+		copy_essential_files
+		copy_dependencies
+	ensure
+		cleanup
 	end
-	done = missing_headers.empty?
 end
 
-sh &quot;cp    #{boost_dir}/boost/detail/{limits,endian}.hpp boost/detail/&quot;
-sh &quot;cp -R #{boost_dir}/boost/config/* boost/config/&quot;
-sh &quot;cp -R #{boost_dir}/boost/detail/sp_counted_* boost/detail/&quot;
-sh &quot;cp -R #{boost_dir}/boost/detail/atomic_count* boost/detail/&quot;
-sh &quot;mkdir -p boost/src &amp;&amp; cp -R #{boost_dir}/libs/thread/src/* boost/src/&quot;
+start</diff>
      <filename>misc/copy_boost_headers.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8469c8c36e4331d7a7cf5f4f146290786eab2ddc</id>
    </parent>
  </parents>
  <author>
    <name>Hongli Lai (Phusion)</name>
    <email>hongli@phusion.nl</email>
  </author>
  <url>http://github.com/FooBarWidget/passenger/commit/e80e5c2f26280433019907f1aa28cd73dc69c7b5</url>
  <id>e80e5c2f26280433019907f1aa28cd73dc69c7b5</id>
  <committed-date>2008-05-19T03:34:40-07:00</committed-date>
  <authored-date>2008-05-19T03:34:40-07:00</authored-date>
  <message>Improve the Boost copying script: don't overwrite existing files, ever.</message>
  <tree>b943d08c96a6be7cf32c8cb93ba45468856dee7a</tree>
  <committer>
    <name>Hongli Lai (Phusion)</name>
    <email>hongli@phusion.nl</email>
  </committer>
</commit>
