39 Commits

Author SHA1 Message Date
Andrey Semashev
59433a9984 Added max CMake version 3.16.
This should resolve CMake warnings.
2024-12-15 19:23:28 +03:00
Andrey Semashev
dc94c80f4b Specify _WIN32_WINNT=0x0A00 in build system scripts to target Windows 10. 2024-09-16 23:55:58 +03:00
Andrey Semashev
6f174ba143 Moved Boost.Core to private dependencies in CMakeLists.txt. 2024-02-20 04:10:50 +03:00
Andrey Semashev
e9621c0585 Reworked directory iterator construction with parameters.
Instead of passing a base directory fd, pass the directory fd to iterate over.
This simplifies code a little and makes it closer to Windows version.

Also, use unique_fd from Boost.Scope instead of a custom fd wrapper. Also
added handling of EINTR returned from open/openat in more places.
2024-02-19 02:57:16 +03:00
Andrey Semashev
3b55b7b0d3 Use C++11 language features unconditionally.
Use nullptr, rvalue references, default function template parameters,
deleted/defaulted functions, noexcept, final, override and scoped enums.

Don't use constexpr yet, as it would raise MSVC requirement.
2024-01-13 19:32:42 +03:00
Andrey Semashev
d7e6e3100a Added storage preallocation for the target file in copy_file on Linux.
Use Linux fallocate system call to preallocate storage for the target
file in copy_file backends based on sendfile and copy_file_range. These
backends are only used when the file size is known beforehand, and
preallocating storage allows to reduce filesystem fragmentation and
get an early error if there's not enough free space on the target
filesystem.

Preallocation is only done as an optimization/hint. On filesystems
that do not support it we continue the data copying process as before.
This is why we aren't using posix_fallocate, because glibc contains
an emulation path that is used when the filesystem doesn't support
the functionality. We don't want this emulation, as it would effectively
double the amount of written data.
2024-01-05 15:41:01 +03:00
Andrey Semashev
571d178f4f Use configure-time check to detect dirent::d_type field support.
This potentially allows to support more C libraries that provide file
type information during directory iteration.
2023-06-03 20:15:59 +03:00
Andrey Semashev
7509619c9e Updated library version selection to avoid ODR violations.
The previous strategy of force-inlining methods that are dependent
on the library version is not effective with MSVC in debug mode,
when linking the static library. The compiler does not inline
methods despite the markup, and during linking the static library
with the user's module the linker may or may not pick up user's
definitions of these methods.

When building the library, do not define path methods that depend
on the library version. Instead, explicitly call v4 internal methods
throughout the implementation. This way the compiled library does not
contain v4 versions of these methods, and therefore does not conflict
with user's definitions of these methods.

Fixes https://github.com/boostorg/filesystem/issues/279.
2023-02-08 01:00:54 +03:00
Andrey Semashev
022c68d481 Added -Wno-restrict for gcc-12.
This disables bogus warnings coming from libstdc++ on string
assignments and appends.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105651
2022-12-18 02:14:16 +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
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
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
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
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
41d076ace5 Added protection for CVE-2022-21658 in remove_all on POSIX systems.
Another process could replace the directory being processed by remove_all
with a symlink after remove_all called symlink_status but before
it creates a directory iterator. As a result, remove_all would remove
the linked directory contents instead of removing the symlink.

On POSIX systems that support fdopendir and O_NOFOLLOW flag for open(2),
this can be prevented by opening the directory with O_NOFOLLOW before
iterating. This will fail if the directory was replaced with a symlink.

No protection on other systems.

Reported in https://github.com/boostorg/filesystem/issues/224.
2022-01-30 23:41:06 +03:00
Andrey Semashev
54ea0cc2f1 Added macro definitions to disable deprecated CRT warnings on Windows. 2021-10-26 19:03:28 +03:00
Andrey Semashev
9e5a3e231e Added a configure check for init_priority attribute.
Apparently, gcc does not support the attribute on Mac OS 11.4. Since
we can't tell if other systems aren't supported as well, it's better
to check with a configure check. As a side effect, this might add
support for more compilers.

Closes https://github.com/boostorg/filesystem/issues/199.
2021-07-14 18:12:47 +03:00
Andrey Semashev
f15a0e9b90 Generate list of Boost library includes for CMake configure checks.
In order to avoid hardcoding library dependencies recursively for the
configure checks performed in CMake build scripts, we generate the list
of all include directories. If there is a unified Boost include tree,
we can use that and avoid filesystem scanning.
2021-06-14 22:47:17 +03:00
Andrey Semashev
2dda038306 Reworked function pointers use and definitions.
Instead of using atomic<> to access global function pointers, use raw
pointers and atomic_ref to access them safely in multi-threaded builds.
This allows to ensure constant initialization of the function pointers,
even in C++03. This also solves the problem of undefined dynamic
initialization order that we previously tried to solve with the
init_priority attribute. The attribute turns out to not work if the
pointers were raw pointers (in single-threaded builds). It is also
not supported by Intel Compiler and possibly other, which required
us to avoid using the function pointer for fill_random.

The resulting code should be simpler and more portable. In order to
check for C++20 std::atomic_ref availability, the older check for <atomic>
header was replaced with a check for std::atomic_ref. If not available,
we're using Boost.Atomic, as before.
2021-06-14 22:09:15 +03:00
Andrey Semashev
45682f8501 Only build windows_file_codecvt on Windows and Cygwin. 2021-06-11 15:11:43 +03:00
Andrey Semashev
98daa68aa8 Force use of windows.h when building the library.
This forces definition of _WIN32_WINNT by Boost.WinAPI, which is important
for CopyFileEx and related symbols to be defined. Platform SDK from MSVC-8
does not define the macro by default, which caused compilation errors
previously.
2021-05-21 00:09:00 +03:00
Andrey Semashev
b27ad65326 Increased the minimum buffer size in read/write loop in copy_file.
Also, take into account the target filesystem block size, if available.
2021-05-19 00:22:31 +03:00
Andrey Semashev
4b9052f1e0 Fallback to read/write loop if sendfile/copy_file_range fail.
Since sendfile and copy_file_range can fail for some filesystems
(e.g. eCryptFS), we have to fallback to the read/write loop in copy_file
implementation. Additionally, since we implement the fallback now,
fallback to sendfile if copy_file_range fails with EXDEV and use
copy_file_range on older kernels that don't implement it for
cross-filesystem copying. This may be beneficial if copy_file_range
is used within a filesystem, and is performed on a remote server NFS or CIFS).

Also, it was discovered that copy_file_range can also fail with EOPNOTSUPP
when it is performed on an NFSv4 filesystem and the remote server does
not support COPY operation. This happens on some patched kernels in RHEL/CentOS.

Lastly, to make sure the copy_file_data pointer is accessed atomically,
it is now declared as an atomic value. If std::atomic is unavailable,
Boost.Atomic is used.

Fixes https://github.com/boostorg/filesystem/issues/184.
2021-05-18 23:16:02 +03:00
Andrey Semashev
c6ac51fb82 Added file creation time checks to CMakeLists.txt. 2021-05-16 23:14:09 +03:00
Andrey Semashev
0ecacd5da7 Updated CMakeLists.txt to reflect latest changes. 2021-05-16 22:46:11 +03:00
Andrey Semashev
db390391bb Restored auto-linking and Windows CE support.
Auto-linking can still be useful to users of MSVC and compatible
compilers on Windows, when the user links against static build of
Boost.Filesystem. This feature is marked deprecated though, so
it can be removed in the future, when the generated CMake config
files include information about third-party dependencies of Boost
libraries.

Additionally, restored support for linking against Windows CE-cpecific
coredll library. This platform is not tested though and therefore not
properly supported.

Closes https://github.com/boostorg/filesystem/issues/156.
2020-07-28 14:48:42 +03:00
Andrey Semashev
1104092053 Extracted platform defines to a separate header and include it everywhere.
This should fix readdir(_r) on 32-bit systems, which was not 64-bit after
commit c758552338e40ffe4c0bde127a81a753a3366fa7 because _FILE_OFFSET_BITS=64
was not defined in directory.cpp. Also, there were filesystem-related system
calls in unique_path.cpp, where the macro was not defined either. Including
the platform header in all source files is useful for possible future changes
that may require the platform-specific macros.

Closes https://github.com/boostorg/filesystem/pull/150.
2020-07-02 13:37:45 +03:00
Andrey Semashev
a3e517365a Corrected BCrypt API detection check in CMakeLists.txt.
The check depends on Boost.Predef and Boost.WinAPI. Unfortunately,
we cannot use their CMake targets in check_cxx_source_compiles because
they may not yet be defined at the point of inclusion of
filesystem/CMakeLists.txt by the superproject. Thus we have to manually
specify include path to the monolithic include tree. And bcrypt library.

We intentionally do not specify include paths for Boost.Predef and
Boost.WinAPI because that would require to also specify paths of their
dependencies, and this is not an acceptable maintenance burden.
2020-06-05 18:41:23 +03:00
Andrey Semashev
e3f29433d9 Updated CMakeLists.txt with configure-time checks required by recent code changes. 2020-06-05 14:00:37 +03:00
Ed Catmur
7a16eab170
Add src/exception.cpp to CMakeLists.txt
After 68ec5b1fb66bf0687d2f9b829e087a6be6ccb89e
2019-10-03 12:12:30 +01:00
Andrey Semashev
c758552338 Moved directory tools to separate files. Reworked readdir_r support.
Directory iteration components were moved to separate files to simplify
maintenance of operations.hpp/cpp.

directory_iterator implementation on POSIX platforms has been reworked
to only allocate internal buffer when readdir_r is used. When readdir
is used, the dirent structure returned by readdir is used directly, which
eliminates the potential of buffer overrun in case if some directory name
exceeds the buffer size. This also removes the need to copy dirent members
into the buffer, which improves performance and simplifies maintenance.

For buffer size we now use the max path size as opposed to max filename
size. This is done to minimize the possibility of buffer overruns when
readdir_r is used.

On Windows, use Boost.WinAPI to configure the default target Windows version.
This removes WINVER and _WIN32_WINNT defines in Boost.Filesystem as these
macros should be defined by Boost.WinAPI now.

Additionally, exception.hpp and directory.hpp includes in operations.hpp are
marked as deprecated as operations.hpp do not need those components. Users
are encouraged to include the new headers explicitly in their code, as needed.
2019-08-01 20:34:39 +03:00
Andrey Semashev
f4769bd4c7 Extracted file_status and error handling helpers to separate headers.
This simplifies maintenance of the operations.hpp/cpp files.

Also, moved BOOST_FILESYSTEM_SOURCE definition to the build system files
instead of defining it in every source file.
2019-07-31 23:12:56 +03:00
Mike-Devel
8ae582a321
[CMake] Add missing private dependency on winapi 2019-04-15 10:49:27 +02:00
Mike Dev
0f8e3acd06 [CMake] Add minimal cmake support
- CMake file only supports add_subdirectory workflow.
- Compiles boost filesystem (without name mangling).
- Provides target Boost::filesystem to link against.
- Does NOT compile/run unit tests (yet) and
  doesn't support installation.
2019-03-08 16:08:42 +01:00
Andrey Semashev
f0f77cfe73 Revert "Added an experimental partial CMakeLists.txt for dependency tracking in CMake projects."
This reverts commit 3c18ac362e63914109c3cbc1bafe9f78fece10a2.

Apparently, just adding include paths to user's CMake projects is not enough
for the original requester.

https://github.com/boostorg/atomic/pull/20#issuecomment-448345886
2018-12-18 23:02:52 +03:00
Andrey Semashev
3c18ac362e Added an experimental partial CMakeLists.txt for dependency tracking in CMake projects. 2018-12-18 19:41:59 +03:00
Troy D. Straszheim
6656351d2e rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back
[SVN r56942]
2009-10-17 02:07:38 +00:00
Troy D. Straszheim
d46ec2ea1c Copyrights on CMakeLists.txt to keep them from clogging up the inspect
reports.  This is essentially the same commit as r55095 on the release
branch.



[SVN r55159]
2009-07-26 00:49:56 +00:00
Michael A. Jackson
5cde8da587 Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor
[SVN r49510]
2008-11-01 13:15:41 +00:00