-
Notifications
You must be signed in to change notification settings - Fork 26
/
operations.hpp
1412 lines (1206 loc) · 54.3 KB
/
operations.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// boost/filesystem/operations.hpp ---------------------------------------------------//
// Copyright Beman Dawes 2002-2009
// Copyright Jan Langer 2002
// Copyright Dietmar Kuehl 2001
// Copyright Vladimir Prus 2002
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
#ifndef BOOST_FILESYSTEM3_OPERATIONS_HPP
#define BOOST_FILESYSTEM3_OPERATIONS_HPP
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/detail/scoped_enum_emulation.hpp>
#include <boost/detail/bitmask.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/iterator.hpp>
#include <boost/cstdint.hpp>
#include <boost/range/mutable_iterator.hpp>
#include <boost/range/const_iterator.hpp>
#ifndef BOOST_FILESYSTEM_USE_TIME_T
#include <boost/chrono.hpp>
#endif
#include <boost/assert.hpp>
#include <string>
#include <utility> // for pair
#include <ctime>
#include <vector>
#include <stack>
#ifdef BOOST_WINDOWS_API
# include <fstream>
#endif
#include <boost/config/abi_prefix.hpp> // must be the last #include
//--------------------------------------------------------------------------------------//
namespace boost
{
namespace filesystem
{
//--------------------------------------------------------------------------------------//
// file_type //
//--------------------------------------------------------------------------------------//
BOOST_SCOPED_ENUM_DECLARE_BEGIN(file_type)
{
none = 0,
not_found = -1,
unknown = 1, // file does exist, but is not one of the other types or the process
// does not have permission to query the file type
regular = 2,
directory = 3,
// the following may not apply to some operating systems or file systems
symlink = 4,
block = 5,
character = 6,
fifo = 7,
socket = 8,
reparse_point = 9, // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
_detail_directory_symlink, // internal use only; never exposed to users
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
status_error = none,
status_unknown = none,
file_not_found = not_found,
regular_file = regular,
directory_file = directory,
// the following may not apply to some operating systems or file systems
symlink_file = symlink,
block_file = block,
character_file = character,
fifo_file = fifo,
socket_file = socket,
reparse_file = reparse_point,
type_unknown = unknown
# endif
}
BOOST_SCOPED_ENUM_DECLARE_END(file_type)
//--------------------------------------------------------------------------------------//
// perms //
//--------------------------------------------------------------------------------------//
enum perms
{
no_perms = 0, // file_not_found is no_perms rather than perms_not_known
// POSIX equivalent macros given in comments.
// Values are from POSIX and are given in octal per the POSIX standard.
// permission bits
owner_read = 0400, // S_IRUSR, Read permission, owner
owner_write = 0200, // S_IWUSR, Write permission, owner
owner_exe = 0100, // S_IXUSR, Execute/search permission, owner
owner_all = 0700, // S_IRWXU, Read, write, execute/search by owner
group_read = 040, // S_IRGRP, Read permission, group
group_write = 020, // S_IWGRP, Write permission, group
group_exe = 010, // S_IXGRP, Execute/search permission, group
group_all = 070, // S_IRWXG, Read, write, execute/search by group
others_read = 04, // S_IROTH, Read permission, others
others_write = 02, // S_IWOTH, Write permission, others
others_exe = 01, // S_IXOTH, Execute/search permission, others
others_all = 07, // S_IRWXO, Read, write, execute/search by others
all_all = owner_all|group_all|others_all, // 0777
// other POSIX bits
set_uid_on_exe = 04000, // S_ISUID, Set-user-ID on execution
set_gid_on_exe = 02000, // S_ISGID, Set-group-ID on execution
sticky_bit = 01000, // S_ISVTX,
// (POSIX XSI) On directories, restricted deletion flag
// (V7) 'sticky bit': save swapped text even after use
// (SunOS) On non-directories: don't cache this file
// (SVID-v4.2) On directories: restricted deletion flag
// Also see http://en.wikipedia.org/wiki/Sticky_bit
perms_mask = all_all|set_uid_on_exe|set_gid_on_exe|sticky_bit, // 07777
perms_not_known = 0xFFFF, // present when directory_entry cache not loaded
// options for permissions() function
add_perms = 0x1000, // adds the given permission bits to the current bits
remove_perms = 0x2000, // removes the given permission bits from the current bits;
// choose add_perms or remove_perms, not both; if neither add_perms
// nor remove_perms is given, replace the current bits with
// the given bits.
symlink_perms = 0x4000 // on POSIX, don't resolve symlinks; implied on Windows
};
BOOST_BITMASK(perms)
//--------------------------------------------------------------------------------------//
// file_status //
//--------------------------------------------------------------------------------------//
class BOOST_FILESYSTEM_DECL file_status
{
public:
file_status()
BOOST_NOEXCEPT : m_type(file_type::none), m_perms(perms_not_known) {}
explicit file_status(file_type tp, perms prms = perms_not_known)
BOOST_NOEXCEPT : m_type(tp), m_perms(prms) {}
#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
// Until compilers catch up, destructor and move construct/assign are not defaulted
file_status(const file_status&) = default;
file_status& operator=(const file_status&) = default;
#endif
~file_status() {}
// observers
BOOST_SCOPED_ENUM(file_type) type() const BOOST_NOEXCEPT { return m_type; }
perms permissions() const BOOST_NOEXCEPT { return m_perms; }
// modifiers
void type(file_type v) BOOST_NOEXCEPT { m_type = v; }
void permissions(perms prms) BOOST_NOEXCEPT
{ m_perms = prms; }
bool operator==(const file_status& rhs) const BOOST_NOEXCEPT
{ return type() == rhs.type() &&
permissions() == rhs.permissions(); }
bool operator!=(const file_status& rhs) const BOOST_NOEXCEPT
{ return !(*this == rhs); }
private:
BOOST_SCOPED_ENUM(file_type) m_type;
enum perms m_perms;
};
inline bool type_present(file_status f) BOOST_NOEXCEPT
{ return f.type() != file_type::none; }
inline bool permissions_present(file_status f) BOOST_NOEXCEPT
{return f.permissions() != perms_not_known;}
inline bool status_known(file_status f) BOOST_NOEXCEPT
{ return type_present(f) && permissions_present(f); }
inline bool exists(file_status f) BOOST_NOEXCEPT
{ return f.type() != file_type::none
&& f.type() != file_type::not_found; }
inline bool is_regular_file(file_status f) BOOST_NOEXCEPT
{ return f.type() == file_type::regular; }
inline bool is_directory(file_status f) BOOST_NOEXCEPT
{ return f.type() == file_type::directory; }
inline bool is_symlink(file_status f) BOOST_NOEXCEPT
{ return f.type() == file_type::symlink; }
inline bool is_other(file_status f) BOOST_NOEXCEPT
{ return exists(f) && !is_regular_file(f)
&& !is_directory(f) && !is_symlink(f); }
inline bool is_block_file(file_status f) BOOST_NOEXCEPT
{ return f.type() == file_type::block; }
inline bool is_character_file(file_status f) BOOST_NOEXCEPT
{ return f.type() == file_type::character; }
inline bool is_fifo(file_status f) BOOST_NOEXCEPT
{ return f.type() == file_type::fifo; }
inline bool is_socket(file_status f) BOOST_NOEXCEPT
{ return f.type() == file_type::socket; }
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline bool is_regular(file_status f) { return f.type() == file_type::regular; }
# endif
//--------------------------------------------------------------------------------------//
// copy_options //
//--------------------------------------------------------------------------------------//
BOOST_SCOPED_ENUM_DECLARE_BEGIN(copy_options)
{
none = 0,
// Option group controlling copy_file() effects for existing target files
skip_existing = 1,
overwrite_existing = 2,
update_existing = 4,
// Option group controlling copy() effects for sub-directories
recursive = 8,
// Option group controlling copy() effects for symbolic links
copy_symlinks = 16,
skip_symlinks = 32,
// Option group controlling copy() effects copy method
directories_only = 64,
create_symlinks = 128,
create_hard_links = 256,
// unspecified implementation detail
_detail_sub_directory = 512,
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
fail_if_exists = none,
overwrite_if_exists = overwrite_existing
# endif
}
BOOST_SCOPED_ENUM_DECLARE_END(copy_options)
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
typedef copy_options copy_option;
# endif
BOOST_BITMASK(BOOST_SCOPED_ENUM(copy_options))
//--------------------------------------------------------------------------------------//
// misc //
//--------------------------------------------------------------------------------------//
struct space_info
{
// all values are byte counts
boost::uintmax_t capacity;
boost::uintmax_t free; // <= capacity
boost::uintmax_t available; // <= free
};
#ifdef BOOST_FILESYSTEM_USE_TIME_T
typedef std::time_t file_time_type;
#else
typedef boost::chrono::system_clock::time_point file_time_type;
#endif
//--------------------------------------------------------------------------------------//
// implementation details //
//--------------------------------------------------------------------------------------//
namespace detail
{
BOOST_FILESYSTEM_DECL
file_status status(const path&p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
file_status symlink_status(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
bool is_empty(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
path initial_path(system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
path canonical(const path& p, const path& base, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void copy(const path& from, const path& to,
BOOST_SCOPED_ENUM(copy_options) options, system::error_code* ec=0);
//BOOST_FILESYSTEM_DECL
//void copy_directory(const path& from, const path& to, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
bool copy_file(const path& from, const path& to,
BOOST_SCOPED_ENUM(copy_options) options, // See ticket #2925
system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void copy_symlink(const path& existing_symlink, const path& new_symlink,
system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
bool create_directories(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
bool create_directory(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
bool create_directory(const path& p, const path& existing_p,
system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void create_directory_symlink(const path& to, const path& from,
system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void create_hard_link(const path& to, const path& from, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void create_symlink(const path& to, const path& from, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
path current_path(system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void current_path(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
bool equivalent(const path& p1, const path& p2, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
boost::uintmax_t file_size(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
boost::uintmax_t hard_link_count(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
std::time_t last_write_time(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void last_write_time(const path& p, const std::time_t new_time,
system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void permissions(const path& p, perms prms, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
path read_symlink(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
// For standardization, if the committee doesn't like "remove", consider "eliminate"
bool remove(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
boost::uintmax_t remove_all(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void rename(const path& old_p, const path& new_p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
void resize_file(const path& p, uintmax_t size, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
space_info space(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
path system_complete(const path& p, system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
path temp_directory_path(system::error_code* ec=0);
BOOST_FILESYSTEM_DECL
path unique_path(const path& p, system::error_code* ec=0);
} // namespace detail
//--------------------------------------------------------------------------------------//
// //
// status query functions //
// //
//--------------------------------------------------------------------------------------//
inline
file_status status(const path& p) {return detail::status(p);}
inline
file_status status(const path& p, system::error_code& ec)
{return detail::status(p, &ec);}
inline
file_status symlink_status(const path& p) {return detail::symlink_status(p);}
inline
file_status symlink_status(const path& p, system::error_code& ec)
{return detail::symlink_status(p, &ec);}
inline
bool exists(const path& p) {return exists(detail::status(p));}
inline
bool exists(const path& p, system::error_code& ec)
{return exists(detail::status(p, &ec));}
inline
bool is_directory(const path& p) {return is_directory(detail::status(p));}
inline
bool is_directory(const path& p, system::error_code& ec)
{return is_directory(detail::status(p, &ec));}
inline
bool is_regular_file(const path& p) {return is_regular_file(detail::status(p));}
inline
bool is_regular_file(const path& p, system::error_code& ec)
{return is_regular_file(detail::status(p, &ec));}
inline
bool is_other(const path& p) {return is_other(detail::status(p));}
inline
bool is_other(const path& p, system::error_code& ec)
{return is_other(detail::status(p, &ec));}
inline
bool is_symlink(const path& p) {return is_symlink(detail::symlink_status(p));}
inline
bool is_symlink(const path& p, system::error_code& ec)
{return is_symlink(detail::symlink_status(p, &ec));}
inline
bool is_block_file(const path& p) {return is_block_file(detail::status(p));}
inline
bool is_block_file(const path& p, system::error_code& ec)
{return is_block_file(detail::status(p, &ec));}
inline
bool is_character_file(const path& p){return is_character_file(detail::status(p));}
inline
bool is_character_file(const path& p, system::error_code& ec)
{return is_character_file(detail::status(p, &ec));}
inline
bool is_fifo(const path& p) {return is_fifo(detail::status(p));}
inline
bool is_fifo(const path& p, system::error_code& ec)
{return is_fifo(detail::status(p, &ec));}
inline
bool is_socket(const path& p) {return is_socket(detail::status(p));}
inline
bool is_socket(const path& p, system::error_code& ec)
{return is_socket(detail::status(p, &ec));}
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline
bool is_regular(const path& p) {return is_regular(detail::status(p));}
inline
bool is_regular(const path& p, system::error_code& ec)
{return is_regular(detail::status(p, &ec));}
# endif
inline
bool is_empty(const path& p) {return detail::is_empty(p);}
inline
bool is_empty(const path& p, system::error_code& ec)
{return detail::is_empty(p, &ec);}
//--------------------------------------------------------------------------------------//
// //
// operational functions //
// in alphabetical order, unless otherwise noted //
// //
//--------------------------------------------------------------------------------------//
// forward declarations
path current_path(); // fwd declaration
path initial_path();
BOOST_FILESYSTEM_DECL
path absolute(const path& p, const path& base=current_path());
// If base.is_absolute(), throws nothing. Thus no need for ec argument
inline
path canonical(const path& p, const path& base=current_path())
{return detail::canonical(p, base);}
inline
path canonical(const path& p, system::error_code& ec)
{return detail::canonical(p, current_path(), &ec);}
inline
path canonical(const path& p, const path& base, system::error_code& ec)
{return detail::canonical(p, base, &ec);}
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline
path complete(const path& p)
{
return absolute(p, initial_path());
}
inline
path complete(const path& p, const path& base)
{
return absolute(p, base);
}
# endif
inline
void copy(const path& from, const path& to, copy_options options = copy_options::none)
{detail::copy(from, to, options);}
inline
void copy(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
{detail::copy(from, to, copy_options::none, &ec);}
inline
void copy(const path& from, const path& to, copy_options options,
system::error_code& ec) BOOST_NOEXCEPT
{detail::copy(from, to, options, &ec);}
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline
void copy_directory(const path& from, const path& to)
{detail::create_directory(to, from);}
inline
void copy_directory(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
{detail::create_directory(to, from, &ec);}
# endif
inline
bool copy_file(const path& from, const path& to, // See ticket #2925
BOOST_SCOPED_ENUM(copy_options) options)
{return detail::copy_file(from, to, options);}
inline
bool copy_file(const path& from, const path& to)
{return detail::copy_file(from, to, copy_options::none);}
inline
bool copy_file(const path& from, const path& to, // See ticket #2925
BOOST_SCOPED_ENUM(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT
{return detail::copy_file(from, to, options, &ec);}
inline
bool copy_file(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
{return detail::copy_file(from, to, copy_options::none, &ec);}
inline
void copy_symlink(const path& existing_symlink, const path& new_symlink)
{detail::copy_symlink(existing_symlink, new_symlink);}
inline
void copy_symlink(const path& existing_symlink, const path& new_symlink,
system::error_code& ec) BOOST_NOEXCEPT
{detail::copy_symlink(existing_symlink, new_symlink, &ec);}
inline
bool create_directories(const path& p) {return detail::create_directories(p);}
inline
bool create_directories(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::create_directories(p, &ec);}
inline
bool create_directory(const path& p) {return detail::create_directory(p);}
inline
bool create_directory(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::create_directory(p, &ec);}
inline
bool create_directory(const path& p, const path& existing_p)
{return detail::create_directory(p, existing_p);}
inline
bool create_directory(const path& p, const path& existing_p,
system::error_code& ec) BOOST_NOEXCEPT
{return detail::create_directory(p, existing_p, &ec);}
inline
void create_directory_symlink(const path& to, const path& from)
{detail::create_directory_symlink(to, from);}
inline
void create_directory_symlink(const path& to, const path& from,
system::error_code& ec) BOOST_NOEXCEPT
{detail::create_directory_symlink(to, from, &ec);}
inline
void create_hard_link(const path& to, const path& new_hard_link)
{detail::create_hard_link(to, new_hard_link);}
inline
void create_hard_link(const path& to, const path& new_hard_link,
system::error_code& ec) BOOST_NOEXCEPT
{detail::create_hard_link(to, new_hard_link, &ec);}
inline
void create_symlink(const path& to, const path& new_symlink)
{detail::create_symlink(to, new_symlink);}
inline
void create_symlink(const path& to, const path& new_symlink,
system::error_code& ec) BOOST_NOEXCEPT
{detail::create_symlink(to, new_symlink, &ec);}
inline
path current_path() {return detail::current_path();}
inline
path current_path(system::error_code& ec) {return detail::current_path(&ec);}
inline
void current_path(const path& p) {detail::current_path(p);}
inline
void current_path(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{detail::current_path(p, &ec);}
inline
bool equivalent(const path& p1, const path& p2) {return detail::equivalent(p1, p2);}
inline
bool equivalent(const path& p1, const path& p2, system::error_code& ec) BOOST_NOEXCEPT
{return detail::equivalent(p1, p2, &ec);}
inline
boost::uintmax_t file_size(const path& p) {return detail::file_size(p);}
inline
boost::uintmax_t file_size(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::file_size(p, &ec);}
inline
boost::uintmax_t hard_link_count(const path& p) {return detail::hard_link_count(p);}
inline
boost::uintmax_t hard_link_count(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::hard_link_count(p, &ec);}
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline
path initial_path() {return detail::initial_path();}
inline
path initial_path(system::error_code& ec)
{return detail::initial_path(&ec);}
template <class Path>
path initial_path() {return initial_path();}
template <class Path>
path initial_path(system::error_code& ec)
{return detail::initial_path(&ec);}
#endif
inline
file_time_type last_write_time(const path& p)
#ifdef BOOST_FILESYSTEM_USE_TIME_T
{return detail::last_write_time(p);}
#else
{return boost::chrono::system_clock::from_time_t(detail::last_write_time(p));}
#endif
inline
file_time_type last_write_time(const path& p, system::error_code& ec) BOOST_NOEXCEPT
#ifdef BOOST_FILESYSTEM_USE_TIME_T
{return detail::last_write_time(p, &ec);}
#else
{return boost::chrono::system_clock::from_time_t(detail::last_write_time(p, &ec));}
#endif
inline
void last_write_time(const path& p, file_time_type new_time)
#ifdef BOOST_FILESYSTEM_USE_TIME_T
{detail::last_write_time(p, new_time);}
#else
{detail::last_write_time(p, boost::chrono::system_clock::to_time_t(new_time));}
#endif
inline
void last_write_time(const path& p, file_time_type new_time,
system::error_code& ec) BOOST_NOEXCEPT
#ifdef BOOST_FILESYSTEM_USE_TIME_T
{detail::last_write_time(p, new_time, &ec);}
#else
{detail::last_write_time(p, boost::chrono::system_clock::to_time_t(new_time), &ec);}
#endif
inline
void permissions(const path& p, perms prms)
{detail::permissions(p, prms);}
inline
void permissions(const path& p, perms prms, system::error_code& ec) BOOST_NOEXCEPT
{detail::permissions(p, prms, &ec);}
inline
path read_symlink(const path& p) {return detail::read_symlink(p);}
inline
path read_symlink(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::read_symlink(p, &ec);}
inline
// For standardization, if the committee doesn't like "remove", consider "eliminate"
bool remove(const path& p) {return detail::remove(p);}
inline
bool remove(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::remove(p, &ec);}
inline
boost::uintmax_t remove_all(const path& p) {return detail::remove_all(p);}
inline
boost::uintmax_t remove_all(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::remove_all(p, &ec);}
inline
void rename(const path& old_p, const path& new_p) {detail::rename(old_p, new_p);}
inline
void rename(const path& old_p, const path& new_p, system::error_code& ec) BOOST_NOEXCEPT
{detail::rename(old_p, new_p, &ec);}
inline // name suggested by Scott McMurray
void resize_file(const path& p, uintmax_t size) {detail::resize_file(p, size);}
inline
void resize_file(const path& p, uintmax_t size, system::error_code& ec) BOOST_NOEXCEPT
{detail::resize_file(p, size, &ec);}
inline
space_info space(const path& p) {return detail::space(p);}
inline
space_info space(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::space(p, &ec);}
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline bool symbolic_link_exists(const path& p)
{return is_symlink(symlink_status(p));}
# endif
inline
path system_complete(const path& p) {return detail::system_complete(p);}
inline
path system_complete(const path& p, system::error_code& ec)
{return detail::system_complete(p, &ec);}
inline
path temp_directory_path() {return detail::temp_directory_path();}
inline
path temp_directory_path(system::error_code& ec)
{return detail::temp_directory_path(&ec);}
inline
path unique_path(const path& p="%%%%-%%%%-%%%%-%%%%")
{ return detail::unique_path(p); }
inline
path unique_path(const path& p, system::error_code& ec)
{ return detail::unique_path(p, &ec); }
//--------------------------------------------------------------------------------------//
// //
// directory_entry //
// //
//--------------------------------------------------------------------------------------//
// GCC has a problem with a member function named path within a namespace or
// sub-namespace that also has a class named path. The workaround is to always
// fully qualify the name path when it refers to the class name.
class BOOST_FILESYSTEM_DECL directory_entry
{
public:
#ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
// Until compilers catch up, destructor and move construct/assign are not defaulted
directory_entry() = default;
directory_entry(const directory_entry&) = default;
directory_entry& operator=(const directory_entry&) = default;
#else
directory_entry() {}
#endif
~directory_entry() {}
explicit directory_entry(const boost::filesystem::path& p,
file_status st = file_status(), file_status symlink_st=file_status())
: m_path(p), m_status(st), m_symlink_status(symlink_st)
{}
void assign(const boost::filesystem::path& p,
file_status st = file_status(), file_status symlink_st = file_status())
{ m_path = p; m_status = st; m_symlink_status = symlink_st; }
void replace_filename(const boost::filesystem::path& p,
file_status st = file_status(), file_status symlink_st = file_status())
{
m_path.remove_filename();
m_path /= p;
m_status = st;
m_symlink_status = symlink_st;
}
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
void replace_leaf(const boost::filesystem::path& p,
file_status st, file_status symlink_st)
{ replace_filename(p, st, symlink_st); }
# endif
const boost::filesystem::path& path() const BOOST_NOEXCEPT {return m_path;}
file_status status() const {return m_get_status();}
file_status status(system::error_code& ec) const BOOST_NOEXCEPT
{return m_get_status(&ec);}
file_status symlink_status() const {return m_get_symlink_status();}
file_status symlink_status(system::error_code& ec) const BOOST_NOEXCEPT
{return m_get_symlink_status(&ec);}
bool operator==(const directory_entry& rhs) const BOOST_NOEXCEPT
{return m_path == rhs.m_path;}
bool operator!=(const directory_entry& rhs) const BOOST_NOEXCEPT
{return m_path != rhs.m_path;}
bool operator< (const directory_entry& rhs) const BOOST_NOEXCEPT
{return m_path < rhs.m_path;}
bool operator<=(const directory_entry& rhs) const BOOST_NOEXCEPT
{return m_path <= rhs.m_path;}
bool operator> (const directory_entry& rhs) const BOOST_NOEXCEPT
{return m_path > rhs.m_path;}
bool operator>=(const directory_entry& rhs) const BOOST_NOEXCEPT
{return m_path >= rhs.m_path;}
private:
boost::filesystem::path m_path;
mutable file_status m_status; // stat()-like
mutable file_status m_symlink_status; // lstat()-like
file_status m_get_status(system::error_code* ec=0) const;
file_status m_get_symlink_status(system::error_code* ec=0) const;
}; // directory_entry
//--------------------------------------------------------------------------------------//
// //
// directory_iterator helpers //
// //
//--------------------------------------------------------------------------------------//
class directory_iterator;
namespace detail
{
BOOST_FILESYSTEM_DECL
system::error_code dir_itr_close(// never throws()
void *& handle
# if defined(BOOST_POSIX_API)
, void *& buffer
# endif
);
struct dir_itr_imp
{
directory_entry dir_entry;
void* handle;
# ifdef BOOST_POSIX_API
void* buffer; // see dir_itr_increment implementation
# endif
dir_itr_imp() : handle(0)
# ifdef BOOST_POSIX_API
, buffer(0)
# endif
{}
~dir_itr_imp() // never throws
{
dir_itr_close(handle
# if defined(BOOST_POSIX_API)
, buffer
# endif
);
}
};
// see path::iterator: comment below
BOOST_FILESYSTEM_DECL void directory_iterator_construct(directory_iterator& it,
const path& p, system::error_code* ec, bool eof_on_permission_denied=false);
BOOST_FILESYSTEM_DECL void directory_iterator_increment(directory_iterator& it,
system::error_code* ec);
} // namespace detail
//----------------------------- directory_options ------------------------------------//
BOOST_SCOPED_ENUM_START(directory_options)
{
none,
follow_directory_symlink, // default: not set; skip directory symlink
skip_permission_denied, // default: not set; treat as error
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
no_recurse = none, // deprecated
recurse = follow_directory_symlink, // deprecated
# endif
_detail_no_push = skip_permission_denied << 1 // internal use only
};
BOOST_SCOPED_ENUM_END
BOOST_BITMASK(BOOST_SCOPED_ENUM(directory_options))
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
typedef directory_options symlink_option;
#endif
//--------------------------------------------------------------------------------------//
// //
// directory_iterator //
// //
//--------------------------------------------------------------------------------------//
class directory_iterator
: public boost::iterator_facade< directory_iterator,
directory_entry,
boost::single_pass_traversal_tag >
{
public:
# ifndef BOOST_NO_CXX11_DEFAULTED_FUNCTIONS
// Until compilers catch up, destructor and move construct/assign are not defaulted
directory_iterator() = default;
directory_iterator(const directory_iterator&) = default;
directory_iterator& operator=(const directory_iterator&) = default;
// TODO: Still not working with gcc 4.7.0
//~directory_iterator() BOOST_NOEXCEPT = default;
# else
directory_iterator() {} // creates the "end" iterator
# endif
~directory_iterator() {}
// iterator_facade derived classes don't seem to like implementations in
// separate translation unit dll's, so forward to detail functions
explicit directory_iterator(const path& p,
BOOST_SCOPED_ENUM(directory_options) opt = directory_options::none)
: m_imp(new detail::dir_itr_imp)
{
detail::directory_iterator_construct(*this, p, 0,
(opt & directory_options::skip_permission_denied)
== directory_options::skip_permission_denied);
}
directory_iterator(const path& p, system::error_code& ec,
BOOST_SCOPED_ENUM(directory_options) opt = directory_options::none) BOOST_NOEXCEPT
: m_imp(new detail::dir_itr_imp)
{
detail::directory_iterator_construct(*this, p, &ec,
(opt & directory_options::skip_permission_denied)
== directory_options::skip_permission_denied);
}
directory_iterator& increment(system::error_code& ec) BOOST_NOEXCEPT
{
detail::directory_iterator_increment(*this, &ec);
return *this;
}
private:
friend struct detail::dir_itr_imp;
friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_construct(directory_iterator& it,
const path& p, system::error_code* ec, bool eof_on_permission_denied);
friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_increment(directory_iterator& it,
system::error_code* ec);
// shared_ptr provides shallow-copy semantics required for InputIterators.
// m_imp.get()==0 indicates the end iterator.
boost::shared_ptr< detail::dir_itr_imp > m_imp;
friend class boost::iterator_core_access;
boost::iterator_facade<
directory_iterator,
directory_entry,
boost::single_pass_traversal_tag >::reference dereference() const
{
BOOST_ASSERT_MSG(m_imp.get(), "attempt to dereference end iterator");
return m_imp->dir_entry;
}
void increment() { detail::directory_iterator_increment(*this, 0); }
bool equal(const directory_iterator& rhs) const
{ return m_imp == rhs.m_imp; }
};
// enable C++11 range-base for statement use ---------------------------------------//
// begin() and end() are only used by a range-based for statement in the context of
// auto - thus the top-level const is stripped - so returning const is harmless and
// emphasizes begin() is just a pass through.
inline
const directory_iterator& begin(const directory_iterator& iter) BOOST_NOEXCEPT
{return iter;}
inline
directory_iterator end(const directory_iterator&) BOOST_NOEXCEPT
{return directory_iterator();}
// enable BOOST_FOREACH ------------------------------------------------------------//
inline
directory_iterator& range_begin(directory_iterator& iter) BOOST_NOEXCEPT {return iter;}
inline
directory_iterator range_begin(const directory_iterator& iter) BOOST_NOEXCEPT
{return iter;}
inline
directory_iterator range_end(const directory_iterator&) BOOST_NOEXCEPT
{return directory_iterator();}
} // namespace filesystem
// namespace boost template specializations
template<>
struct range_mutable_iterator<boost::filesystem::directory_iterator>
{ typedef boost::filesystem::directory_iterator type; };
template<>
struct range_const_iterator <boost::filesystem::directory_iterator>
{ typedef boost::filesystem::directory_iterator type; };
namespace filesystem
{
//--------------------------------------------------------------------------------------//
// //
// recursive_directory_iterator helpers //
// //
//--------------------------------------------------------------------------------------//
namespace detail
{
struct recur_dir_itr_imp
{
typedef directory_iterator element_type;
std::stack< element_type, std::vector< element_type > > m_stack;
int m_depth;
BOOST_SCOPED_ENUM(directory_options) m_options;
recur_dir_itr_imp() : m_depth(0), m_options(directory_options::none) {}
void increment(system::error_code* ec); // ec == 0 means throw on error