]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/filesystem/operations.hpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / boost / filesystem / operations.hpp
1 // boost/filesystem/operations.hpp ---------------------------------------------------//
2
3 // Copyright Beman Dawes 2002-2009
4 // Copyright Jan Langer 2002
5 // Copyright Dietmar Kuehl 2001
6 // Copyright Vladimir Prus 2002
7 // Copyright Andrey Semashev 2020-2021
8
9 // Distributed under the Boost Software License, Version 1.0.
10 // See http://www.boost.org/LICENSE_1_0.txt
11
12 // Library home page: http://www.boost.org/libs/filesystem
13
14 //--------------------------------------------------------------------------------------//
15
16 #ifndef BOOST_FILESYSTEM_OPERATIONS_HPP
17 #define BOOST_FILESYSTEM_OPERATIONS_HPP
18
19 #include <boost/filesystem/config.hpp>
20 #include <boost/filesystem/path.hpp>
21 #include <boost/filesystem/file_status.hpp>
22
23 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
24 // These includes are left for backward compatibility and should be included directly by users, as needed
25 #include <boost/filesystem/exception.hpp>
26 #include <boost/filesystem/directory.hpp>
27 #endif
28
29 #include <boost/detail/bitmask.hpp>
30 #include <boost/core/scoped_enum.hpp>
31 #include <boost/system/error_code.hpp>
32 #include <boost/cstdint.hpp>
33 #include <string>
34 #include <ctime>
35
36 #include <boost/filesystem/detail/header.hpp> // must be the last #include
37
38 //--------------------------------------------------------------------------------------//
39
40 namespace boost {
41 namespace filesystem {
42
43 struct space_info
44 {
45 // all values are byte counts
46 boost::uintmax_t capacity;
47 boost::uintmax_t free; // <= capacity
48 boost::uintmax_t available; // <= free
49 };
50
51 BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(copy_options, unsigned int)
52 {
53 none = 0u, // Default. For copy_file: error if the target file exists. For copy: do not recurse, follow symlinks, copy file contents.
54
55 // copy_file options:
56 skip_existing = 1u, // Don't overwrite the existing target file, don't report an error
57 overwrite_existing = 1u << 1, // Overwrite existing file
58 update_existing = 1u << 2, // Overwrite existing file if its last write time is older than the replacement file
59 synchronize_data = 1u << 3, // Flush all buffered data written to the target file to permanent storage
60 synchronize = 1u << 4, // Flush all buffered data and attributes written to the target file to permanent storage
61
62 // copy options:
63 recursive = 1u << 8, // Recurse into sub-directories
64 copy_symlinks = 1u << 9, // Copy symlinks as symlinks instead of copying the referenced file
65 skip_symlinks = 1u << 10, // Don't copy symlinks
66 directories_only = 1u << 11, // Only copy directory structure, do not copy non-directory files
67 create_symlinks = 1u << 12, // Create symlinks instead of copying files
68 create_hard_links = 1u << 13, // Create hard links instead of copying files
69 _detail_recursing = 1u << 14 // Internal use only, do not use
70 }
71 BOOST_SCOPED_ENUM_DECLARE_END(copy_options)
72
73 BOOST_BITMASK(BOOST_SCOPED_ENUM_NATIVE(copy_options))
74
75 #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
76 BOOST_SCOPED_ENUM_DECLARE_BEGIN(copy_option)
77 {
78 none = static_cast< unsigned int >(copy_options::none),
79 fail_if_exists = none,
80 overwrite_if_exists = static_cast< unsigned int >(copy_options::overwrite_existing)
81 }
82 BOOST_SCOPED_ENUM_DECLARE_END(copy_option)
83 #endif
84
85 //--------------------------------------------------------------------------------------//
86 // implementation details //
87 //--------------------------------------------------------------------------------------//
88
89 namespace detail {
90
91 BOOST_FILESYSTEM_DECL
92 path absolute(path const& p, path const& base, system::error_code* ec = 0);
93 BOOST_FILESYSTEM_DECL
94 file_status status(path const& p, system::error_code* ec = 0);
95 BOOST_FILESYSTEM_DECL
96 file_status symlink_status(path const& p, system::error_code* ec = 0);
97 BOOST_FILESYSTEM_DECL
98 bool is_empty(path const& p, system::error_code* ec = 0);
99 BOOST_FILESYSTEM_DECL
100 path initial_path(system::error_code* ec = 0);
101 BOOST_FILESYSTEM_DECL
102 path canonical(path const& p, path const& base, system::error_code* ec = 0);
103 BOOST_FILESYSTEM_DECL
104 void copy(path const& from, path const& to, unsigned int options, system::error_code* ec = 0);
105 #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
106 BOOST_FILESYSTEM_DECL
107 void copy_directory(path const& from, path const& to, system::error_code* ec = 0);
108 #endif
109 BOOST_FILESYSTEM_DECL
110 bool copy_file(path const& from, path const& to, // See ticket #2925
111 unsigned int options, system::error_code* ec = 0); // see copy_options for options
112 BOOST_FILESYSTEM_DECL
113 void copy_symlink(path const& existing_symlink, path const& new_symlink, system::error_code* ec = 0);
114 BOOST_FILESYSTEM_DECL
115 bool create_directories(path const& p, system::error_code* ec = 0);
116 BOOST_FILESYSTEM_DECL
117 bool create_directory(path const& p, const path* existing, system::error_code* ec = 0);
118 BOOST_FILESYSTEM_DECL
119 void create_directory_symlink(path const& to, path const& from, system::error_code* ec = 0);
120 BOOST_FILESYSTEM_DECL
121 void create_hard_link(path const& to, path const& from, system::error_code* ec = 0);
122 BOOST_FILESYSTEM_DECL
123 void create_symlink(path const& to, path const& from, system::error_code* ec = 0);
124 BOOST_FILESYSTEM_DECL
125 path current_path(system::error_code* ec = 0);
126 BOOST_FILESYSTEM_DECL
127 void current_path(path const& p, system::error_code* ec = 0);
128 BOOST_FILESYSTEM_DECL
129 bool equivalent(path const& p1, path const& p2, system::error_code* ec = 0);
130 BOOST_FILESYSTEM_DECL
131 boost::uintmax_t file_size(path const& p, system::error_code* ec = 0);
132 BOOST_FILESYSTEM_DECL
133 boost::uintmax_t hard_link_count(path const& p, system::error_code* ec = 0);
134 BOOST_FILESYSTEM_DECL
135 std::time_t creation_time(path const& p, system::error_code* ec = 0);
136 BOOST_FILESYSTEM_DECL
137 std::time_t last_write_time(path const& p, system::error_code* ec = 0);
138 BOOST_FILESYSTEM_DECL
139 void last_write_time(path const& p, const std::time_t new_time, system::error_code* ec = 0);
140 BOOST_FILESYSTEM_DECL
141 void permissions(path const& p, perms prms, system::error_code* ec = 0);
142 BOOST_FILESYSTEM_DECL
143 path read_symlink(path const& p, system::error_code* ec = 0);
144 BOOST_FILESYSTEM_DECL
145 path relative(path const& p, path const& base, system::error_code* ec = 0);
146 BOOST_FILESYSTEM_DECL
147 bool remove(path const& p, system::error_code* ec = 0);
148 BOOST_FILESYSTEM_DECL
149 boost::uintmax_t remove_all(path const& p, system::error_code* ec = 0);
150 BOOST_FILESYSTEM_DECL
151 void rename(path const& old_p, path const& new_p, system::error_code* ec = 0);
152 BOOST_FILESYSTEM_DECL
153 void resize_file(path const& p, uintmax_t size, system::error_code* ec = 0);
154 BOOST_FILESYSTEM_DECL
155 space_info space(path const& p, system::error_code* ec = 0);
156 BOOST_FILESYSTEM_DECL
157 path system_complete(path const& p, system::error_code* ec = 0);
158 BOOST_FILESYSTEM_DECL
159 path temp_directory_path(system::error_code* ec = 0);
160 BOOST_FILESYSTEM_DECL
161 path unique_path(path const& p, system::error_code* ec = 0);
162 BOOST_FILESYSTEM_DECL
163 path weakly_canonical(path const& p, path const& base, system::error_code* ec = 0);
164
165 } // namespace detail
166
167 //--------------------------------------------------------------------------------------//
168 // //
169 // status query functions //
170 // //
171 //--------------------------------------------------------------------------------------//
172
173 inline file_status status(path const& p)
174 {
175 return detail::status(p);
176 }
177
178 inline file_status status(path const& p, system::error_code& ec)
179 {
180 return detail::status(p, &ec);
181 }
182
183 inline file_status symlink_status(path const& p)
184 {
185 return detail::symlink_status(p);
186 }
187
188 inline file_status symlink_status(path const& p, system::error_code& ec)
189 {
190 return detail::symlink_status(p, &ec);
191 }
192
193 inline bool exists(path const& p)
194 {
195 return exists(detail::status(p));
196 }
197
198 inline bool exists(path const& p, system::error_code& ec)
199 {
200 return exists(detail::status(p, &ec));
201 }
202
203 inline bool is_directory(path const& p)
204 {
205 return is_directory(detail::status(p));
206 }
207
208 inline bool is_directory(path const& p, system::error_code& ec)
209 {
210 return is_directory(detail::status(p, &ec));
211 }
212
213 inline bool is_regular_file(path const& p)
214 {
215 return is_regular_file(detail::status(p));
216 }
217
218 inline bool is_regular_file(path const& p, system::error_code& ec)
219 {
220 return is_regular_file(detail::status(p, &ec));
221 }
222
223 inline bool is_other(path const& p)
224 {
225 return is_other(detail::status(p));
226 }
227
228 inline bool is_other(path const& p, system::error_code& ec)
229 {
230 return is_other(detail::status(p, &ec));
231 }
232
233 inline bool is_symlink(path const& p)
234 {
235 return is_symlink(detail::symlink_status(p));
236 }
237
238 inline bool is_symlink(path const& p, system::error_code& ec)
239 {
240 return is_symlink(detail::symlink_status(p, &ec));
241 }
242
243 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
244 inline bool is_regular(path const& p)
245 {
246 return is_regular(detail::status(p));
247 }
248
249 inline bool is_regular(path const& p, system::error_code& ec)
250 {
251 return is_regular(detail::status(p, &ec));
252 }
253 #endif
254
255 inline bool is_empty(path const& p)
256 {
257 return detail::is_empty(p);
258 }
259
260 inline bool is_empty(path const& p, system::error_code& ec)
261 {
262 return detail::is_empty(p, &ec);
263 }
264
265 //--------------------------------------------------------------------------------------//
266 // //
267 // operational functions //
268 // //
269 //--------------------------------------------------------------------------------------//
270
271 inline path initial_path()
272 {
273 return detail::initial_path();
274 }
275
276 inline path initial_path(system::error_code& ec)
277 {
278 return detail::initial_path(&ec);
279 }
280
281 template< class Path >
282 path initial_path()
283 {
284 return initial_path();
285 }
286 template< class Path >
287 path initial_path(system::error_code& ec)
288 {
289 return detail::initial_path(&ec);
290 }
291
292 inline path current_path()
293 {
294 return detail::current_path();
295 }
296
297 inline path current_path(system::error_code& ec)
298 {
299 return detail::current_path(&ec);
300 }
301
302 inline void current_path(path const& p)
303 {
304 detail::current_path(p);
305 }
306
307 inline void current_path(path const& p, system::error_code& ec) BOOST_NOEXCEPT
308 {
309 detail::current_path(p, &ec);
310 }
311
312 inline path absolute(path const& p, path const& base = current_path())
313 {
314 return detail::absolute(p, base);
315 }
316
317 inline path absolute(path const& p, system::error_code& ec)
318 {
319 path base = current_path(ec);
320 if (ec)
321 return path();
322 return detail::absolute(p, base, &ec);
323 }
324
325 inline path absolute(path const& p, path const& base, system::error_code& ec)
326 {
327 return detail::absolute(p, base, &ec);
328 }
329
330 inline path canonical(path const& p, path const& base = current_path())
331 {
332 return detail::canonical(p, base);
333 }
334
335 inline path canonical(path const& p, system::error_code& ec)
336 {
337 path base = current_path(ec);
338 if (ec)
339 return path();
340 return detail::canonical(p, base, &ec);
341 }
342
343 inline path canonical(path const& p, path const& base, system::error_code& ec)
344 {
345 return detail::canonical(p, base, &ec);
346 }
347
348 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
349 inline path complete(path const& p)
350 {
351 return absolute(p, initial_path());
352 }
353
354 inline path complete(path const& p, path const& base)
355 {
356 return absolute(p, base);
357 }
358 #endif
359
360 inline void copy(path const& from, path const& to)
361 {
362 detail::copy(from, to, static_cast< unsigned int >(copy_options::none));
363 }
364
365 inline void copy(path const& from, path const& to, system::error_code& ec) BOOST_NOEXCEPT
366 {
367 detail::copy(from, to, static_cast< unsigned int >(copy_options::none), &ec);
368 }
369
370 inline void copy(path const& from, path const& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options)
371 {
372 detail::copy(from, to, static_cast< unsigned int >(options));
373 }
374
375 inline void copy(path const& from, path const& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT
376 {
377 detail::copy(from, to, static_cast< unsigned int >(options), &ec);
378 }
379
380 #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
381 inline void copy_directory(path const& from, path const& to)
382 {
383 detail::copy_directory(from, to);
384 }
385
386 inline void copy_directory(path const& from, path const& to, system::error_code& ec) BOOST_NOEXCEPT
387 {
388 detail::copy_directory(from, to, &ec);
389 }
390 #endif
391
392 inline bool copy_file(path const& from, path const& to)
393 {
394 return detail::copy_file(from, to, static_cast< unsigned int >(copy_options::none));
395 }
396
397 inline bool copy_file(path const& from, path const& to, system::error_code& ec) BOOST_NOEXCEPT
398 {
399 return detail::copy_file(from, to, static_cast< unsigned int >(copy_options::none), &ec);
400 }
401
402 inline bool copy_file(path const& from, path const& to, // See ticket #2925
403 BOOST_SCOPED_ENUM_NATIVE(copy_options) options)
404 {
405 return detail::copy_file(from, to, static_cast< unsigned int >(options));
406 }
407
408 inline bool copy_file(path const& from, path const& to, // See ticket #2925
409 BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT
410 {
411 return detail::copy_file(from, to, static_cast< unsigned int >(options), &ec);
412 }
413
414 #if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
415 inline bool copy_file(path const& from, path const& to, // See ticket #2925
416 BOOST_SCOPED_ENUM_NATIVE(copy_option) options)
417 {
418 return detail::copy_file(from, to, static_cast< unsigned int >(options));
419 }
420
421 inline bool copy_file(path const& from, path const& to, // See ticket #2925
422 BOOST_SCOPED_ENUM_NATIVE(copy_option) options, system::error_code& ec) BOOST_NOEXCEPT
423 {
424 return detail::copy_file(from, to, static_cast< unsigned int >(options), &ec);
425 }
426 #endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
427
428 inline void copy_symlink(path const& existing_symlink, path const& new_symlink)
429 {
430 detail::copy_symlink(existing_symlink, new_symlink);
431 }
432
433 inline void copy_symlink(path const& existing_symlink, path const& new_symlink, system::error_code& ec) BOOST_NOEXCEPT
434 {
435 detail::copy_symlink(existing_symlink, new_symlink, &ec);
436 }
437
438 inline bool create_directories(path const& p)
439 {
440 return detail::create_directories(p);
441 }
442
443 inline bool create_directories(path const& p, system::error_code& ec) BOOST_NOEXCEPT
444 {
445 return detail::create_directories(p, &ec);
446 }
447
448 inline bool create_directory(path const& p)
449 {
450 return detail::create_directory(p, 0);
451 }
452
453 inline bool create_directory(path const& p, system::error_code& ec) BOOST_NOEXCEPT
454 {
455 return detail::create_directory(p, 0, &ec);
456 }
457
458 inline bool create_directory(path const& p, path const& existing)
459 {
460 return detail::create_directory(p, &existing);
461 }
462
463 inline bool create_directory(path const& p, path const& existing, system::error_code& ec) BOOST_NOEXCEPT
464 {
465 return detail::create_directory(p, &existing, &ec);
466 }
467
468 inline void create_directory_symlink(path const& to, path const& from)
469 {
470 detail::create_directory_symlink(to, from);
471 }
472
473 inline void create_directory_symlink(path const& to, path const& from, system::error_code& ec) BOOST_NOEXCEPT
474 {
475 detail::create_directory_symlink(to, from, &ec);
476 }
477
478 inline void create_hard_link(path const& to, path const& new_hard_link)
479 {
480 detail::create_hard_link(to, new_hard_link);
481 }
482
483 inline void create_hard_link(path const& to, path const& new_hard_link, system::error_code& ec) BOOST_NOEXCEPT
484 {
485 detail::create_hard_link(to, new_hard_link, &ec);
486 }
487
488 inline void create_symlink(path const& to, path const& new_symlink)
489 {
490 detail::create_symlink(to, new_symlink);
491 }
492
493 inline void create_symlink(path const& to, path const& new_symlink, system::error_code& ec) BOOST_NOEXCEPT
494 {
495 detail::create_symlink(to, new_symlink, &ec);
496 }
497
498 inline bool equivalent(path const& p1, path const& p2)
499 {
500 return detail::equivalent(p1, p2);
501 }
502
503 inline bool equivalent(path const& p1, path const& p2, system::error_code& ec) BOOST_NOEXCEPT
504 {
505 return detail::equivalent(p1, p2, &ec);
506 }
507
508 inline boost::uintmax_t file_size(path const& p)
509 {
510 return detail::file_size(p);
511 }
512
513 inline boost::uintmax_t file_size(path const& p, system::error_code& ec) BOOST_NOEXCEPT
514 {
515 return detail::file_size(p, &ec);
516 }
517
518 inline boost::uintmax_t hard_link_count(path const& p)
519 {
520 return detail::hard_link_count(p);
521 }
522
523 inline boost::uintmax_t hard_link_count(path const& p, system::error_code& ec) BOOST_NOEXCEPT
524 {
525 return detail::hard_link_count(p, &ec);
526 }
527
528 inline std::time_t creation_time(path const& p)
529 {
530 return detail::creation_time(p);
531 }
532
533 inline std::time_t creation_time(path const& p, system::error_code& ec) BOOST_NOEXCEPT
534 {
535 return detail::creation_time(p, &ec);
536 }
537
538 inline std::time_t last_write_time(path const& p)
539 {
540 return detail::last_write_time(p);
541 }
542
543 inline std::time_t last_write_time(path const& p, system::error_code& ec) BOOST_NOEXCEPT
544 {
545 return detail::last_write_time(p, &ec);
546 }
547
548 inline void last_write_time(path const& p, const std::time_t new_time)
549 {
550 detail::last_write_time(p, new_time);
551 }
552
553 inline void last_write_time(path const& p, const std::time_t new_time, system::error_code& ec) BOOST_NOEXCEPT
554 {
555 detail::last_write_time(p, new_time, &ec);
556 }
557
558 inline void permissions(path const& p, perms prms)
559 {
560 detail::permissions(p, prms);
561 }
562
563 inline void permissions(path const& p, perms prms, system::error_code& ec) BOOST_NOEXCEPT
564 {
565 detail::permissions(p, prms, &ec);
566 }
567
568 inline path read_symlink(path const& p)
569 {
570 return detail::read_symlink(p);
571 }
572
573 inline path read_symlink(path const& p, system::error_code& ec)
574 {
575 return detail::read_symlink(p, &ec);
576 }
577
578 inline bool remove(path const& p)
579 {
580 return detail::remove(p);
581 }
582
583 inline bool remove(path const& p, system::error_code& ec) BOOST_NOEXCEPT
584 {
585 return detail::remove(p, &ec);
586 }
587
588 inline boost::uintmax_t remove_all(path const& p)
589 {
590 return detail::remove_all(p);
591 }
592
593 inline boost::uintmax_t remove_all(path const& p, system::error_code& ec) BOOST_NOEXCEPT
594 {
595 return detail::remove_all(p, &ec);
596 }
597
598 inline void rename(path const& old_p, path const& new_p)
599 {
600 detail::rename(old_p, new_p);
601 }
602
603 inline void rename(path const& old_p, path const& new_p, system::error_code& ec) BOOST_NOEXCEPT
604 {
605 detail::rename(old_p, new_p, &ec);
606 }
607
608 // name suggested by Scott McMurray
609 inline void resize_file(path const& p, uintmax_t size)
610 {
611 detail::resize_file(p, size);
612 }
613
614 inline void resize_file(path const& p, uintmax_t size, system::error_code& ec) BOOST_NOEXCEPT
615 {
616 detail::resize_file(p, size, &ec);
617 }
618
619 inline path relative(path const& p, path const& base = current_path())
620 {
621 return detail::relative(p, base);
622 }
623
624 inline path relative(path const& p, system::error_code& ec)
625 {
626 path base = current_path(ec);
627 if (ec)
628 return path();
629 return detail::relative(p, base, &ec);
630 }
631
632 inline path relative(path const& p, path const& base, system::error_code& ec)
633 {
634 return detail::relative(p, base, &ec);
635 }
636
637 inline space_info space(path const& p)
638 {
639 return detail::space(p);
640 }
641
642 inline space_info space(path const& p, system::error_code& ec) BOOST_NOEXCEPT
643 {
644 return detail::space(p, &ec);
645 }
646
647 #ifndef BOOST_FILESYSTEM_NO_DEPRECATED
648 inline bool symbolic_link_exists(path const& p)
649 {
650 return is_symlink(filesystem::symlink_status(p));
651 }
652 #endif
653
654 inline path system_complete(path const& p)
655 {
656 return detail::system_complete(p);
657 }
658
659 inline path system_complete(path const& p, system::error_code& ec)
660 {
661 return detail::system_complete(p, &ec);
662 }
663
664 inline path temp_directory_path()
665 {
666 return detail::temp_directory_path();
667 }
668
669 inline path temp_directory_path(system::error_code& ec)
670 {
671 return detail::temp_directory_path(&ec);
672 }
673
674 inline path unique_path(path const& p = "%%%%-%%%%-%%%%-%%%%")
675 {
676 return detail::unique_path(p);
677 }
678
679 inline path unique_path(path const& p, system::error_code& ec)
680 {
681 return detail::unique_path(p, &ec);
682 }
683
684 inline path weakly_canonical(path const& p, path const& base = current_path())
685 {
686 return detail::weakly_canonical(p, base);
687 }
688
689 inline path weakly_canonical(path const& p, system::error_code& ec)
690 {
691 path base = current_path(ec);
692 if (ec)
693 return path();
694 return detail::weakly_canonical(p, base, &ec);
695 }
696
697 inline path weakly_canonical(path const& p, path const& base, system::error_code& ec)
698 {
699 return detail::weakly_canonical(p, base, &ec);
700 }
701
702 // test helper -----------------------------------------------------------------------//
703
704 // Not part of the documented interface since false positives are possible;
705 // there is no law that says that an OS that has large stat.st_size
706 // actually supports large file sizes.
707
708 namespace detail {
709
710 BOOST_FILESYSTEM_DECL bool possible_large_file_size_support();
711
712 } // namespace detail
713
714 } // namespace filesystem
715 } // namespace boost
716
717 #include <boost/filesystem/detail/footer.hpp>
718
719 #endif // BOOST_FILESYSTEM_OPERATIONS_HPP