23 Commits

Author SHA1 Message Date
Andrey Semashev
ae458c7884 Switch to POSIX API on Cygwin.
This follows other Boost libraries (in particular, Boost.System) in
treating Cygwin as a POSIX platform rather than Windows. This is
a breaking change, but apparently downstream Boost.Filesystem packages
on Cygwin are patched to the same effect.

As part of this change, AT_NO_AUTOMOUNT is made an optional requirement
to enable POSIX *at APIs. This flag is not POSIX-standard and is not
supported on Cygwin, while *at APIs are.
2025-12-25 04:09:00 +03:00
Andrey Semashev
f7ed6b5ea9 Change searched-lib to lib in the Jamfile.
Apparently, searched-lib was not supposed to be used in libraries,
and the simple lib target is the preferred way to declare external
libraries.

https://github.com/bfgroup/b2/issues/431#issuecomment-2985057673
2025-06-19 02:44:26 +03:00
Andrey Semashev
bf29b81a36 Added a workaround for dirfd being a macro on FreeBSD 9 and older.
Fixes https://github.com/boostorg/filesystem/issues/328.
2024-10-03 13:26:18 +03:00
René Ferdinand Rivera Morell
5746b3f0d6 Add support for modular build structure. (#318)
* Make the library modular usable.

* Use searched-lib targets for external/OS/Windows libraries to avoid trying to refer to mangled names for them. And hence failing to find them.

* Use the OS temp dir for creating test dir to avoid putting dirs in random location based on where one runs tests from.

* Switch to library requirements instead of source. As source puts extra source in install targets.

* Updated dependencies.

* Add missing NO_LIB usage requirements.

* Add missing import-search for cconfig/predef checks.

* Add requires-b2 check to top-level build file.

* Bump B2 require to 5.2

* Change all <source> references to <library>.

* Update copyright dates.

* Move inter-lib dependencies to a project variable and into the build targets.

* Split b2 dependencies into public and private.

* Undo temp dir for test change.

* Make winapi dep target-os specific. And remove direct atomic dep as it is already handled by conditional rule.

* Remove bug targets from all build as that's not a regular project.
2024-09-22 19:57:37 +03:00
Andrey Semashev
7eece0064a On POSIX systems, use *at APIs in recursive_directory_iterator.
This makes the iterator more resilient to concurrent filesystem
modifications.
2024-02-12 01:07:44 +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
176fce8e4d Disable -Wl,--no-undefined on OpenBSD.
This flag is broken for shared libraries on OpenBSD as it leaves all libc
symbols unresolved.

Fixes https://github.com/boostorg/filesystem/issues/283.
2023-04-12 00:10:43 +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
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
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.
2022-03-02 14:19:25 +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
049e9aad94 Check that linking with bcrypt works in has_bcrypt config test.
This allows to succeed library compilation if BCrypt API is
available in headers but the library is not.
2021-10-26 20:23:04 +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
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
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
c03249c375 Reformatted code for more consistent look and better readability. 2021-04-24 22:37:57 +03:00
Andrey Semashev
a031e4ffa9 Added creation_time operation.
The operation allows to query file creation time.

Implementation partially inspired by:

https://github.com/boostorg/filesystem/pull/134

Closes https://github.com/boostorg/filesystem/pull/134.
2020-08-21 01:32:04 +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
2bfb8c91e1 Corrected configure check for BCrypt API. 2020-06-05 14:17:09 +03:00
Andrey Semashev
427697ffcd Check for Cygwin when including Boost.WinAPI. 2020-06-05 12:11:56 +03:00
Andrey Semashev
5d1b14df51 Moved Windows lib linking to the Jamfile and added a config check for BCrypt.
This should improve support for Windows compilers that don't support
auto-linking.
2020-06-05 11:58:17 +03:00
Andrey Semashev
9252269160 Added configuration steps to detect modification time representation in stat.
This should improve compatibility with Mac OS X and other systems with
various representations of file times in struct stat.
2020-05-12 14:56:24 +03:00