1390 Commits

Author SHA1 Message Date
Andrey Semashev
d829a46b31 Deprecated path construction/assignment/appending from container types.
Users are advised to use string types and iterators instead of containers
to construct/assign/append to paths.

In v4, the support for containers is removed.
2022-08-14 19:14:42 +03:00
Andrey Semashev
d58eb7a714 Switched gcc-9 to ubuntu-20.04 GHA CI image. 2022-08-14 17:50:38 +03:00
Andrey Semashev
5c8bcc2ba6 Updated copyright years. 2022-08-14 14:02:19 +03:00
Andrey Semashev
7fd03ddcf4 Replaced ubuntu-18.04 GHA CI images with containers.
Also use ubuntu-latest image for jobs that are running in a container.
2022-08-14 13:49:16 +03:00
Andrey Semashev
5864f397cc Fixed a missing include on POSIX systems that don't support *at APIs.
Fixes https://github.com/boostorg/filesystem/issues/250.
2022-08-12 13:01:07 +03:00
Andrey Semashev
476ca7b6c1 Fix weakly_canonical on Windows with long paths prefix.
During its operation, weakly_canonical would call status() on the path
consisting only from the root name of the input path. This would fail
with ERROR_INVALID_FUNCTION if the root name starts with the "\\?\" prefix,
as the root name path is not absolute.

To fix this, we don't check the status of the root name path (which is
not the correct check anyways as it tests the current directory on the
corresponding drive for existence, which is not what we want). Additionally,
avoid calling status() on the paths containing dot and dot-dot elements
during the weakly_canonical execution for the same reason - the "\\?\"
prefix disables most of the path processing in Windows APIs, including
dot and dot-dot elements resolution.

Fixes https://github.com/boostorg/filesystem/issues/247.
2022-08-10 04:57:21 +03:00
Andrey Semashev
1c4e1c01a6 Added a few tests involving Windows long paths. 2022-08-10 01:06:57 +03:00
Andrey Semashev
bf6d461cc7 Use a more appropriate variable name. 2022-08-10 00:36:41 +03:00
Andrey Semashev
bca612381a Moved the last release note to 1.81.0 release.
The relevant fix did not make it to 1.80.0 as it came too late during
the release process.
2022-08-09 20:42:33 +03:00
Olavo Belloc
9c9d127bdd Limit the buffer size for compatibility with previous versions of Windows
The reported error was reproduced on Windows 7 and 8.1, but not on an early
version of Windows 10 (2004).

Closes https://github.com/boostorg/filesystem/pull/246.
Likely fixes https://github.com/boostorg/filesystem/issues/245.
2022-08-08 17:22:18 +03:00
Andrey Semashev
ea22e76552 Updated protection of remove_all against CVE-2022-21658 on Windows.
This follows up the previous update for POSIX.

The new implementation of remove_all on Windows Vista and later uses
NtCreateFile internal function in order to open files relative to
a previously opened directory handle, similar to POSIX openat.
Furthermore, querying file status and removing the file is now also
done through file handles to avoid performing path resolutions.

Closes https://github.com/boostorg/filesystem/issues/224.
boost-1.80.0
2022-07-24 02:52:27 +03:00
Andrey Semashev
36cf9aaf81 Updated protection of remove_all against CVE-2022-21658 on POSIX.
The previous implementation could still allow for following symlinks
while remove_all is running if a directory was replaced with a symlink
higher in the tree than remove_all is currently processing. This was
reported here:

https://github.com/boostorg/filesystem/issues/224#issuecomment-1183738097

The solution is to use POSIX.1-2008 *at APIs to prevent symlink resolution
higher in the directory tree while iterating over the subtree in remove_all.
This required updating the directory iterator construction interface so that
it is possible to pass the base directory fd and return fd of the directory
used by the iterator. This is done via platform-specific params that are
currently defined only for POSIX. Additionally, status, symlink_status and
remove were extended to accept the base directory fd as well.

Other systems, including Windows, remain vulnerable.

Related to https://github.com/boostorg/filesystem/issues/224.
2022-07-17 04:00:07 +03:00
Andrey Semashev
014216f3e5 Replaced literal zeros with NULL in headers.
This is for better code readability and to possibly silence compiler
warnings.
2022-07-17 03:57:48 +03:00
Andrey Semashev
561b964c2e Fixed copy_file sendfile fallback if copy_file_range fails with ENOSYS.
The copy_file_range implementation of copy_file used to set incorrect sendfile
fallback if copy_file_range failed with ENOSYS. The fallback would skip
checking the filesystem type for whether it is supported by sendfile.

Also, wrapped sendfile and copy_file_range implementations in structs to
silence clang warnings about using C++11 feature in C++03 mode: the functions
are in an anonymous namespace and therefore have internal linkage, and
pointers to such functions are not allowed to be used in non-type template
parameters in C++03.
2022-07-17 03:57:04 +03:00
Andrey Semashev
fd3af54208 Disable warnings about unused functions.
Clang triggers -Wunused-function for get_dir_itr_imp_extra_data, which
may or may not be used depending on the target platform. Better to disable
the warning rather than add macro checks.
2022-07-17 03:26:56 +03:00
Andrey Semashev
0601c887b7 Switch to macos-11 GHA image as macos-10.15 is deprecated. 2022-07-17 03:26:39 +03:00
Andrey Semashev
945c2ecf11 Worked around a compilation problem on RTEMS.
Closes https://github.com/boostorg/filesystem/pull/240.
2022-07-07 23:43:07 +03:00
Andrey Semashev
7cd11c770b Moved header that is used in tests to tests. 2022-07-07 23:34:35 +03:00
Andrey Semashev
e9c845db2f Include header.hpp/footer.hpp in .cpp files to silence warnings.
Related to https://github.com/boostorg/filesystem/pull/241.
2022-07-07 23:30:16 +03:00
Andrey Semashev
fcc11010a5 Added VS2022 job and C++20 and C++latest jobs to AppVeyor CI. boost-1.80.0.beta1 2022-06-06 02:52:16 +03:00
Guus Waals
11b28f0ec0 Flip default Emscripten default usage of WASI
When using Emscripten filesystem now links against the POSIX functions
2022-05-15 18:43:42 +03:00
Guus Waals
c33862dd91 Fix logic error in comment 2022-05-15 18:43:42 +03:00
Guus Waals
4d88f86765 Fix standalone wasm define. Rename define.
- Add cmake option to turn WASI API on/off
- Rename BOOST_STANDALONE_WASM => BOOST_FILESYSTEM_STANDALONE_WASM
2022-05-15 18:43:42 +03:00
Guus Waals
ef54f768b8 Implement on top of posix API for emscripten 2022-05-15 18:43:42 +03:00
Andrey Semashev
1f2e37cae5 Added a workaround for GetFileInformationByHandleEx error in dir iterator.
Reproduce the workaround for GetFileInformationByHandleEx returning
ERROR_INVALID_PARAMETER when querying FILE_ATTRIBUTE_TAG_INFO on FAT/exFAT
filesystems in directory iterator construction.

Fixes https://github.com/boostorg/filesystem/issues/237.
2022-05-15 17:20:24 +03:00
Andrey Semashev
15249ba87b Added a workaround for (symlink_)status failing on Windows.
Apparently, GetFileInformationByHandleEx(FileAttributeTagInfo) fails
with ERROR_INVALID_PARAMETER on FAT/exFAT filesystems, which used to
be interpreted as "file not found" result in (symlink_)status(). The
file is clearly present since it was successfully opened before,
and the error is presumably because the filesystem does not support
reparse points and cannot return a ReparseTag.

Check that error code and also ERROR_NOT_SUPPORTED for good measure
and fall back to the legacy code path that works for FAT/exFAT.

Fixes https://github.com/boostorg/filesystem/issues/236.
2022-05-12 16:21:52 +03:00
Andrey Semashev
2896908264 Trim spaces. 2022-05-10 14:54:31 +03:00
Andrey Semashev
a187a9f10f Added symlink_status test for a system directory. 2022-05-09 20:04:23 +03:00
Andrey Semashev
4bdac43bd9 Use GetFileAttributesW in symlink_status if CreateFileW fails.
For some system files and folders like "System Volume Information"
CreateFileW fails with ERROR_ACCESS_DENIED while GetFileAttributesW
succeeds. GetFileAttributesW doesn't allow to discover whether the
file is a symlink or some other kind of a reparse point, so this
fallback will only work for files that are not reparse points,
symlinks or not. For reparse points continue to report error.

Closes https://github.com/boostorg/filesystem/issues/234.
2022-05-09 20:00:50 +03:00
Andrey Semashev
d732ab006a Explicitly specify FILE_READ_ATTRIBUTES when optning files to read attributes. 2022-05-09 19:13:32 +03:00
Andrey Semashev
88b0be807e Corrected a typo in a comment. 2022-04-06 23:15:27 +03:00
Andrey Semashev
aeb5318cd0 Silenced gcc warnings about non-virtual destructor in codecvt_error_cat.
Closes https://github.com/boostorg/filesystem/issues/232.
2022-04-06 20:12:08 +03:00
Andrey Semashev
123fe5faa6 Disable statx syscall usage on Android prior to 11.0.
Even though the syscall number is defined in kernel headers, the syscall
is blacklisted by seccomp in runtime.

Note that Android 11 also introduces the libc wrapper for statx, so
effectively the library will always use the libc wrapper on Android.

Reported in https://github.com/boostorg/filesystem/issues/229.
boost-1.79.0 boost-1.79.0.beta1
2022-03-02 14:19:25 +03:00
Andrey Semashev
7403ffca00 Added support for POSIX semantics for file removal on Windows.
Windows 10 1709 and later support POSIX semantics for removing files,
which means the file name is removed from the filesystem namespace as
soon as the file is marked for deletion. This makes opening the file
afterwards impossible, and allows creating a new file with the same
name, even if the deleted file is still open and in use.

The implementation uses runtime detection of the feature in the OS.
We are also using two more implementations for file removal: one that
employs the more recent FILE_DISPOSITION_FLAG_IGNORE_READONLY_ATTRIBUTE
flag (available since Windows 10 1809), and FILE_DISPOSITION_INFO
structure (supported since Windows Vista). The former allows to optimize
removal of read-only files, and the latter allows to make file deletion
atomic (i.e. not prone to failure if the file is replaced on the filesystem
while the operation is executing). The implementation is chosen in
runtime, depending on which one succeeds removing a file.

Also, added support for deleting read-only directories, in addition
to non-directory files, and simplified code a little.

Closes https://github.com/boostorg/filesystem/issues/216.
2022-03-01 11:09:08 +03:00
Andrey Semashev
97722a3107 Reimplemented status() and symlink_status() in terms of handles on Windows.
Using handles allows to reduce the number of system calls and avoids requesting
reparse point info, if the file is one. This should improve performance.
2022-02-21 19:18:49 +03:00
Andrey Semashev
f7930053c8 Corrected error handling and aded checks for exceptions. 2022-02-21 14:38:20 +03:00
Andrey Semashev
f2b09fc0a3 Make path::replace_extension version-dependent.
We have changed v4 path::extension() to not return the filename if
it starts with a dot, but we have not made path::replace_extension
version-dependent, which made v3 behave like v4. Fixing this,
and optimizing v4 path::replace_extension in the process.
2022-02-21 01:06:47 +03:00
Andrey Semashev
733eacfd59 Put Boost.Atomic dependency on a separate line in CMakeLists.txt.
Works around https://github.com/boostorg/cmake/issues/17.
2022-02-20 23:51:14 +03:00
Andrey Semashev
826edcc3e5 Fixed compilation. 2022-02-15 04:19:53 +03:00
Andrey Semashev
2b35bc8f11 Check if the handle refers to a directory in dir_itr_create on Windows.
Also, make a more robust check whether the handle refers to a symlink
in case if GetFileInformationByHandleEx is not available. If it is
not a symlink, but some other type of a reparse point, continue
processing it as if it is a regular directory.

Also, in remove_all_impl, check whether creating a directory iterator
fails due to the file not being a directory. Interpret this the same
way as with ELOOP - the error indicates that the directory was replaced
with some other kind of file between querying its type and creating
the directory iterator. Retry the operation.
2022-02-15 03:57:01 +03:00
Andrey Semashev
f803579e53 Reworked directory_iterator on Windows to add support for O_NOFOLLOW.
directory_iterator implementation now explicitly opens a directory
handle and relies on GetFileInformationByHandleEx or NtQueryDirectoryFile
to query information of the files in the directory. With
GetFileInformationByHandleEx, there are at least three ways to request
the information, each supported on different Windows versions and
different filesystems and providing different sets of information.
We support all three (FILE_ID_BOTH_DIR_INFO, FILE_FULL_DIR_INFO and
FILE_ID_EXTD_DIR_INFO), and we fall back to older ones if the newer
ones are not supported. GetFileInformationByHandleEx is available
since Windows Vista.

NtQueryDirectoryFile is an NT API that provides similar information to
GetFileInformationByHandleEx, but exists since at least Windows XP,
but some sources state it has existed since NT 4.0. This API is now
used when GetFileInformationByHandleEx is not available and it replaces
FindFirstFileW/FindNextFileW/FindClose based implementation (which
supposedly uses NtQueryDirectoryFile internally). Being an NT API,
we have to handle NTSTATUS error codes returned from it, so we had to
refactor unique path code that also used NTSTATUS previously.

Opening a directory handle explicitly allows to support O_NOFOLLOW
semantics on Windows, as we are able to prevent CreateFile from
following to the reparse point target. This is needed for remove_all
implementation to fix CVE-2022-21658. Similar to POSIX, remove_all_impl
on Windows now requests the directory iterator to not follow symlinks
when it is used to dive into a directory.

FindFirstFileW/FindNextFileW/FindClose based implementation is still
preserved for now for Windows CE, as it is unlikely to support neither
GetFileInformationByHandleEx nor NtQueryDirectoryFile. Given that
Windows CE has been untested for many years and is probably broken
anyway, its support is now declared deprecated. The related code,
including Find*-based directory iterator, will be removed in a
future release.

Closes https://github.com/boostorg/filesystem/issues/224.

And a couple cleanup changes:

 - Since we now may use GetFileInformationByHandleEx, we are now using
   it to query FILE_ATTRIBUTE_TAG_INFO for testing whether a reparse
   point is a symlink.

 - In resize_file_impl, we now specify all sharing flags to allow the
   operation to succeed if the file is already opened by someone.
2022-02-14 15:49:59 +03:00
Andrey Semashev
0346889a48 Added a cast to suppress MSVC warning of a possible truncation. 2022-02-14 04:50:52 +03:00
Andrey Semashev
47a4e69c79 Added a deprecated tag in release notes. 2022-02-08 23:31:28 +03:00
Andrey Semashev
266e1ac892 Moved string_file.hpp tests to deprecated tests.
Turns out string_file.hpp was tested in operations_unit_test, though not
included directly. Since string_file.hpp contents are disabled when the
test is compiled (as any other deprecated functionality), the test failed
to compile.

Moved the string_file.hpp test to deprecated_test, which explicitly enables
deprecated functionality. Also, include string_file.hpp in filesystem.hpp
if explicitly requested by defining BOOST_FILESYSTEM_DEPRECATED.
2022-02-08 22:45:52 +03:00
Andrey Semashev
f37d1f0db6 Deprecated string_file.hpp.
The header was not documented or tested, and the utilities it contains
are out of scope of the library.
2022-02-08 21:18:30 +03:00
Andrey Semashev
f6444522d7 Added checks against read/write size overflows and casts to silence warnings.
Closes https://github.com/boostorg/filesystem/issues/228.
2022-02-08 21:04:55 +03:00
Andrey Semashev
43f213fbd8 Removed unified initializers for global initializer objects.
This was supposed to be a workaround for clang bug that required an
initializer for global constant objects without a user-defined constructor,
but the initializer classes do have user-defined constructors, so this
workaround should not be needed. Removing it simplifies code a bit.
2022-02-08 15:30:27 +03:00
Andrey Semashev
edc2d8e4da Added early initialization of codecvt error category.
Marked codecvt error category constructor constexpr and defined
it unconditionally to work around clang bug in XCode 8: the compiler
requires a user-defined constructor to initialize the static const object
of the category.

When constexpr is not available (more precisely, when it is not enabled
by Boost.System), try to dynamic-initialize the category instance early.
For MSVC, invoke codecvt_error_category() from the early global initialization
routine in path.cpp. For other compilers, use a global initializer, possibly
augmented with init_priority attribute.

Closes https://github.com/boostorg/filesystem/issues/227.
2022-02-08 15:13:43 +03:00
Andrey Semashev
0ab2d5d309 Extracted Boost library include paths collection to a CMake module.
Also, save the collected paths to a global property to avoid potentially
scanning the filesystem in every library that needs these paths.
2022-02-04 14:41:47 +03:00
Andrey Semashev
dbec3baaad Use O_NONBLOCK instead of O_NDELAY as it is the flag defined by POSIX. 2022-02-03 20:58:42 +03:00