]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // boost/filesystem/operations.hpp ---------------------------------------------------// |
2 | ||
3 | // Copyright Beman Dawes 2002-2009 | |
4 | // Copyright Jan Langer 2002 | |
92f5a8d4 | 5 | // Copyright Dietmar Kuehl 2001 |
7c673cae | 6 | // Copyright Vladimir Prus 2002 |
92f5a8d4 | 7 | |
7c673cae FG |
8 | // Distributed under the Boost Software License, Version 1.0. |
9 | // See http://www.boost.org/LICENSE_1_0.txt | |
10 | ||
11 | // Library home page: http://www.boost.org/libs/filesystem | |
12 | ||
13 | //--------------------------------------------------------------------------------------// | |
14 | ||
15 | #ifndef BOOST_FILESYSTEM3_OPERATIONS_HPP | |
16 | #define BOOST_FILESYSTEM3_OPERATIONS_HPP | |
17 | ||
18 | #include <boost/config.hpp> | |
19 | ||
20 | # if defined( BOOST_NO_STD_WSTRING ) | |
21 | # error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support | |
22 | # endif | |
23 | ||
24 | #include <boost/filesystem/config.hpp> | |
25 | #include <boost/filesystem/path.hpp> | |
92f5a8d4 TL |
26 | #include <boost/filesystem/file_status.hpp> |
27 | ||
28 | #ifndef BOOST_FILESYSTEM_NO_DEPRECATED | |
29 | // These includes are left for backward compatibility and should be included directly by users, as needed | |
30 | #include <boost/filesystem/exception.hpp> | |
31 | #include <boost/filesystem/directory.hpp> | |
32 | #endif | |
7c673cae | 33 | |
92f5a8d4 | 34 | #include <boost/core/scoped_enum.hpp> |
7c673cae | 35 | #include <boost/system/error_code.hpp> |
7c673cae | 36 | #include <boost/cstdint.hpp> |
7c673cae | 37 | #include <string> |
7c673cae | 38 | #include <ctime> |
7c673cae FG |
39 | |
40 | #include <boost/config/abi_prefix.hpp> // must be the last #include | |
41 | ||
42 | //--------------------------------------------------------------------------------------// | |
43 | ||
92f5a8d4 TL |
44 | namespace boost { |
45 | namespace filesystem { | |
7c673cae | 46 | |
92f5a8d4 TL |
47 | struct space_info |
48 | { | |
49 | // all values are byte counts | |
50 | boost::uintmax_t capacity; | |
51 | boost::uintmax_t free; // <= capacity | |
52 | boost::uintmax_t available; // <= free | |
53 | }; | |
7c673cae | 54 | |
92f5a8d4 TL |
55 | BOOST_SCOPED_ENUM_DECLARE_BEGIN(copy_option) |
56 | {none=0, fail_if_exists = none, overwrite_if_exists} | |
57 | BOOST_SCOPED_ENUM_DECLARE_END(copy_option) | |
7c673cae FG |
58 | |
59 | //--------------------------------------------------------------------------------------// | |
60 | // implementation details // | |
61 | //--------------------------------------------------------------------------------------// | |
62 | ||
92f5a8d4 TL |
63 | namespace detail { |
64 | ||
65 | // We cannot pass a BOOST_SCOPED_ENUM to a compled function because it will result | |
66 | // in an undefined reference if the library is compled with -std=c++0x but the use | |
67 | // is compiled in C++03 mode, or vice versa. See tickets 6124, 6779, 10038. | |
68 | enum copy_option {none=0, fail_if_exists = none, overwrite_if_exists}; | |
69 | ||
70 | BOOST_FILESYSTEM_DECL | |
71 | file_status status(const path&p, system::error_code* ec=0); | |
72 | BOOST_FILESYSTEM_DECL | |
73 | file_status symlink_status(const path& p, system::error_code* ec=0); | |
74 | BOOST_FILESYSTEM_DECL | |
75 | bool is_empty(const path& p, system::error_code* ec=0); | |
76 | BOOST_FILESYSTEM_DECL | |
77 | path initial_path(system::error_code* ec=0); | |
78 | BOOST_FILESYSTEM_DECL | |
79 | path canonical(const path& p, const path& base, system::error_code* ec=0); | |
80 | BOOST_FILESYSTEM_DECL | |
81 | void copy(const path& from, const path& to, system::error_code* ec=0); | |
82 | BOOST_FILESYSTEM_DECL | |
83 | void copy_directory(const path& from, const path& to, system::error_code* ec=0); | |
84 | BOOST_FILESYSTEM_DECL | |
85 | void copy_file(const path& from, const path& to, // See ticket #2925 | |
86 | detail::copy_option option, system::error_code* ec=0); | |
87 | BOOST_FILESYSTEM_DECL | |
88 | void copy_symlink(const path& existing_symlink, const path& new_symlink, system::error_code* ec=0); | |
89 | BOOST_FILESYSTEM_DECL | |
90 | bool create_directories(const path& p, system::error_code* ec=0); | |
91 | BOOST_FILESYSTEM_DECL | |
92 | bool create_directory(const path& p, system::error_code* ec=0); | |
93 | BOOST_FILESYSTEM_DECL | |
94 | void create_directory_symlink(const path& to, const path& from, | |
95 | system::error_code* ec=0); | |
96 | BOOST_FILESYSTEM_DECL | |
97 | void create_hard_link(const path& to, const path& from, system::error_code* ec=0); | |
98 | BOOST_FILESYSTEM_DECL | |
99 | void create_symlink(const path& to, const path& from, system::error_code* ec=0); | |
100 | BOOST_FILESYSTEM_DECL | |
101 | path current_path(system::error_code* ec=0); | |
102 | BOOST_FILESYSTEM_DECL | |
103 | void current_path(const path& p, system::error_code* ec=0); | |
104 | BOOST_FILESYSTEM_DECL | |
105 | bool equivalent(const path& p1, const path& p2, system::error_code* ec=0); | |
106 | BOOST_FILESYSTEM_DECL | |
107 | boost::uintmax_t file_size(const path& p, system::error_code* ec=0); | |
108 | BOOST_FILESYSTEM_DECL | |
109 | boost::uintmax_t hard_link_count(const path& p, system::error_code* ec=0); | |
110 | BOOST_FILESYSTEM_DECL | |
111 | std::time_t last_write_time(const path& p, system::error_code* ec=0); | |
112 | BOOST_FILESYSTEM_DECL | |
113 | void last_write_time(const path& p, const std::time_t new_time, | |
114 | system::error_code* ec=0); | |
115 | BOOST_FILESYSTEM_DECL | |
116 | void permissions(const path& p, perms prms, system::error_code* ec=0); | |
117 | BOOST_FILESYSTEM_DECL | |
118 | path read_symlink(const path& p, system::error_code* ec=0); | |
119 | BOOST_FILESYSTEM_DECL | |
120 | path relative(const path& p, const path& base, system::error_code* ec = 0); | |
121 | BOOST_FILESYSTEM_DECL | |
122 | bool remove(const path& p, system::error_code* ec=0); | |
123 | BOOST_FILESYSTEM_DECL | |
124 | boost::uintmax_t remove_all(const path& p, system::error_code* ec=0); | |
125 | BOOST_FILESYSTEM_DECL | |
126 | void rename(const path& old_p, const path& new_p, system::error_code* ec=0); | |
127 | BOOST_FILESYSTEM_DECL | |
128 | void resize_file(const path& p, uintmax_t size, system::error_code* ec=0); | |
129 | BOOST_FILESYSTEM_DECL | |
130 | space_info space(const path& p, system::error_code* ec=0); | |
131 | BOOST_FILESYSTEM_DECL | |
132 | path system_complete(const path& p, system::error_code* ec=0); | |
133 | BOOST_FILESYSTEM_DECL | |
134 | path temp_directory_path(system::error_code* ec=0); | |
135 | BOOST_FILESYSTEM_DECL | |
136 | path unique_path(const path& p, system::error_code* ec=0); | |
137 | BOOST_FILESYSTEM_DECL | |
138 | path weakly_canonical(const path& p, system::error_code* ec = 0); | |
139 | ||
140 | } // namespace detail | |
7c673cae FG |
141 | |
142 | //--------------------------------------------------------------------------------------// | |
143 | // // | |
144 | // status query functions // | |
145 | // // | |
146 | //--------------------------------------------------------------------------------------// | |
147 | ||
92f5a8d4 TL |
148 | inline |
149 | file_status status(const path& p) {return detail::status(p);} | |
150 | inline | |
151 | file_status status(const path& p, system::error_code& ec) | |
152 | {return detail::status(p, &ec);} | |
153 | inline | |
154 | file_status symlink_status(const path& p) {return detail::symlink_status(p);} | |
155 | inline | |
156 | file_status symlink_status(const path& p, system::error_code& ec) | |
157 | {return detail::symlink_status(p, &ec);} | |
158 | inline | |
159 | bool exists(const path& p) {return exists(detail::status(p));} | |
160 | inline | |
161 | bool exists(const path& p, system::error_code& ec) | |
162 | {return exists(detail::status(p, &ec));} | |
163 | inline | |
164 | bool is_directory(const path& p) {return is_directory(detail::status(p));} | |
165 | inline | |
166 | bool is_directory(const path& p, system::error_code& ec) | |
167 | {return is_directory(detail::status(p, &ec));} | |
168 | inline | |
169 | bool is_regular_file(const path& p) {return is_regular_file(detail::status(p));} | |
170 | inline | |
171 | bool is_regular_file(const path& p, system::error_code& ec) | |
172 | {return is_regular_file(detail::status(p, &ec));} | |
173 | inline | |
174 | bool is_other(const path& p) {return is_other(detail::status(p));} | |
175 | inline | |
176 | bool is_other(const path& p, system::error_code& ec) | |
177 | {return is_other(detail::status(p, &ec));} | |
178 | inline | |
179 | bool is_symlink(const path& p) {return is_symlink(detail::symlink_status(p));} | |
180 | inline | |
181 | bool is_symlink(const path& p, system::error_code& ec) | |
182 | {return is_symlink(detail::symlink_status(p, &ec));} | |
183 | #ifndef BOOST_FILESYSTEM_NO_DEPRECATED | |
184 | inline | |
185 | bool is_regular(const path& p) {return is_regular(detail::status(p));} | |
186 | inline | |
187 | bool is_regular(const path& p, system::error_code& ec) | |
188 | {return is_regular(detail::status(p, &ec));} | |
189 | #endif | |
7c673cae | 190 | |
92f5a8d4 TL |
191 | inline |
192 | bool is_empty(const path& p) {return detail::is_empty(p);} | |
193 | inline | |
194 | bool is_empty(const path& p, system::error_code& ec) | |
195 | {return detail::is_empty(p, &ec);} | |
7c673cae FG |
196 | |
197 | //--------------------------------------------------------------------------------------// | |
198 | // // | |
199 | // operational functions // | |
200 | // in alphabetical order, unless otherwise noted // | |
201 | // // | |
7c673cae FG |
202 | //--------------------------------------------------------------------------------------// |
203 | ||
92f5a8d4 TL |
204 | // forward declarations |
205 | path current_path(); // fwd declaration | |
206 | path initial_path(); | |
207 | ||
208 | BOOST_FILESYSTEM_DECL | |
209 | path absolute(const path& p, const path& base=current_path()); | |
210 | // If base.is_absolute(), throws nothing. Thus no need for ec argument | |
211 | ||
212 | inline | |
213 | path canonical(const path& p, const path& base=current_path()) | |
214 | {return detail::canonical(p, base);} | |
215 | inline | |
216 | path canonical(const path& p, system::error_code& ec) | |
217 | {return detail::canonical(p, current_path(), &ec);} | |
218 | inline | |
219 | path canonical(const path& p, const path& base, system::error_code& ec) | |
220 | {return detail::canonical(p, base, &ec);} | |
221 | ||
222 | #ifndef BOOST_FILESYSTEM_NO_DEPRECATED | |
223 | inline | |
224 | path complete(const path& p) | |
225 | { | |
226 | return absolute(p, initial_path()); | |
227 | } | |
7c673cae | 228 | |
92f5a8d4 TL |
229 | inline |
230 | path complete(const path& p, const path& base) | |
7c673cae | 231 | { |
92f5a8d4 TL |
232 | return absolute(p, base); |
233 | } | |
7c673cae FG |
234 | #endif |
235 | ||
92f5a8d4 TL |
236 | inline |
237 | void copy(const path& from, const path& to) {detail::copy(from, to);} | |
238 | ||
239 | inline | |
240 | void copy(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT | |
241 | {detail::copy(from, to, &ec);} | |
242 | inline | |
243 | void copy_directory(const path& from, const path& to) | |
244 | {detail::copy_directory(from, to);} | |
245 | inline | |
246 | void copy_directory(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT | |
247 | {detail::copy_directory(from, to, &ec);} | |
248 | inline | |
249 | void copy_file(const path& from, const path& to, // See ticket #2925 | |
250 | BOOST_SCOPED_ENUM_NATIVE(copy_option) option) | |
7c673cae | 251 | { |
92f5a8d4 TL |
252 | detail::copy_file(from, to, static_cast<detail::copy_option>(option)); |
253 | } | |
254 | inline | |
255 | void copy_file(const path& from, const path& to) | |
7c673cae | 256 | { |
92f5a8d4 TL |
257 | detail::copy_file(from, to, detail::fail_if_exists); |
258 | } | |
259 | inline | |
260 | void copy_file(const path& from, const path& to, // See ticket #2925 | |
261 | BOOST_SCOPED_ENUM_NATIVE(copy_option) option, system::error_code& ec) BOOST_NOEXCEPT | |
7c673cae | 262 | { |
92f5a8d4 TL |
263 | detail::copy_file(from, to, static_cast<detail::copy_option>(option), &ec); |
264 | } | |
265 | inline | |
266 | void copy_file(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT | |
267 | { | |
268 | detail::copy_file(from, to, detail::fail_if_exists, &ec); | |
269 | } | |
270 | inline | |
271 | void copy_symlink(const path& existing_symlink, | |
272 | const path& new_symlink) {detail::copy_symlink(existing_symlink, new_symlink);} | |
273 | ||
274 | inline | |
275 | void copy_symlink(const path& existing_symlink, const path& new_symlink, | |
276 | system::error_code& ec) BOOST_NOEXCEPT | |
277 | {detail::copy_symlink(existing_symlink, new_symlink, &ec);} | |
278 | inline | |
279 | bool create_directories(const path& p) {return detail::create_directories(p);} | |
280 | ||
281 | inline | |
282 | bool create_directories(const path& p, system::error_code& ec) BOOST_NOEXCEPT | |
283 | {return detail::create_directories(p, &ec);} | |
284 | inline | |
285 | bool create_directory(const path& p) {return detail::create_directory(p);} | |
286 | ||
287 | inline | |
288 | bool create_directory(const path& p, system::error_code& ec) BOOST_NOEXCEPT | |
289 | {return detail::create_directory(p, &ec);} | |
290 | inline | |
291 | void create_directory_symlink(const path& to, const path& from) | |
292 | {detail::create_directory_symlink(to, from);} | |
293 | inline | |
294 | void create_directory_symlink(const path& to, const path& from, system::error_code& ec) BOOST_NOEXCEPT | |
295 | {detail::create_directory_symlink(to, from, &ec);} | |
296 | inline | |
297 | void create_hard_link(const path& to, const path& new_hard_link) {detail::create_hard_link(to, new_hard_link);} | |
298 | ||
299 | inline | |
300 | void create_hard_link(const path& to, const path& new_hard_link, system::error_code& ec) BOOST_NOEXCEPT | |
301 | {detail::create_hard_link(to, new_hard_link, &ec);} | |
302 | inline | |
303 | void create_symlink(const path& to, const path& new_symlink) {detail::create_symlink(to, new_symlink);} | |
304 | ||
305 | inline | |
306 | void create_symlink(const path& to, const path& new_symlink, system::error_code& ec) BOOST_NOEXCEPT | |
307 | {detail::create_symlink(to, new_symlink, &ec);} | |
308 | inline | |
309 | path current_path() {return detail::current_path();} | |
310 | ||
311 | inline | |
312 | path current_path(system::error_code& ec) {return detail::current_path(&ec);} | |
313 | ||
314 | inline | |
315 | void current_path(const path& p) {detail::current_path(p);} | |
316 | ||
317 | inline | |
318 | void current_path(const path& p, system::error_code& ec) BOOST_NOEXCEPT {detail::current_path(p, &ec);} | |
319 | ||
320 | inline | |
321 | bool equivalent(const path& p1, const path& p2) {return detail::equivalent(p1, p2);} | |
322 | ||
323 | inline | |
324 | bool equivalent(const path& p1, const path& p2, system::error_code& ec) BOOST_NOEXCEPT | |
325 | {return detail::equivalent(p1, p2, &ec);} | |
326 | inline | |
327 | boost::uintmax_t file_size(const path& p) {return detail::file_size(p);} | |
328 | ||
329 | inline | |
330 | boost::uintmax_t file_size(const path& p, system::error_code& ec) BOOST_NOEXCEPT | |
331 | {return detail::file_size(p, &ec);} | |
332 | inline | |
333 | boost::uintmax_t hard_link_count(const path& p) {return detail::hard_link_count(p);} | |
334 | ||
335 | inline | |
336 | boost::uintmax_t hard_link_count(const path& p, system::error_code& ec) BOOST_NOEXCEPT | |
337 | {return detail::hard_link_count(p, &ec);} | |
338 | inline | |
339 | path initial_path() {return detail::initial_path();} | |
340 | ||
341 | inline | |
342 | path initial_path(system::error_code& ec) {return detail::initial_path(&ec);} | |
343 | ||
344 | template <class Path> | |
345 | path initial_path() {return initial_path();} | |
346 | template <class Path> | |
347 | path initial_path(system::error_code& ec) {return detail::initial_path(&ec);} | |
348 | ||
349 | inline | |
350 | std::time_t last_write_time(const path& p) {return detail::last_write_time(p);} | |
351 | ||
352 | inline | |
353 | std::time_t last_write_time(const path& p, system::error_code& ec) BOOST_NOEXCEPT | |
354 | {return detail::last_write_time(p, &ec);} | |
355 | inline | |
356 | void last_write_time(const path& p, const std::time_t new_time) | |
357 | {detail::last_write_time(p, new_time);} | |
358 | inline | |
359 | void last_write_time(const path& p, const std::time_t new_time, | |
360 | system::error_code& ec) BOOST_NOEXCEPT | |
361 | {detail::last_write_time(p, new_time, &ec);} | |
362 | inline | |
363 | void permissions(const path& p, perms prms) | |
364 | {detail::permissions(p, prms);} | |
365 | inline | |
366 | void permissions(const path& p, perms prms, system::error_code& ec) BOOST_NOEXCEPT | |
367 | {detail::permissions(p, prms, &ec);} | |
368 | ||
369 | inline | |
370 | path read_symlink(const path& p) {return detail::read_symlink(p);} | |
371 | ||
372 | inline | |
373 | path read_symlink(const path& p, system::error_code& ec) | |
374 | {return detail::read_symlink(p, &ec);} | |
375 | ||
376 | inline | |
377 | bool remove(const path& p) {return detail::remove(p);} | |
378 | ||
379 | inline | |
380 | bool remove(const path& p, system::error_code& ec) BOOST_NOEXCEPT | |
381 | {return detail::remove(p, &ec);} | |
382 | ||
383 | inline | |
384 | boost::uintmax_t remove_all(const path& p) {return detail::remove_all(p);} | |
385 | ||
386 | inline | |
387 | boost::uintmax_t remove_all(const path& p, system::error_code& ec) BOOST_NOEXCEPT | |
388 | {return detail::remove_all(p, &ec);} | |
389 | inline | |
390 | void rename(const path& old_p, const path& new_p) {detail::rename(old_p, new_p);} | |
391 | ||
392 | inline | |
393 | void rename(const path& old_p, const path& new_p, system::error_code& ec) BOOST_NOEXCEPT | |
394 | {detail::rename(old_p, new_p, &ec);} | |
395 | inline // name suggested by Scott McMurray | |
396 | void resize_file(const path& p, uintmax_t size) {detail::resize_file(p, size);} | |
397 | ||
398 | inline | |
399 | void resize_file(const path& p, uintmax_t size, system::error_code& ec) BOOST_NOEXCEPT | |
400 | {detail::resize_file(p, size, &ec);} | |
401 | inline | |
402 | path relative(const path& p, const path& base=current_path()) | |
403 | {return detail::relative(p, base);} | |
404 | inline | |
405 | path relative(const path& p, system::error_code& ec) | |
406 | {return detail::relative(p, current_path(), &ec);} | |
407 | inline | |
408 | path relative(const path& p, const path& base, system::error_code& ec) | |
409 | {return detail::relative(p, base, &ec);} | |
410 | inline | |
411 | space_info space(const path& p) {return detail::space(p);} | |
412 | ||
413 | inline | |
414 | space_info space(const path& p, system::error_code& ec) BOOST_NOEXCEPT | |
415 | {return detail::space(p, &ec);} | |
416 | ||
417 | #ifndef BOOST_FILESYSTEM_NO_DEPRECATED | |
418 | inline bool symbolic_link_exists(const path& p) | |
419 | { return is_symlink(filesystem::symlink_status(p)); } | |
420 | #endif | |
7c673cae | 421 | |
92f5a8d4 TL |
422 | inline |
423 | path system_complete(const path& p) {return detail::system_complete(p);} | |
424 | ||
425 | inline | |
426 | path system_complete(const path& p, system::error_code& ec) | |
427 | {return detail::system_complete(p, &ec);} | |
428 | inline | |
429 | path temp_directory_path() {return detail::temp_directory_path();} | |
430 | ||
431 | inline | |
432 | path temp_directory_path(system::error_code& ec) | |
433 | {return detail::temp_directory_path(&ec);} | |
434 | inline | |
435 | path unique_path(const path& p="%%%%-%%%%-%%%%-%%%%") | |
436 | {return detail::unique_path(p);} | |
437 | inline | |
438 | path unique_path(const path& p, system::error_code& ec) | |
439 | {return detail::unique_path(p, &ec);} | |
440 | inline | |
441 | path weakly_canonical(const path& p) {return detail::weakly_canonical(p);} | |
442 | ||
443 | inline | |
444 | path weakly_canonical(const path& p, system::error_code& ec) | |
445 | {return detail::weakly_canonical(p, &ec);} | |
7c673cae FG |
446 | |
447 | // test helper -----------------------------------------------------------------------// | |
448 | ||
449 | // Not part of the documented interface since false positives are possible; | |
450 | // there is no law that says that an OS that has large stat.st_size | |
451 | // actually supports large file sizes. | |
452 | ||
92f5a8d4 TL |
453 | namespace detail { |
454 | ||
455 | BOOST_FILESYSTEM_DECL bool possible_large_file_size_support(); | |
456 | ||
457 | } // namespace detail | |
7c673cae | 458 | |
92f5a8d4 | 459 | } // namespace filesystem |
7c673cae FG |
460 | } // namespace boost |
461 | ||
462 | #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas | |
463 | #endif // BOOST_FILESYSTEM3_OPERATIONS_HPP |