364 Commits

Author SHA1 Message Date
Andrey Semashev d73863751b Remove the check for Cygwin from Windows-only branch of fopen.
Cygwin is now handled by the POSIX branch of the code.
2026-06-28 19:43:35 +03:00
Andrey Semashev 03e8fc35a7 Marked templated overloads of initial_path as deprecated.
These overloads are presumably remnants from Boost.Filesystem v2, where
the path class was templated on the character type. They should have
been removed long ago, but were left behind. Users should be using
non-templated versions of these functions.
2026-04-19 22:05:37 +03:00
Andrey Semashev faf9c4ac3c Updated support for Boost.Container strings.
This updates container::basic_string forward declaration with the new
Options template parameter.

Also added tests for container::basic_string in path_test.cpp.

Fixes https://github.com/boostorg/filesystem/issues/342.
Closes https://github.com/boostorg/filesystem/pull/343.
2026-01-24 23:02:40 +03:00
Andrey Semashev 016cafbaf4 Added a check that the platform API macros are in sync with Boost.System.
Check that BOOST_FILESYSTEM_POSIX/WINDOWS_API and BOOST_POSIX/WINDOWS_API
are defined in the same way and error out if not. Allow users to suppress
this check (and keep their code compiling) by defining
BOOST_FILESYSTEM_ALLOW_SYSTEM_API_MISMATCH to 1 to reduce the error to
a warning or to 2 to completely disable the check.

If we diverge in platform API selection with Boost.System again, we may
want to implement our own system category that is guaranteed to be in sync
with the platform API Boost.Filesystem actually uses. But for now the two
libraries are expected to be in sync, and the added check should do.
2025-12-30 15:53:09 +03:00
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 d8eca47d05 Define Boost-Filesystem-specific macros for platform API selection.
Because Boost.System has switched to define BOOST_POSIX_API on Cygwin[1],
Boost.Filesystem now defines its own set of macros for platform API
selection. At this time, we preserve the previous behavior, where
Cygwin is treated as Windows.

[1]: https://github.com/boostorg/system/pull/137
2025-12-23 00:22:54 +03:00
Andrey Semashev 5a7e76d556 Extend the dllimport workaround to any gcc 12.
At least, gcc on Cygwin also emits the same bogus warnings about
missing dllimport attributes. Presumably, this may also be the case
for visibility attributes, so just disable the warning universally
on any gcc 12.
2025-06-13 18:36:55 +03:00
Andrey Semashev 1be9ea7f04 Disable the gcc 12 warning about dllimport in directory.hpp.
The warnings suppressed in header.hpp can be force-enabled by the user,
so disable the buggy warning in directory.hpp instead. Also make the
workaround more specific to MinGW.
2025-06-13 03:18:50 +03:00
Andrey Semashev 9e11731148 Work around bogus warning in MinGW-w64 gcc 12 about missing dllimport.
Disable the warning for gcc 12.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106395
2025-06-13 03:06:39 +03:00
Andrey Semashev fbd23ee0e0 Prevent templated path members from accepting args convertible to path.
This forces the non-templated overloads accepting path to be chosen instead
of the templated members that expect arguments converible to Source.

This resolves overload resolution ambiguities, when the argument of a
user-defined type is convertible to path and multiple other types that qualify
as Source. By preferring the conversion to path we avoid testing other
conversion paths that may be ambiguous.

Fixes https://github.com/boostorg/filesystem/issues/326.
2024-09-30 02:53:06 +03:00
Andrey Semashev 7bdccb0d2f Use <type_traits>, when possible. 2024-02-20 01:38:29 +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 4530e2496c Pass enum values to the compiled library.
Since we now require C++11 scoped enums and removed deprecated enums,
we can now pass copy_options and directory_options to the compiled
library without converting to the underlying type.
2024-01-14 18:28:05 +03:00
Andrey Semashev 5df060e95c Removed deprecated APIs.
Removed APIs that were marked as deprecated a long time ago. Disabled
by default support for path construction, assignment and appending from
container types. Users can still enable this functionality by defining
BOOST_FILESYSTEM_DEPRECATED.

Updated docs, tests and examples accordingly.
2024-01-14 17:48:44 +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 fc243122b9 Added a copy_options::ignore_attribute_errors option for copy_file/copy.
The new option allows to ignore errors while copying file attributes
(but not file contents).

Closes https://github.com/boostorg/filesystem/issues/179.
2024-01-13 17:22:16 +03:00
Andrey Semashev 7ff596a8df v4: Make absolute() produce a trailing slash for empty input path.
This follows the absolute() definition in the docs, as in v4 appending
an empty path results in a trailing slash.

Unfortunately, this also influences canonical and weakly_canonical,
so we had to duplicate those for v3 and v4 as well.

Fixes https://github.com/boostorg/filesystem/issues/301.
2024-01-08 20:42:32 +03:00
Andrey Semashev 1426ca53b4 v4: Make equivalent() fail if only one of the paths exists.
In v3, equivaluent would successfully return false if one of the paths
existed and the other one didn't. v4 now fails in this case, similar
to std::filesystem.
2024-01-08 02:35:29 +03:00
Andrey Semashev 9361213a91 Added a unique_path overload taking a single error_code& argument.
The overload uses the default path model.

Also, express the default model in native characters to avoid unnecessary
character code conversion.
2024-01-04 18:47:50 +03:00
Andrey Semashev b87d2790e7 v4: Avoid converting slashes in path root name in path::make_preferred.
Similarly to other methods, make_preferred is only supposed to affect
directory separators and not the slashes that are part of the path
root name.
2024-01-04 04:07:46 +03:00
Andrey Semashev 18b4e2f94c Rework path::generic_path to remove duplicate separators and retain root name.
std::filesystem::path::generic_string mandates that the returned string
uses *single* forward slashes for directory separators, which means
any duplicates must be removed. Boost.Filesystem now follows this definition,
and also documents that forward slashes are used for directory separators.

Additionally, since only directory separators are supposed to be affected,
in v4 avoid converting any slashes that are part of the path root name. This
is the case on Windows with UNC paths and Windows-specific path prefixes.
Keep v3 behavior unchanged for backward compatibility.

Closes https://github.com/boostorg/filesystem/issues/299.
2024-01-04 04:07:34 +03:00
Andrey Semashev be82eff289 Removed string_file.hpp that was deprecated in 1.79.0. 2023-10-04 19:40:55 +03:00
Andrey Semashev 4c621f1577 Removed support for Windows CE that was deprecated in 1.79.0. 2023-10-04 19:40:47 +03:00
Andrey Semashev 73f2bf064a Renamed check functions to avoid UE macro clash.
Reported in https://github.com/boostorg/filesystem/issues/294.
2023-09-23 00:00:04 +03:00
Andrey Semashev 16805b5a11 Added missing error code clearing in directory_entry members.
Fixes https://github.com/boostorg/filesystem/issues/291.
2023-08-28 19:47:55 +03:00
Andrey Semashev 7bb038fcb8 Added a new cstdio.hpp header with fopen overload.
This overload takes filesystem::path as its first argument to support
wide character paths on Windows. Other than this, the overload is
equivalent to std::fopen.
2023-06-12 15:02:30 +03:00
Andrey Semashev b794e63216 Marked file status querying functions with error_codes noexcept.
After the recent change to get_reparse_point_tag_ioctl, status functions
should no longer throw if error reporting is done via error_code. This
allows us to mark all file status querying functions with error_code
arguments noexcept, as specified in std::filesystem and Boost.Filesystem
docs.
2023-06-11 21:16:10 +03:00
Andrey Semashev b1bf547a55 Added more file type testing functions.
Also, make namespace-scope file testing functions for directory_entry
forward to member functions for better efficiency.
2023-06-11 20:56:20 +03:00
Andrey Semashev d508d4950f Add dir_entry::refresh and file type observers. Use them in recursive dir_it.
This commit changes behavior of directory_entry constructors and modifiers
that change the stored path in v4: the methods will now automatically query
the filesystem for the file status instead of leaving the cached data
default-initialized. This means that the paths passed to directory_entry
must be valid, otherwise an error will be returned. Filesystem querying
is implemented in the new directory_entry::refresh methods.

The constructors and modifiers that accepted file_status arguments are
now removed in v4. The cached file statuses are an implementation detail,
and eventually we may want to add more cached data, as we add more observers
to directory_entry.

Also added a few file type observers to directory_entry. These observers
allow to avoid querying the filesystem if the full file status is not cached
but the file type is (i.e. when permissions are not cached). This is the case
with readdir-based implementation of directory_iterator, if the underlying
C library supports dirent::d_type field.

recursive_directory_iterator has been updated to use the added file type
observers instead of querying the full status. This may improve performance
of directory iteration.

Closes https://github.com/boostorg/filesystem/issues/288.
2023-06-04 20:18:50 +03:00
Andrey Semashev 277da85cab Make fstream types move constructible/assignable.
If the standard library fstream types are movable, Boost.Filesystem
counterparts are now movable as well.

Closes https://github.com/boostorg/filesystem/issues/280.
2023-05-22 23:21:56 +03:00
Andrey Semashev 3a596f3533 Renamed BOOST_FILESYSTEM_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR to detail. 2023-05-22 23:00:59 +03:00
Andrey Semashev a30b36946a Use namespace-scope helper functions in is_convertible_to_path_source. 2023-05-21 17:41:53 +03:00
Andrey Semashev 39b0f3a1fe Check that the type is an iterator in is_path_source_iterator.
This fixes hard compilation error when the passed type is not an iterator
at all. As a result, path constructors from iterators are no longer
selected by the compiler in overload resolution in users' code, when
the caller is passing an initializer list with a pair of non-iterator
elements. Added a test for this fix.

Also, use integral_constant to implement boolean type traits.

Fixes https://github.com/boostorg/filesystem/issues/287.
2023-05-21 17:27:12 +03:00
Andrey Semashev 396eef1398 Restrict generic path comparison operators to avoid ambiguities with std lib.
Path comparison operators that accept arbitrary path source types now require
the other argument to be exactly path. This prevents the compiler from picking
those operators when the other argument is convertible to path. This can happen
even when neither of the arguments are actually paths, e.g. when the
comparison operators are brought into the current scope by a using directive.

Fixes https://github.com/boostorg/filesystem/issues/285.
2023-05-08 00:11:37 +03:00
Andrey Semashev d53450936d Removed noexcept markup from directory_entry comparisons.
These operators forward to path comparison operators and eventually
path::compare, which are not noexcept and may actually throw.
2023-05-07 20:34:30 +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 5f2d434a9d Silenced clang warnings about unnamed types in template parameters. 2023-02-07 13:22:44 +03:00
Andrey Semashev 32a3878d6a Updated copyrights. 2023-02-05 20:35:00 +03:00
Andrey Semashev b6ecf3013d Added v4 path::remove_filename. Added path::replace_filename.
v4 remove_filename works similar to std::filesystem, i.e. preserves
the trailing directory separator after removing the filename.
v3 remove_filename works as before. Its behavior is also useful in
v4, so added a new method remove_filename_and_trailing_separators
with the same behavior.

Also added replace_filename that was previously missing.

remove_filename discrepancy from std::filesystem was reported in:

https://github.com/boostorg/filesystem/issues/271
2023-02-05 20:25:50 +03:00
Andrey Semashev 0451cb206d Fixed compilation with gcc in C++23 mode. 2023-02-04 23:20:04 +03:00
Andrey Semashev f05ac885d1 Disabled construction and assignment of path from nullptr.
It is always an error and UB. Explicitly deleting the functions produces
better compiler errors.

Closes https://github.com/boostorg/filesystem/issues/278.
2023-02-04 20:24:18 +03:00
Andrey Semashev 5cefe7890f Remove path converting constructors from types convertible to path sources.
This causes ambiguities in users' code where the previously added conversion
from user-defined types that have a conversion to one of the path source
types:

  struct my_class
  {
    operator std::string() const;
  };

  std::string to_string(std::string const&);
  std::string to_string(boost::filesystem::path const&);

  to_string(my_class());

The above call is ambiguous as the conversion operator in my_class and
a converting constructor in boost::filesystem::path from my_class are
both available and have equivalent ranks.

Removing the conversion constructors from boost::filesystem::path
means users will have to explicitly cast their types to one of the
path source types before constructing path.

In order to preserve backward compatibility with operator== and operator!=
for paths that also accepted source types (path::string_type,
const path::value_type*), we have to update path::compare and comparison
operators to accept types that are convertible to source types.

Fixes https://github.com/boostorg/filesystem/issues/273.
2023-02-04 19:55:17 +03:00
Andrey Semashev 9a49c4f3f4 Ported to BOOST_DEPRECATED macro from Boost.Config. 2022-12-22 18:38:40 +03:00
Andrey Semashev bd878f47e8 Added missing #endif in path_traits.hpp.
Fixes https://github.com/boostorg/filesystem/issues/268.
2022-12-02 12:12:09 +03:00
Andrey Semashev e2d2472eda std::string_view range constructor will be explicit in libstdc++ 11.4.
As noted here:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106808
2022-09-08 23:45:18 +03:00
Andrey Semashev 9613ccfa4a std::string_view range constructor was made explicit in gcc 12.2, not 12.1. 2022-09-02 18:27:29 +03:00
Andrey Semashev cffb1d1bbd Marked path append operators forceinline. 2022-09-02 02:24:47 +03:00
Andrey Semashev b224703125 Added a workaround for gcc 11 compile errors in C++23 mode.
C++23 std::string_view added a range constructor that is constrained with
a concept check that in particular checks if the range is contiguous. In
that check, the range iterator type is checked. Since fs::path members now
test whether the source argument is convertible to std::string_view, that
concept check is performed whenever the overload resolution or SFINAE check
is performed. This caused a problem if the check was performed before
fs::path::iterator is defined, since the result of the check formally
changes when the iterator gets defined.

To work around this, move any fs::path non-template member functions that
call to other members (including constructors) which may involve overload
resolution or SFINAE checks that might require testing whether
std::string_view is constructible from fs::path out of fs::path definition
and past the fs::path::iterator definition.

This was also reported to gcc team:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106808
2022-09-02 02:06:01 +03:00
Andrey Semashev b219d9fb8a Added support for string views and boost::container::string.
Path traits and relevant path members were reworked to better support
wider range of types that are compatible with path constructors, assignment
and appending members. Added support for C++17 std::string_view,
boost::string_view and boost::container::string as the possible string
types accepted by path members.

Also extended support for types convertible to one of the string types.
Previously, user's type had to be convertible to a string with a character
type that matches the native path character type. Now all supported character
types are acceptable.

Additionally, restricted members accepting a pair of iterators to only accept
iterators whose value types are one of the supported path character types.

Lastly, path::compare and comparison operators now only accept path arguments,
relying on path conversion constructors to do the job of supporting various
source types. Also removed noexcept from compare as it is using lex_compare
and iterators internally and those can throw.

Closes https://github.com/boostorg/filesystem/issues/208.
2022-08-31 09:52:30 +03:00
Andrey Semashev 349daee54b Moved path_traits.hpp to detail.
The public path_traits.hpp header is deprecated and will be removed. Its
contents are path implementation details and are now in detail.
2022-08-21 18:45:59 +03:00