summaryrefslogtreecommitdiffstats
path: root/libcxx/src/experimental/filesystem
Commit message (Collapse)AuthorAgeFilesLines
* Implement <filesystem>Eric Fiselier2018-07-274-2597/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements the <filesystem> header and uses that to provide <experimental/filesystem>. Unlike other standard headers, the symbols needed for <filesystem> have not yet been placed in libc++.so. Instead they live in the new libc++fs.a library. Users of filesystem are required to link this library. (Also note that libc++experimental no longer contains the definition of <experimental/filesystem>, which now requires linking libc++fs). The reason for keeping <filesystem> out of the dylib for now is that it's still somewhat experimental, and the possibility of requiring an ABI breaking change is very real. In the future the symbols will likely be moved into the dylib, or the dylib will be made to link libc++fs automagically). Note that moving the symbols out of libc++experimental may break user builds until they update to -lc++fs. This should be OK, because the experimental library provides no stability guarantees. However, I plan on looking into ways we can force libc++experimental to automagically link libc++fs. In order to use a single implementation and set of tests for <filesystem>, it has been placed in a special `__fs` namespace. This namespace is inline in C++17 onward, but not before that. As such implementation is available in C++11 onward, but no filesystem namespace is present "directly", and as such name conflicts shouldn't occur in C++11 or C++14. llvm-svn: 338093
* Be more consistent about which bool value means an error occurredEric Fiselier2018-07-261-6/+6
| | | | llvm-svn: 338002
* Cleanup the last_write_time internalsEric Fiselier2018-07-262-17/+26
| | | | llvm-svn: 338001
* Fix attribute placement WRT extern CEric Fiselier2018-07-261-2/+2
| | | | llvm-svn: 337999
* [libc++] Add hack to allow ubsan to work w/o compiler-rt (__muloti4 is ↵Eric Fiselier2018-07-261-0/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | undefined) Summary: Using int128_t with UBSAN causes link errors unless compiler-rt is providing the runtime library. Specifically ubsan generates calls to __muloti4 but libgcc doesn't provide a definition. In order to avoid this, and allow users to continue using sanitized versions of libc++, this patch introduces a hack. It adds a cribbed version of the compiler-rt builtin to the libc++ filesystem sources. I don't think this approach will work in the long run, but it seems OK for now. Also see: https://bugs.llvm.org/show_bug.cgi?id=30643 https://bugs.llvm.org/show_bug.cgi?id=16404 Reviewers: mclow.lists, ldionne, rsmith, jyknight, echristo Reviewed By: echristo Subscribers: dberris, cfe-commits Differential Revision: https://reviews.llvm.org/D49828 llvm-svn: 337990
* [libc++] Follow-up to r337968: use an explicit cast as suggested by EricAlex Lorenz2018-07-251-2/+4
| | | | llvm-svn: 337984
* Fix GCC build in C++14 w/o c++14 constexprEric Fiselier2018-07-251-1/+1
| | | | llvm-svn: 337974
* Fix failing test under C++14Eric Fiselier2018-07-251-2/+2
| | | | llvm-svn: 337970
* [libc++] Follow-up to r337960: specify lambda's return type to avoidAlex Lorenz2018-07-251-1/+1
| | | | | | | | | | | -Wc++11-narrowing warning on Darwin The internal CI produced the following diagnostic: error: non-constant-expression cannot be narrowed from type 'long long' to '__darwin_suseconds_t' (aka 'int') in initializer list [-Wc++11-narrowing] struct ::timeval ConvertedTS[2] = {{TS[0].tv_sec, Convert(TS[0].tv_nsec)}, ^~~~~~~~~~~~~~~~~~~~~~ llvm-svn: 337968
* Make <experimental/filesystem> compile with gcc 4.8.5Eric Fiselier2018-07-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Patch by Victor Zverovich. This fixes an error when compiling `<experimental/filesystem>` with gcc 4.8.5: ``` .../libcxx/src/experimental/filesystem/filesystem_common.h:137:34: error: redeclaration ‘T std::experimental::filesystem::v1::detail::{anonymous}::error_value() [with T = bool]’ d iffers in ‘constexpr’ constexpr bool error_value<bool>() { ^ .../libcxx/src/experimental/filesystem/filesystem_common.h:133:3: error: from previous declaration ‘T std::experimental::filesystem::v1::detail::{anonymous}::error_value() [with T = bool]’ T error_value(); ^ ``` Reviewed as https://reviews.llvm.org/D49813 llvm-svn: 337962
* [libc++] Use __int128_t to represent file_time_type.Eric Fiselier2018-07-252-159/+186
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The ``file_time_type`` time point is used to represent the write times for files. Its job is to act as part of a C++ wrapper for less ideal system interfaces. The underlying filesystem uses the ``timespec`` struct for the same purpose. However, the initial implementation of ``file_time_type`` could not represent either the range or resolution of ``timespec``, making it unsuitable. Fixing this requires an implementation which uses more than 64 bits to store the time point. I primarily considered two solutions: Using ``__int128_t`` and using a arithmetic emulation of ``timespec``. Each has its pros and cons, and both come with more than one complication. However, after a lot of consideration, I decided on using `__int128_t`. This patch implements that change. Please see the [FileTimeType Design Document](http://libcxx.llvm.org/docs/DesignDocs/FileTimeType.html) for more information. Reviewers: mclow.lists, ldionne, joerg, arthur.j.odwyer, EricWF Reviewed By: EricWF Subscribers: christof, K-ballo, cfe-commits, BillyONeal Differential Revision: https://reviews.llvm.org/D49774 llvm-svn: 337960
* Fix bugs in create_directory implementation.Eric Fiselier2018-07-251-2/+4
| | | | | | | | | | | | | | Libc++ was incorrectly reporting an error when the target of create_directory already exists, but was not a directory. This behavior is not specified in the most recent standard, which says no error should be reported. Additionally, libc++ failed to report an error when the attribute directory path didn't exist or didn't name a directory. This has been fixed as well. Although it's not clear if we should call status or symlink_status on the attribute directory. This patch chooses to still call status. llvm-svn: 337888
* Make <experimental/filesystem> explicitly require C++11.Eric Fiselier2018-07-251-2/+0
| | | | | | | | | | | | | | Previously the <experimental/filesystem> didn't guard its contents in any dialect. However, the implementation implicitly requires at least C++11, and the tests have always been marked unsupported in C++03. This patch puts a header guard around the contents to avoid exposing them before C++11. Additionally, it replaces all of the usages of _NOEXCEPT or _LIBCPP_CONSTEXPR with the keyword directly, since we can expect the compiler to implement those by now. llvm-svn: 337884
* Ensure path::iterator and PathParser share the same enumeration values.Eric Fiselier2018-07-251-11/+10
| | | | | | | | | | | | To avoid exposing implementation details, path::iterator and PathParser both implicitly used the same set of values to represent the state, but they were defined twice. This could have lead to a mismatch occuring. This patch moves all of the parser state values into the filesystem header and changes PathParser to use those value to avoid this. llvm-svn: 337883
* Handle DT_UNKNOWN correctly during directory iteration.Eric Fiselier2018-07-231-1/+4
| | | | | | | | | | Unlike stat and lstat, where unknown really means we know it's something weird, during directory iteration DT_UNKNOWN simply means that the underlying FS doesn't support the dirent::dt_type field. This patch fixes libc++ to correctly set the cache to empty when DT_UNKNOWN is reported. llvm-svn: 337768
* Recommit "Use possibly cached directory entry values when performing ↵Eric Fiselier2018-07-231-3/+4
| | | | | | | | | | | | | recursive directory iteration." The initial patch didn't correctly handle systems when the dirent struct didn't provide the d_type member. Specifically it set the cache to the incorrect state, and claimed it was partially populated. The updated version of this change correctly handles setting up the cache when the file type is not known (aka file_type::none). llvm-svn: 337765
* Revert "Use possibly cached directory entry values when performing recursive ↵Eric Fiselier2018-07-231-2/+2
| | | | | | | | directory iteration." This reverts commit 04ce4aef00d3ee508327f6cf7bf1b1d200ab6238. llvm-svn: 337749
* Cleanup unnecessary conversions in filesystem.Eric Fiselier2018-07-231-2/+2
| | | | llvm-svn: 337685
* Cleanup name qualification in the filesystem internals.Eric Fiselier2018-07-233-118/+118
| | | | | | | | In most cases there is no reason why the filesystem internals use the qualifier std:: or _VSTD::. This patch removes the unneeded qualifiers, making the sources files more consistent llvm-svn: 337684
* Use possibly cached directory entry values when performing recursive ↵Eric Fiselier2018-07-231-2/+2
| | | | | | directory iteration. llvm-svn: 337669
* Work around various GCC 4.9 build errorsEric Fiselier2018-07-232-9/+14
| | | | llvm-svn: 337665
* Implement filesystem_error::what() and improve reporting.Eric Fiselier2018-07-233-373/+494
| | | | | | | | | | | This patch implements the `what()` for filesystem errors. The message includes the 'what_arg', any paths that were specified, and the error code message. Additionally this patch refactors how errors are created, making it easier to report them correctly. llvm-svn: 337664
* Workaround bug in GCC trunk.Eric Fiselier2018-07-221-4/+4
| | | | | | | | | | For some reason GCC ToT is failing to deduce the auto type for a static data member from its initializer in some cases. Though I'm sure the bug will be short lived, there is a trivial workaround for it. So we might as well get the bot passing again. llvm-svn: 337661
* Harden copy_file even more.Eric Fiselier2018-07-221-5/+7
| | | | | | | | | | | This patch removes the O_CREAT open flag when we first attempt to open the destination file but we expect it to already exist. This theoretically avoids the possibility that it was removed between when we first stat'ed it, and when we attempt to open it. llvm-svn: 337659
* Implement a better copy_file.Eric Fiselier2018-07-221-79/+279
| | | | | | | | | | | | | | | | | | | | This patch improves both the performance, and the safety of the copy_file implementation. The performance improvements are achieved by using sendfile on Linux and copyfile on OS X when available. The TOCTOU hardening is achieved by opening the source and destination files and then using fstat to check their attributes to see if we can copy them. Unfortunately for the destination file, there is no way to open it without accidentally creating it, so we first have to use stat to determine if it exists, and if we should copy to it. Then, once we're sure we should try to copy, we open the dest file and ensure it names the same entity we previously stat'ed. llvm-svn: 337649
* adjust incorrect commentEric Fiselier2018-07-201-1/+2
| | | | llvm-svn: 337532
* Use _LIBCPP_UNREACHABLE to convince GCC that non-void functions actually ↵Eric Fiselier2018-07-201-2/+2
| | | | | | always return llvm-svn: 337519
* cleanup test assertion inside libraryEric Fiselier2018-07-201-6/+0
| | | | llvm-svn: 337517
* [libc++] Implement Directory Entry Caching -- Sort of.Eric Fiselier2018-07-203-202/+393
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch implements directory_entry caching *almost* as specified in P0317r1. However, I explicitly chose to deviate from the standard as I'll explain below. The approach I decided to take is a fully caching one. When `refresh()` is called, the cache is populated by calls to `stat` and `lstat` as needed. During directory iteration the cache is only populated with the `file_type` as reported by `readdir`. The cache can be in the following states: * `_Empty`: There is nothing in the cache (likely due to an error) * `_IterSymlink`: Created by directory iteration when we walk onto a symlink only the symlink file type is known. * `_IterNonSymlink`: Created by directory iteration when we walk onto a non-symlink. Both the regular file type and symlink file type are known. * `_RefreshSymlink` and `_RefreshNonSymlink`: A full cache created by `refresh()`. This case includes dead symlinks. * `_RefreshSymlinkUnresolved`: A partial cache created by refresh when we fail to resolve the file pointed to by a symlink (likely due to permissions). Symlink attributes are cached, but attributes about the linked entity are not. As mentioned, this implementation purposefully deviates from the standard. According to some readings of the specification, and the Windows filesystem implementation, the constructors and modifiers which don't pass an `error_code` must throw when the `directory_entry` points to a entity which doesn't exist. or when attribute resolution fails for another reason. @BillyONeal has proposed a more reasonable set of requirements, where modifiers other than refresh ignore errors. This is the behavior libc++ currently implements, with the expectation some form of the new language will be accepted into the standard. Some additional semantics which differ from the Windows implementation: 1. `refresh` will not throw when the entry doesn't exist. In this case we can still meet the functions specification, so we don't treat it as an error. 2. We don't clear the path name when a constructor fails via refresh (this will hopefully be changed in the standard as well). It should be noted that libstdc++'s current implementation has the same behavior as libc++, except for point (2). If the changes to the specification don't get accepted, we'll be able to make the changes later. [1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0317r1.html Reviewers: mclow.lists, gromer, ldionne, aaron.ballman Subscribers: BillyONeal, christof, cfe-commits Differential Revision: https://reviews.llvm.org/D49530 llvm-svn: 337516
* Implement filesystem NB comments, relative paths, and related issues.Eric Fiselier2018-04-022-476/+647
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a fairly large patch that implements all of the filesystem NB comments and the relative paths changes (ex. adding weakly_canonical). These issues and papers are all interrelated so their implementation couldn't be split up nicely. This patch upgrades <experimental/filesystem> to match the C++17 spec and not the published experimental TS spec. Some of the changes in this patch are both API and ABI breaking, however libc++ makes no guarantee about stability for experimental implementations. The major changes in this patch are: * Implement NB comments for filesystem (P0492R2), including: * Implement `perm_options` enum as part of NB comments, and update the `permissions` function to match. * Implement changes to `remove_filename` and `replace_filename` * Implement changes to `path::stem()` and `path::extension()` which support splitting examples like `.profile`. * Change path iteration to return an empty path instead of '.' for trailing separators. * Change `operator/=` to handle absolute paths on the RHS. * Change `absolute` to no longer accept a current path argument. * Implement relative paths according to NB comments (P0219r1) * Combine `path.cpp` and `operations.cpp` since some path functions require access to the operations internals, and some fs operations require access to the path parser. llvm-svn: 329028
* Implement filesystem::perm_options specified in NB comments.Eric Fiselier2018-03-261-8/+11
| | | | | | | | | | The NB comments for filesystem changed permissions and added a new enum `perm_options` which control how the permissions are applied. This implements than NB resolution llvm-svn: 328476
* Fix building libc++ with the macOS 10.13 SDK with -mmacosx-version-min=10.12 ↵Nico Weber2018-02-061-4/+29
| | | | | | | | | | | | | | | | | or lower. The 10.13 SDK always defines utimensat() (with an availability(macosx=10.13) annotation) and unconditionally defines UTIME_OMIT, so use the compile-time availability macros on Apple platforms instead. For people statically linking libc++, it might make sense to also provide an opt-in option for using __builtin_available() to dynamically check for the OS version, but for now let's do the smallest thing needed to unbreak the build. Based on a patch by Eric Fiselier <eric@efcs.ca>: https://reviews.llvm.org/D34249 Fixes PR33469. llvm-svn: 324385
* Address LWG 2849 and fix missing failure condition in copy_file.Eric Fiselier2018-02-041-10/+20
| | | | | | | Previously copy_file didn't handle the case where the input and output were the same file. llvm-svn: 324187
* Make std::experimental::filesystem::remove and remove_all return false or 0 ↵Ekaterina Vaartis2018-01-111-4/+11
| | | | | | | | if the file doesn't exist Differential Revision: https://reviews.llvm.org/D41830 llvm-svn: 322293
* [libcxx] Suppress unused warning on apple.Don Hinton2017-12-251-0/+1
| | | | | | | | | | | | | | | | Summary: This warning is already suppressed on non-apple platforms, so this change just suppresses it on apple as well. Reviewers: EricWF, lichray Reviewed By: lichray Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D41248 llvm-svn: 321435
* Fix PR35078 - recursive directory iterator's increment method throws ↵Eric Fiselier2017-10-301-9/+28
| | | | | | | | | | | | | | incorrectly. The guts of the increment method for recursive_directory_iterator was failing to pass an error code object to calls to status/symlink_status, which can throw under certain conditions. This patch fixes the issues by correctly propagating the error codes. However the noexcept still needs to be removed from the signature, as mentioned in LWG 3014, but that change will be made in a separate commit. llvm-svn: 316939
* Rename a couple variables to eliminate a shadow warning. No functionality changeMarshall Clow2017-08-021-11/+11
| | | | llvm-svn: 309881
* Fix filesystem build on platforms with weird time_t types.Eric Fiselier2017-07-082-144/+181
| | | | | | | | | | | | | | 32-bit powerpc provides a 64 bit time_t type and older ppc64 systems provide time_t as a floating point type. This caused problems when building operations.cpp since operations.cpp contained compile time tests for conversions between time_t and filesystem time type. When these tests failed they caused the libc++ build to fail as well. This is unfortunate. This patch moves the tests out of the source file and into the test suite. It also expands the tests to allow testing of the weird time_t configurations on all platforms. llvm-svn: 307461
* Implement LWG 2937 - equivalent("dne", "exists") is not an errorEric Fiselier2017-07-051-6/+9
| | | | | | | | | | | | | | This patch speculatively implements the PR for LWG 2937, which fixes two issues with equivalent. (1) It makes equivalent("dne", "exists") an error. Previously only equivalent("dne", "dne") was an error and the former case was not (it returned false). Now equivalent reports an error when either input doesn't exist. (2) It makes equivalent(p1, p2) well-formed when `is_other(p1) && is_other(p2)`. Previously this was an error, but there is seemingly no reason why it should be on POSIX system. llvm-svn: 307117
* path: Use string_view_t consistentlyDuncan P. N. Exon Smith2017-06-191-2/+3
| | | | | | | | | Most of filesystem/path.cpp uses string_view_t. This fixes the two spots that use string_view directly. https://reviews.llvm.org/D34332 llvm-svn: 305661
* Fix potential bug by casting to the POSIX specified typeEric Fiselier2017-06-161-1/+1
| | | | llvm-svn: 305549
* Fix remaining GCC 7 build warningsEric Fiselier2017-05-051-2/+2
| | | | llvm-svn: 302283
* Fix bugs in filesystem detected by _LIBCPP_ASSERT.Eric Fiselier2017-02-072-7/+16
| | | | | | | | | | | | | | | | | Recently I turned on libc++'s debug mode assertions when CMake is configured with -DLIBCXX_ENABLE_ASSERTIONS=ON. This change exposed assertion failures caused by bugs in filesystem. This patch fixes those failures. The first bug was that `PathParser` was using front()/back() on empty string views in order to get the address of the character. However this is UB on empty strings. Those operations now use data() to obtain the pointer. The second bug was that directory_iterator attempted to capture errno when it was unset and there was an assertion to detect this. llvm-svn: 294360
* filesystem: return the constructed objectSaleem Abdulrasool2017-02-071-5/+2
| | | | | | | | This really should get identified properly by the compiler to convert to a NVRO, but compress the code anyways. This makes the implementation identical to directory_iterator.cpp llvm-svn: 294270
* filesystem: fix n4100 conformance for `temp_directory_path`Saleem Abdulrasool2017-02-051-14/+19
| | | | | | | | | N4100 states that an error shall be reported if `!exists(p) || !is_directory(p)`. We were missing the first half of the conditional. Invert the error and normal code paths to make the code easier to follow. llvm-svn: 294127
* Recommit [libcxx] Never use <cassert> within libc++Eric Fiselier2017-02-041-4/+0
| | | | | | | | | | It is my opinion that libc++ should never use `<cassert>`, including in the `dylib`. This patch remove all uses of `assert` from within libc++ and replaces most of them with `_LIBCPP_ASSERT` instead. Additionally this patch turn `LIBCXX_ENABLE_ASSERTIONS` off by default, because the standard library should not be aborting user programs unless explicitly asked to. llvm-svn: 294107
* experimental: avoid using raw _WIN32 in filesystemSaleem Abdulrasool2017-01-301-5/+6
| | | | | | | Use the _LIBCPP_WIN32API macro instead of _WIN32 checks. Fix a missed renaming for style conformance. llvm-svn: 293543
* experimental: port directory_iterator to WindowsSaleem Abdulrasool2017-01-301-0/+72
| | | | | | | | | This adds a basic first cut implementation for directory_iterator on Windows. It uses the FindFirstFile/FindNextFile which has the same restrictions as opendir/readdir where there exists a TOCTOU race condition. llvm-svn: 293531
* experimental: add missing file headerSaleem Abdulrasool2017-01-301-0/+9
| | | | | | | The directory_iterator implementation file was missing the file header. Add one. NFC. llvm-svn: 293530
* experimental: inline single use of a typedefSaleem Abdulrasool2017-01-301-4/+1
| | | | | | | The typedef is not particularly long, and used in exactly one location. Just spell it out at the site. NFC. llvm-svn: 293450
OpenPOWER on IntegriCloud