1 | /* |
---|
2 | * |
---|
3 | * Copyright (c) 2003 Dr John Maddock |
---|
4 | * Use, modification and distribution is subject to the |
---|
5 | * Boost Software License, Version 1.0. (See accompanying file |
---|
6 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | * |
---|
8 | * This file implements the following: |
---|
9 | * void bcp_implementation::copy_path(const fs::path& p) |
---|
10 | * void bcp_implementation::create_path(const fs::path& p) |
---|
11 | */ |
---|
12 | |
---|
13 | #include "bcp_imp.hpp" |
---|
14 | #include <boost/filesystem/operations.hpp> |
---|
15 | #include <fstream> |
---|
16 | #include <iterator> |
---|
17 | #include <algorithm> |
---|
18 | #include <iostream> |
---|
19 | |
---|
20 | void bcp_implementation::copy_path(const fs::path& p) |
---|
21 | { |
---|
22 | assert(!fs::is_directory(m_boost_path / p)); |
---|
23 | if(fs::exists(m_dest_path / p)) |
---|
24 | { |
---|
25 | std::cout << "Copying (and overwriting) file: " << p.string() << "\n"; |
---|
26 | fs::remove(m_dest_path / p); |
---|
27 | } |
---|
28 | else |
---|
29 | std::cout << "Copying file: " << p.string() << "\n"; |
---|
30 | // |
---|
31 | // create the path to the new file if it doesn't already exist: |
---|
32 | // |
---|
33 | create_path(p.branch_path()); |
---|
34 | // |
---|
35 | // do text based copy if requested: |
---|
36 | // |
---|
37 | if(m_unix_lines && !is_binary_file(p)) |
---|
38 | { |
---|
39 | std::ifstream is((m_boost_path / p).native_file_string().c_str()); |
---|
40 | std::istreambuf_iterator<char> isi(is); |
---|
41 | std::istreambuf_iterator<char> end; |
---|
42 | |
---|
43 | std::ofstream os((m_dest_path / p).native_file_string().c_str(), std::ios_base::binary | std::ios_base::out); |
---|
44 | std::ostreambuf_iterator<char> osi(os); |
---|
45 | |
---|
46 | std::copy(isi, end, osi); |
---|
47 | } |
---|
48 | else |
---|
49 | { |
---|
50 | // binary copy: |
---|
51 | fs::copy_file(m_boost_path / p, m_dest_path / p); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | void bcp_implementation::create_path(const fs::path& p) |
---|
56 | { |
---|
57 | if(!fs::exists(m_dest_path / p)) |
---|
58 | { |
---|
59 | // recurse then create the path: |
---|
60 | create_path(p.branch_path()); |
---|
61 | fs::create_directory(m_dest_path / p); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | |
---|