-
Notifications
You must be signed in to change notification settings - Fork 22
/
filesystem.hpp
executable file
·5558 lines (5031 loc) · 164 KB
/
filesystem.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
//---------------------------------------------------------------------------------------
//
// ghc::filesystem - A C++17-like filesystem implementation for C++11/C++14/C++17
//
//---------------------------------------------------------------------------------------
//
// Copyright (c) 2018, Steffen Schümann <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//---------------------------------------------------------------------------------------
//
// To dynamically select std::filesystem where available, you could use:
//
// #if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) && __has_include(<filesystem>)
// #include <filesystem>
// namespace fs = std::filesystem;
// #else
// #include <ghc/filesystem.hpp>
// namespace fs = ghc::filesystem;
// #endif
//
//---------------------------------------------------------------------------------------
#ifndef GHC_FILESYSTEM_H
#define GHC_FILESYSTEM_H
// #define BSD manifest constant only in
// sys/param.h
#ifndef _WIN32
#include <sys/param.h>
#endif
#ifndef GHC_OS_DETECTED
#if defined(__APPLE__) && defined(__MACH__)
#define GHC_OS_MACOS
#elif defined(__linux__)
#define GHC_OS_LINUX
#if defined(__ANDROID__)
#define GHC_OS_ANDROID
#endif
#elif defined(_WIN64)
#define GHC_OS_WINDOWS
#define GHC_OS_WIN64
#elif defined(_WIN32)
#define GHC_OS_WINDOWS
#define GHC_OS_WIN32
#elif defined(__svr4__)
#define GHC_OS_SYS5R4
#elif defined(BSD)
#define GHC_OS_BSD
#elif defined(__EMSCRIPTEN__)
#define GHC_OS_WEB
#include <wasi/api.h>
#else
#error "Operating system currently not supported!"
#endif
#define GHC_OS_DETECTED
#endif
#if defined(GHC_FILESYSTEM_IMPLEMENTATION)
#define GHC_EXPAND_IMPL
#define GHC_INLINE
#ifdef GHC_OS_WINDOWS
#define GHC_FS_API
#define GHC_FS_API_CLASS
#else
#define GHC_FS_API __attribute__((visibility("default")))
#define GHC_FS_API_CLASS __attribute__((visibility("default")))
#endif
#elif defined(GHC_FILESYSTEM_FWD)
#define GHC_INLINE
#ifdef GHC_OS_WINDOWS
#define GHC_FS_API extern
#define GHC_FS_API_CLASS
#else
#define GHC_FS_API extern
#define GHC_FS_API_CLASS
#endif
#else
#define GHC_EXPAND_IMPL
#define GHC_INLINE inline
#define GHC_FS_API
#define GHC_FS_API_CLASS
#endif
#ifdef GHC_EXPAND_IMPL
#ifdef GHC_OS_WINDOWS
#include <windows.h>
// additional includes
#include <shellapi.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <wchar.h>
#include <winioctl.h>
#else
#include <dirent.h>
#include <fcntl.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <limits.h>
#ifdef GHC_OS_ANDROID
#include <android/api-level.h>
#if __ANDROID_API__ < 12
#include <sys/syscall.h>
#endif
#include <sys/vfs.h>
#define statvfs statfs
#else
#include <sys/statvfs.h>
#endif
#if !defined(__ANDROID__) || __ANDROID_API__ >= 26
#include <langinfo.h>
#endif
#endif
#ifdef GHC_OS_MACOS
#include <Availability.h>
#endif
#include <algorithm>
#include <cctype>
#include <chrono>
#include <clocale>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <memory>
#include <stack>
#include <stdexcept>
#include <string>
#include <system_error>
#include <type_traits>
#include <utility>
#include <vector>
#else // GHC_EXPAND_IMPL
#include <chrono>
#include <fstream>
#include <memory>
#include <stack>
#include <stdexcept>
#include <string>
#include <system_error>
#ifdef GHC_OS_WINDOWS
#include <vector>
#endif
#endif // GHC_EXPAND_IMPL
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Behaviour Switches (see README.md, should match the config in test/filesystem_test.cpp):
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// LWG #2682 disables the since then invalid use of the copy option create_symlinks on directories
// configure LWG conformance ()
#define LWG_2682_BEHAVIOUR
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// LWG #2395 makes crate_directory/create_directories not emit an error if there is a regular
// file with that name, it is superceded by P1164R1, so only activate if really needed
// #define LWG_2935_BEHAVIOUR
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// LWG #2937 enforces that fs::equivalent emits an error, if !fs::exists(p1)||!exists(p2)
#define LWG_2937_BEHAVIOUR
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// UTF8-Everywhere is the original behaviour of ghc::filesystem. With this define you can
// enable the more standard conforming implementation option that uses wstring on Windows
// as ghc::filesystem::string_type.
// #define GHC_WIN_WSTRING_STRING_TYPE
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Raise errors/exceptions when invalid unicode codepoints or UTF-8 sequences are found,
// instead of replacing them with the unicode replacement character (U+FFFD).
// #define GHC_RAISE_UNICODE_ERRORS
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ghc::filesystem version in decimal (major * 10000 + minor * 100 + patch)
#define GHC_FILESYSTEM_VERSION 10304L
#if !defined(GHC_WITH_EXCEPTIONS) && (defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND))
#define GHC_WITH_EXCEPTIONS
#endif
#if !defined(GHC_WITH_EXCEPTIONS) && defined(GHC_RAISE_UNICODE_ERRORS)
#error "Can't raise unicode errors whith exception support disabled"
#endif
namespace ghc {
namespace filesystem {
// temporary existing exception type for yet unimplemented parts
class GHC_FS_API_CLASS not_implemented_exception : public std::logic_error
{
public:
not_implemented_exception()
: std::logic_error("function not implemented yet.")
{
}
};
template<typename char_type>
class path_helper_base
{
public:
using value_type = char_type;
#ifdef GHC_OS_WINDOWS
static constexpr value_type preferred_separator = '\\';
#else
static constexpr value_type preferred_separator = '/';
#endif
};
#if __cplusplus < 201703L
template <typename char_type>
constexpr char_type path_helper_base<char_type>::preferred_separator;
#endif
// 30.10.8 class path
class GHC_FS_API_CLASS path
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_WSTRING_STRING_TYPE)
#define GHC_USE_WCHAR_T
: private path_helper_base<std::wstring::value_type>
{
public:
using path_helper_base<std::wstring::value_type>::value_type;
#else
: private path_helper_base<std::string::value_type>
{
public:
using path_helper_base<std::string::value_type>::value_type;
#endif
using string_type = std::basic_string<value_type>;
using path_helper_base<value_type>::preferred_separator;
// 30.10.10.1 enumeration format
/// The path format in wich the constructor argument is given.
enum format {
generic_format, ///< The generic format, internally used by
///< ghc::filesystem::path with slashes
native_format, ///< The format native to the current platform this code
///< is build for
auto_format, ///< Try to auto-detect the format, fallback to native
};
template <class T>
struct _is_basic_string : std::false_type
{
};
template <class CharT, class Traits, class Alloc>
struct _is_basic_string<std::basic_string<CharT, Traits, Alloc>> : std::true_type
{
};
#ifdef __cpp_lib_string_view
template <class CharT>
struct _is_basic_string<std::basic_string_view<CharT>> : std::true_type
{
};
#endif
template <typename T1, typename T2 = void>
using path_type = typename std::enable_if<!std::is_same<path, T1>::value, path>::type;
#ifdef GHC_USE_WCHAR_T
template <typename T>
using path_from_string = typename std::enable_if<_is_basic_string<T>::value || std::is_same<char const*, typename std::decay<T>::type>::value || std::is_same<char*, typename std::decay<T>::type>::value ||
std::is_same<wchar_t const*, typename std::decay<T>::type>::value || std::is_same<wchar_t*, typename std::decay<T>::type>::value,
path>::type;
template <typename T>
using path_type_EcharT = typename std::enable_if<std::is_same<T, char>::value || std::is_same<T, char16_t>::value || std::is_same<T, char32_t>::value, path>::type;
#else
template <typename T>
using path_from_string = typename std::enable_if<_is_basic_string<T>::value || std::is_same<char const*, typename std::decay<T>::type>::value || std::is_same<char*, typename std::decay<T>::type>::value, path>::type;
template <typename T>
using path_type_EcharT = typename std::enable_if<std::is_same<T, char>::value || std::is_same<T, char16_t>::value || std::is_same<T, char32_t>::value || std::is_same<T, wchar_t>::value, path>::type;
#endif
// 30.10.8.4.1 constructors and destructor
path() noexcept;
path(const path& p);
path(path&& p) noexcept;
path(string_type&& source, format fmt = auto_format);
template <class Source, typename = path_from_string<Source>>
path(const Source& source, format fmt = auto_format);
template <class InputIterator>
path(InputIterator first, InputIterator last, format fmt = auto_format);
#ifdef GHC_WITH_EXCEPTIONS
template <class Source, typename = path_from_string<Source>>
path(const Source& source, const std::locale& loc, format fmt = auto_format);
template <class InputIterator>
path(InputIterator first, InputIterator last, const std::locale& loc, format fmt = auto_format);
#endif
~path();
// 30.10.8.4.2 assignments
path& operator=(const path& p);
path& operator=(path&& p) noexcept;
path& operator=(string_type&& source);
path& assign(string_type&& source);
template <class Source>
path& operator=(const Source& source);
template <class Source>
path& assign(const Source& source);
template <class InputIterator>
path& assign(InputIterator first, InputIterator last);
// 30.10.8.4.3 appends
path& operator/=(const path& p);
template <class Source>
path& operator/=(const Source& source);
template <class Source>
path& append(const Source& source);
template <class InputIterator>
path& append(InputIterator first, InputIterator last);
// 30.10.8.4.4 concatenation
path& operator+=(const path& x);
path& operator+=(const string_type& x);
#ifdef __cpp_lib_string_view
path& operator+=(std::basic_string_view<value_type> x);
#endif
path& operator+=(const value_type* x);
path& operator+=(value_type x);
template <class Source>
path_from_string<Source>& operator+=(const Source& x);
template <class EcharT>
path_type_EcharT<EcharT>& operator+=(EcharT x);
template <class Source>
path& concat(const Source& x);
template <class InputIterator>
path& concat(InputIterator first, InputIterator last);
// 30.10.8.4.5 modifiers
void clear() noexcept;
path& make_preferred();
path& remove_filename();
path& replace_filename(const path& replacement);
path& replace_extension(const path& replacement = path());
void swap(path& rhs) noexcept;
// 30.10.8.4.6 native format observers
const string_type& native() const; // this implementation doesn't support noexcept for native()
const value_type* c_str() const; // this implementation doesn't support noexcept for c_str()
operator string_type() const;
template <class EcharT, class traits = std::char_traits<EcharT>, class Allocator = std::allocator<EcharT>>
std::basic_string<EcharT, traits, Allocator> string(const Allocator& a = Allocator()) const;
std::string string() const;
std::wstring wstring() const;
std::string u8string() const;
std::u16string u16string() const;
std::u32string u32string() const;
// 30.10.8.4.7 generic format observers
template <class EcharT, class traits = std::char_traits<EcharT>, class Allocator = std::allocator<EcharT>>
std::basic_string<EcharT, traits, Allocator> generic_string(const Allocator& a = Allocator()) const;
const std::string& generic_string() const; // this is different from the standard, that returns by value
std::wstring generic_wstring() const;
std::string generic_u8string() const;
std::u16string generic_u16string() const;
std::u32string generic_u32string() const;
// 30.10.8.4.8 compare
int compare(const path& p) const noexcept;
int compare(const string_type& s) const;
#ifdef __cpp_lib_string_view
int compare(std::basic_string_view<value_type> s) const;
#endif
int compare(const value_type* s) const;
// 30.10.8.4.9 decomposition
path root_name() const;
path root_directory() const;
path root_path() const;
path relative_path() const;
path parent_path() const;
path filename() const;
path stem() const;
path extension() const;
// 30.10.8.4.10 query
bool empty() const noexcept;
bool has_root_name() const;
bool has_root_directory() const;
bool has_root_path() const;
bool has_relative_path() const;
bool has_parent_path() const;
bool has_filename() const;
bool has_stem() const;
bool has_extension() const;
bool is_absolute() const;
bool is_relative() const;
// 30.10.8.4.11 generation
path lexically_normal() const;
path lexically_relative(const path& base) const;
path lexically_proximate(const path& base) const;
// 30.10.8.5 iterators
class iterator;
using const_iterator = iterator;
iterator begin() const;
iterator end() const;
private:
using impl_value_type = std::string::value_type;
using impl_string_type = std::basic_string<impl_value_type>;
friend class directory_iterator;
void append_name(const char* name);
static constexpr impl_value_type generic_separator = '/';
template <typename InputIterator>
class input_iterator_range
{
public:
typedef InputIterator iterator;
typedef InputIterator const_iterator;
typedef typename InputIterator::difference_type difference_type;
input_iterator_range(const InputIterator& first, const InputIterator& last)
: _first(first)
, _last(last)
{
}
InputIterator begin() const { return _first; }
InputIterator end() const { return _last; }
private:
InputIterator _first;
InputIterator _last;
};
friend void swap(path& lhs, path& rhs) noexcept;
friend size_t hash_value(const path& p) noexcept;
static void postprocess_path_with_format(impl_string_type& p, format fmt);
impl_string_type _path;
#ifdef GHC_OS_WINDOWS
impl_string_type native_impl() const;
mutable string_type _native_cache;
#else
const impl_string_type& native_impl() const;
#endif
};
// 30.10.8.6 path non-member functions
GHC_FS_API void swap(path& lhs, path& rhs) noexcept;
GHC_FS_API size_t hash_value(const path& p) noexcept;
GHC_FS_API bool operator==(const path& lhs, const path& rhs) noexcept;
GHC_FS_API bool operator!=(const path& lhs, const path& rhs) noexcept;
GHC_FS_API bool operator<(const path& lhs, const path& rhs) noexcept;
GHC_FS_API bool operator<=(const path& lhs, const path& rhs) noexcept;
GHC_FS_API bool operator>(const path& lhs, const path& rhs) noexcept;
GHC_FS_API bool operator>=(const path& lhs, const path& rhs) noexcept;
GHC_FS_API path operator/(const path& lhs, const path& rhs);
// 30.10.8.6.1 path inserter and extractor
template <class charT, class traits>
std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os, const path& p);
template <class charT, class traits>
std::basic_istream<charT, traits>& operator>>(std::basic_istream<charT, traits>& is, path& p);
// 30.10.8.6.2 path factory functions
template <class Source, typename = path::path_from_string<Source>>
path u8path(const Source& source);
template <class InputIterator>
path u8path(InputIterator first, InputIterator last);
// 30.10.9 class filesystem_error
class GHC_FS_API_CLASS filesystem_error : public std::system_error
{
public:
filesystem_error(const std::string& what_arg, std::error_code ec);
filesystem_error(const std::string& what_arg, const path& p1, std::error_code ec);
filesystem_error(const std::string& what_arg, const path& p1, const path& p2, std::error_code ec);
const path& path1() const noexcept;
const path& path2() const noexcept;
const char* what() const noexcept override;
private:
std::string _what_arg;
std::error_code _ec;
path _p1, _p2;
};
class GHC_FS_API_CLASS path::iterator
{
public:
using value_type = const path;
using difference_type = std::ptrdiff_t;
using pointer = const path*;
using reference = const path&;
using iterator_category = std::bidirectional_iterator_tag;
iterator();
iterator(const impl_string_type::const_iterator& first, const impl_string_type::const_iterator& last, const impl_string_type::const_iterator& pos);
iterator& operator++();
iterator operator++(int);
iterator& operator--();
iterator operator--(int);
bool operator==(const iterator& other) const;
bool operator!=(const iterator& other) const;
reference operator*() const;
pointer operator->() const;
private:
impl_string_type::const_iterator increment(const std::string::const_iterator& pos) const;
impl_string_type::const_iterator decrement(const std::string::const_iterator& pos) const;
void updateCurrent();
impl_string_type::const_iterator _first;
impl_string_type::const_iterator _last;
impl_string_type::const_iterator _root;
impl_string_type::const_iterator _iter;
path _current;
};
struct space_info
{
uintmax_t capacity;
uintmax_t free;
uintmax_t available;
};
// 30.10.10, enumerations
enum class file_type {
none,
not_found,
regular,
directory,
symlink,
block,
character,
fifo,
socket,
unknown,
};
enum class perms : uint16_t {
none = 0,
owner_read = 0400,
owner_write = 0200,
owner_exec = 0100,
owner_all = 0700,
group_read = 040,
group_write = 020,
group_exec = 010,
group_all = 070,
others_read = 04,
others_write = 02,
others_exec = 01,
others_all = 07,
all = 0777,
set_uid = 04000,
set_gid = 02000,
sticky_bit = 01000,
mask = 07777,
unknown = 0xffff
};
enum class perm_options : uint16_t {
replace = 3,
add = 1,
remove = 2,
nofollow = 4,
};
enum class copy_options : uint16_t {
none = 0,
skip_existing = 1,
overwrite_existing = 2,
update_existing = 4,
recursive = 8,
copy_symlinks = 0x10,
skip_symlinks = 0x20,
directories_only = 0x40,
create_symlinks = 0x80,
#ifndef GHC_OS_WEB
create_hard_links = 0x100
#endif
};
enum class directory_options : uint16_t {
none = 0,
follow_directory_symlink = 1,
skip_permission_denied = 2,
};
// 30.10.11 class file_status
class GHC_FS_API_CLASS file_status
{
public:
// 30.10.11.1 constructors and destructor
file_status() noexcept;
explicit file_status(file_type ft, perms prms = perms::unknown) noexcept;
file_status(const file_status&) noexcept;
file_status(file_status&&) noexcept;
~file_status();
// assignments:
file_status& operator=(const file_status&) noexcept;
file_status& operator=(file_status&&) noexcept;
// 30.10.11.3 modifiers
void type(file_type ft) noexcept;
void permissions(perms prms) noexcept;
// 30.10.11.2 observers
file_type type() const noexcept;
perms permissions() const noexcept;
private:
file_type _type;
perms _perms;
};
using file_time_type = std::chrono::time_point<std::chrono::system_clock>;
// 30.10.12 Class directory_entry
class GHC_FS_API_CLASS directory_entry
{
public:
// 30.10.12.1 constructors and destructor
directory_entry() noexcept = default;
directory_entry(const directory_entry&) = default;
directory_entry(directory_entry&&) noexcept = default;
#ifdef GHC_WITH_EXCEPTIONS
explicit directory_entry(const path& p);
#endif
directory_entry(const path& p, std::error_code& ec);
~directory_entry();
// assignments:
directory_entry& operator=(const directory_entry&) = default;
directory_entry& operator=(directory_entry&&) noexcept = default;
// 30.10.12.2 modifiers
#ifdef GHC_WITH_EXCEPTIONS
void assign(const path& p);
#endif
void assign(const path& p, std::error_code& ec);
#ifdef GHC_WITH_EXCEPTIONS
void replace_filename(const path& p);
#endif
void replace_filename(const path& p, std::error_code& ec);
#ifdef GHC_WITH_EXCEPTIONS
void refresh();
#endif
void refresh(std::error_code& ec) noexcept;
// 30.10.12.3 observers
const filesystem::path& path() const noexcept;
operator const filesystem::path&() const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
bool exists() const;
#endif
bool exists(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
bool is_block_file() const;
#endif
bool is_block_file(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
bool is_character_file() const;
#endif
bool is_character_file(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
bool is_directory() const;
#endif
bool is_directory(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
bool is_fifo() const;
#endif
bool is_fifo(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
bool is_other() const;
#endif
bool is_other(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
bool is_regular_file() const;
#endif
bool is_regular_file(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
bool is_socket() const;
#endif
bool is_socket(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
bool is_symlink() const;
#endif
bool is_symlink(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
uintmax_t file_size() const;
#endif
uintmax_t file_size(std::error_code& ec) const noexcept;
#ifndef GHC_OS_WEB
#ifdef GHC_WITH_EXCEPTIONS
uintmax_t hard_link_count() const;
#endif
uintmax_t hard_link_count(std::error_code& ec) const noexcept;
#endif
#ifdef GHC_WITH_EXCEPTIONS
file_time_type last_write_time() const;
#endif
file_time_type last_write_time(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
file_status status() const;
#endif
file_status status(std::error_code& ec) const noexcept;
#ifdef GHC_WITH_EXCEPTIONS
file_status symlink_status() const;
#endif
file_status symlink_status(std::error_code& ec) const noexcept;
bool operator<(const directory_entry& rhs) const noexcept;
bool operator==(const directory_entry& rhs) const noexcept;
bool operator!=(const directory_entry& rhs) const noexcept;
bool operator<=(const directory_entry& rhs) const noexcept;
bool operator>(const directory_entry& rhs) const noexcept;
bool operator>=(const directory_entry& rhs) const noexcept;
private:
friend class directory_iterator;
filesystem::path _path;
file_status _status;
file_status _symlink_status;
uintmax_t _file_size = 0;
#ifndef GHC_OS_WINDOWS
uintmax_t _hard_link_count = 0;
#endif
time_t _last_write_time = 0;
};
// 30.10.13 Class directory_iterator
class GHC_FS_API_CLASS directory_iterator
{
public:
class GHC_FS_API_CLASS proxy
{
public:
const directory_entry& operator*() const& noexcept { return _dir_entry; }
directory_entry operator*() && noexcept { return std::move(_dir_entry); }
private:
explicit proxy(const directory_entry& dir_entry)
: _dir_entry(dir_entry)
{
}
friend class directory_iterator;
friend class recursive_directory_iterator;
directory_entry _dir_entry;
};
using iterator_category = std::input_iterator_tag;
using value_type = directory_entry;
using difference_type = std::ptrdiff_t;
using pointer = const directory_entry*;
using reference = const directory_entry&;
// 30.10.13.1 member functions
directory_iterator() noexcept;
#ifdef GHC_WITH_EXCEPTIONS
explicit directory_iterator(const path& p);
directory_iterator(const path& p, directory_options options);
#endif
directory_iterator(const path& p, std::error_code& ec) noexcept;
directory_iterator(const path& p, directory_options options, std::error_code& ec) noexcept;
directory_iterator(const directory_iterator& rhs);
directory_iterator(directory_iterator&& rhs) noexcept;
~directory_iterator();
directory_iterator& operator=(const directory_iterator& rhs);
directory_iterator& operator=(directory_iterator&& rhs) noexcept;
const directory_entry& operator*() const;
const directory_entry* operator->() const;
#ifdef GHC_WITH_EXCEPTIONS
directory_iterator& operator++();
#endif
directory_iterator& increment(std::error_code& ec) noexcept;
// other members as required by 27.2.3, input iterators
#ifdef GHC_WITH_EXCEPTIONS
proxy operator++(int)
{
proxy p{**this};
++*this;
return p;
}
#endif
bool operator==(const directory_iterator& rhs) const;
bool operator!=(const directory_iterator& rhs) const;
private:
friend class recursive_directory_iterator;
class impl;
std::shared_ptr<impl> _impl;
};
// 30.10.13.2 directory_iterator non-member functions
GHC_FS_API directory_iterator begin(directory_iterator iter) noexcept;
GHC_FS_API directory_iterator end(const directory_iterator&) noexcept;
// 30.10.14 class recursive_directory_iterator
class GHC_FS_API_CLASS recursive_directory_iterator
{
public:
using iterator_category = std::input_iterator_tag;
using value_type = directory_entry;
using difference_type = std::ptrdiff_t;
using pointer = const directory_entry*;
using reference = const directory_entry&;
// 30.10.14.1 constructors and destructor
recursive_directory_iterator() noexcept;
#ifdef GHC_WITH_EXCEPTIONS
explicit recursive_directory_iterator(const path& p);
recursive_directory_iterator(const path& p, directory_options options);
#endif
recursive_directory_iterator(const path& p, directory_options options, std::error_code& ec) noexcept;
recursive_directory_iterator(const path& p, std::error_code& ec) noexcept;
recursive_directory_iterator(const recursive_directory_iterator& rhs);
recursive_directory_iterator(recursive_directory_iterator&& rhs) noexcept;
~recursive_directory_iterator();
// 30.10.14.1 observers
directory_options options() const;
int depth() const;
bool recursion_pending() const;
const directory_entry& operator*() const;
const directory_entry* operator->() const;
// 30.10.14.1 modifiers recursive_directory_iterator&
recursive_directory_iterator& operator=(const recursive_directory_iterator& rhs);
recursive_directory_iterator& operator=(recursive_directory_iterator&& rhs) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
recursive_directory_iterator& operator++();
#endif
recursive_directory_iterator& increment(std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
void pop();
#endif
void pop(std::error_code& ec);
void disable_recursion_pending();
// other members as required by 27.2.3, input iterators
#ifdef GHC_WITH_EXCEPTIONS
directory_iterator::proxy operator++(int)
{
directory_iterator::proxy proxy{**this};
++*this;
return proxy;
}
#endif
bool operator==(const recursive_directory_iterator& rhs) const;
bool operator!=(const recursive_directory_iterator& rhs) const;
private:
struct recursive_directory_iterator_impl
{
directory_options _options;
bool _recursion_pending;
std::stack<directory_iterator> _dir_iter_stack;
recursive_directory_iterator_impl(directory_options options, bool recursion_pending)
: _options(options)
, _recursion_pending(recursion_pending)
{
}
};
std::shared_ptr<recursive_directory_iterator_impl> _impl;
};
// 30.10.14.2 directory_iterator non-member functions
GHC_FS_API recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
GHC_FS_API recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
// 30.10.15 filesystem operations
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API path absolute(const path& p);
#endif
GHC_FS_API path absolute(const path& p, std::error_code& ec);
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API path canonical(const path& p);
#endif
GHC_FS_API path canonical(const path& p, std::error_code& ec);
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API void copy(const path& from, const path& to);
#endif
GHC_FS_API void copy(const path& from, const path& to, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API void copy(const path& from, const path& to, copy_options options);
#endif
GHC_FS_API void copy(const path& from, const path& to, copy_options options, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API bool copy_file(const path& from, const path& to);
#endif
GHC_FS_API bool copy_file(const path& from, const path& to, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API bool copy_file(const path& from, const path& to, copy_options option);
#endif
GHC_FS_API bool copy_file(const path& from, const path& to, copy_options option, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API void copy_symlink(const path& existing_symlink, const path& new_symlink);
#endif
GHC_FS_API void copy_symlink(const path& existing_symlink, const path& new_symlink, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API bool create_directories(const path& p);
#endif
GHC_FS_API bool create_directories(const path& p, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API bool create_directory(const path& p);
#endif
GHC_FS_API bool create_directory(const path& p, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API bool create_directory(const path& p, const path& attributes);
#endif
GHC_FS_API bool create_directory(const path& p, const path& attributes, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API void create_directory_symlink(const path& to, const path& new_symlink);
#endif
GHC_FS_API void create_directory_symlink(const path& to, const path& new_symlink, std::error_code& ec) noexcept;
#ifndef GHC_OS_WEB
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API void create_hard_link(const path& to, const path& new_hard_link);
#endif
GHC_FS_API void create_hard_link(const path& to, const path& new_hard_link, std::error_code& ec) noexcept;
#endif
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API void create_symlink(const path& to, const path& new_symlink);
#endif
GHC_FS_API void create_symlink(const path& to, const path& new_symlink, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API path current_path();
#endif
GHC_FS_API path current_path(std::error_code& ec);
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API void current_path(const path& p);
#endif
GHC_FS_API void current_path(const path& p, std::error_code& ec) noexcept;
GHC_FS_API bool exists(file_status s) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API bool exists(const path& p);
#endif
GHC_FS_API bool exists(const path& p, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API bool equivalent(const path& p1, const path& p2);
#endif
GHC_FS_API bool equivalent(const path& p1, const path& p2, std::error_code& ec) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API uintmax_t file_size(const path& p);
#endif
GHC_FS_API uintmax_t file_size(const path& p, std::error_code& ec) noexcept;
#ifndef GHC_OS_WEB
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API uintmax_t hard_link_count(const path& p);
#endif
GHC_FS_API uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcept;
#endif
GHC_FS_API bool is_block_file(file_status s) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API bool is_block_file(const path& p);
#endif
GHC_FS_API bool is_block_file(const path& p, std::error_code& ec) noexcept;
GHC_FS_API bool is_character_file(file_status s) noexcept;
#ifdef GHC_WITH_EXCEPTIONS
GHC_FS_API bool is_character_file(const path& p);
#endif
GHC_FS_API bool is_character_file(const path& p, std::error_code& ec) noexcept;
GHC_FS_API bool is_directory(file_status s) noexcept;