Commit Graph

483 Commits

Author SHA1 Message Date
Andrey Semashev
ac821cd53a Marked global constants with unused/used attributes to suppress clang warnings.
The "unused" attribute suppresses warnings emitted by clang for global
constants that are used to hook into early initialization of globals. The
"used" attribute is a precaution to ensure these hooks are not eliminated
by compiler or linker.
2021-10-26 19:49:58 +03:00
Andrey Semashev
df972e9a5d Remove unused constants on Windows to silence clang warnings. 2021-10-26 19:10:01 +03:00
Andrey Semashev
3a323cae2d Removed implicit trailing dot element of the path in v4.
When the path ends with a non-root directory separator, no longer
produce a trailing dot element (filename). Instead, return an empty
path.

This affects not only path iterators and path::filename, but also any
other APIs that rely on them.

Closes https://github.com/boostorg/filesystem/issues/193.
2021-10-17 21:40:19 +03:00
Andrey Semashev
b4c39093cc Reimplemented create_directories for compatibility with v4 paths.
The new implementation is prepared for the removal of the implicit
trailing dots in v4 path. It also no longer uses recursion
internally and therefore is better protected against stack overflows.

As a side effect of this rewrite, create_directories no longer reports
error if the input path consists entirely of dot and dot-dot elements.
This is in line with C++20 std::filesystem behavior.
2021-10-17 21:38:28 +03:00
Andrey Semashev
34b357acf6 Marked windows_file_codecvt::do_unshift with BOOST_OVERRIDE.
Closes https://github.com/boostorg/filesystem/issues/206.
2021-09-03 13:35:24 +03:00
Andrey Semashev
9794725bda Added a workaround for Linux headers older than 2.6.19.
linux/magic.h was introduced in Linux kernel 2.6.19, building Boost.Filesystem
with older kernel headers would fail because of this. Only include the header
when it is found and fallback to our local constant definitions when it's not.
2021-08-03 14:45:46 +03:00
Andrey Semashev
87d3c1fd8a Fix weakly_canonical on Windows if the path contains non-existing elements.
Windows APIs such as GetFileAttributesW perform lexical path normalization
internally, which means e.g. "C:\a\.." resolves to an existing path
even if "C:\a" doesn't. This breaks depection of the longest sequence
of existing path elements in weakly_canonical and results in an error
in canonical that is called on that sequence.

As a workaround, perform forward iteration on Windows, so that we
stop on the first path element that doesn't exist.

Also, while at it, corrected error code reported from weakly_canonical
when status fails with an error.

Closes https://github.com/boostorg/filesystem/issues/201.
2021-07-28 20:05:17 +03:00
Andrey Semashev
d418858839 Convert root dir to preferred separator in path::lexically_normal.
This is consistent with std::filesystem and behavior before
16bd89b7c0.

Closes https://github.com/boostorg/filesystem/issues/200.
2021-07-20 11:42:55 +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
003f002399 Disable posix_fadvise for Android API < 21.
Closes https://github.com/boostorg/filesystem/issues/198.
2021-07-12 15:50:18 +03:00
Andrey Semashev
97f93a8cdc Added explicit initializer for path locale deleter to work around clang-3.7 bug.
clang-3.7 and possibly other versions require an explicit initializer for
global constant objects, even if they are default-constructible.
2021-07-05 02:09:04 +03:00
Andrey Semashev
007ccb7a5e Init path globals early to allow using Boost.FS during program termination.
This works around recurringissues when Boost.Filesystem is used during
program termination (for example, in Boost.Log, when it performs the final
log file rotation). At that point, the path locale as well as dot and dot-dot
paths may no longer be available.

Also, MSVC 14.2 has a bug[1] that results in a deadlock whet dot or
dot-dot path is being created during program termination, while atexit
callbacks are being run in the main thread. This change works around it
as the new code does not call atexit on initialization of these paths.

This is only supported on MSVC, GCC, Clang and compatible compilers that
support MSVC-specific or GCC-specific means to customize global initialization
order.

[1]: https://github.com/boostorg/log/issues/153
2021-06-28 20:58:35 +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
08e7a20785 Added runtime detection of getrantom Linux system call.
Fall back to reading /dev/(u)random if getrandom fails with ENOSYS.

Also, extracted the portability macros for atomics to a separate header
to be able to use them in unique_path.cpp. Rearranged function pointers
initialization to decouple the initializer object from the particular
system calls.

For getrandom, the ENOSYS failure is only cached if the compiler supports
specifying global object initialization priority, which is needed to ensure
that the function pointer is initialized before the syscall initializer
in a different TU. If the compiler does not support this feature, just
always attempt getrandom first.
2021-06-14 03:39:03 +03:00
Andrey Semashev
017d8c7d40 Get rid of the separator strings. 2021-06-14 02:32:29 +03:00
Andrey Semashev
2a5ce62a3a Removed unused constants and added a precondition assert. 2021-06-13 21:29:31 +03:00
Andrey Semashev
3e8c8b15f9 Added runtime detection of the statx system call on Linux.
This can be useful if the syscall is present at compile time but fails with
ENOSYS at run time (for example, in Docker containers that restrict the syscall,
even if available on the host).

Additionally, marked statx syscall wrappers with attributes to disable MSAN
for them. It was reported that MSAN on clang 10 is showing errors
accessing uninitialized data in stx_mask, which must be initialized by the
syscall.

Related to https://github.com/boostorg/filesystem/issues/172
Related to https://github.com/boostorg/filesystem/issues/185
2021-06-13 21:10:10 +03:00
Andrey Semashev
7339882ccf Added BOOST_FILESYSTEM_VERSION 4 and moved breaking path changes to v4.
Boost.Filesystem v4 will contain breaking changes from v3 that are required
for better compatibility with C++17 std::filesystem. It will also remove
the deprecated features of v3.

Updated docs to reflect the differences between v3 and v4. Updated tests
to verify both v3 and v4 where the differences are present.
2021-06-13 03:20:30 +03:00
Andrey Semashev
f851c4eb41 Moved windows_file_codecvt to library namespace and modernized it.
Closes https://github.com/boostorg/filesystem/issues/195.
2021-06-11 14:48:15 +03:00
Andrey Semashev
60e908dfcf Don't return root directory from path::filename().
This is a breaking change.

path::filename accessor now only returns the actual filename or the implied
trailing dot element of the path, if it ends with a separator other than
root directory. This makes boost::filesystem::path behavior closer to that
of std::filesystem::path.

Updated tests and docs accordingly.

Closes https://github.com/boostorg/filesystem/issues/194.
2021-06-10 03:49:30 +03:00
Andrey Semashev
26a07aad53 Allow creating symlinks on Windows in non-elevated mode.
If Windows is running in Developer mode, it is possible to specify
SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE flag to CreateSymbolicLinkW
so that the call doesn't require elevated privileges.

While at it, explicitly separated implementation of create_symlink and
create_directory_symlink for POSIX and Windows.
2021-06-09 19:09:24 +03:00
Andrey Semashev
4b5023c94b Use preferred separator for root directory in (weakly_)canonical.
Using preferred separators in paths on Windows works around "file not found"
errors returned by GetFileAttributesW, when a forward slash is used in some paths.
Specifically, this can happen with UNC paths and paths starting with the Win32
filesystem prefix ("\\?\").

Closes https://github.com/boostorg/filesystem/issues/87.
Closes https://github.com/boostorg/filesystem/issues/187.
2021-06-06 22:56:16 +03:00
Andrey Semashev
8328bb277b Treat filenames starting with a dot as filenames rather than extension.
Filenames starting with a dot (and no other dots) are commonly treated
as filenames with no extension rather than an extension. This is also
the behavior mandated in C++17 filesystem.

Reported in https://github.com/boostorg/filesystem/issues/88.
2021-06-06 18:31:41 +03:00
Andrey Semashev
62a598e3dd Reduced absolute_path_max limit.
The new value is closer to max path size limits that is defined on various
systems.
2021-06-06 17:27:53 +03:00
Andrey Semashev
dbd28cb489 Removed unused variable. 2021-06-06 12:19:15 +03:00
Andrey Semashev
5cbcdb5b14 Trim trailing spaces. 2021-06-06 04:32:36 +03:00
Andrey Semashev
a252f15f06 Use substitute names to obtain the target of a reparse point.
The print name can be empty for some reparse points (e.g. mount points
created by Box cloud storage driver and directory junctions created by
junction.exe). It is supposed to be mostly used for presenting a "simple"
path to the user and not to actually locate the file.

The substitute name is the actionable replacement path, but it is in
NT path format and can potentially point to unmounted volumes and
UNC resources. The implementation attempts to convert the NT path
to Win32 path by matching commonly known patterns against the NT path.
If no pattern matches, we create a Win32 path by converting the NT path
prefix to "\\?\".

Related to https://github.com/boostorg/filesystem/issues/187.
2021-06-06 04:20:24 +03:00
Andrey Semashev
16bd89b7c0 Reworked path::lexically_normal to remove some redundant dot path elements.
The new implementation is also not relying on the root name format and
is more pertormant as it avoids unnecessarily copying path elements during
operation.

Note that this commit does not remove the trailing dot elements in the
normalized paths.
2021-06-05 23:34:49 +03:00
Andrey Semashev
4b84226783 Refactored path implementation for better support Windows path prefixes.
- Unified root name and root directory parsing that was scattered and
  duplicated across different algorithms. The new implementation is
  consolidated in a single function for parsing root name and root
  directory, which is used from various algorithms.

- The new root name parsing now supports Windows local device ("\\.\")
  and NT path ("\??\") prefixes. It also adds support for filesystem
  ("\\?\") prefix to some of the higher level algorithms that were
  using custom parsing previously. Tests updated to verify these prefixes.

- Some of the path decomposition methods were unified with presence checking
  methods (e.g. root_name with has_root_name). This makes these methods
  work consistently and also makes the has_* methods less expensive as
  they no longer have to construct a path only to check if it is empty.

- The filename accessor no longer returns root name if the whole path
  only consists of a root name. This also affects stem and extension as
  those accessors are based on filename. This is a breaking change.

- Cleaned up code:
  - Removed redundant checks for std::wstring support.
  - Added header/footer headers to globally disable compiler warnings.
  - Removed commented out super-deprecated code.
  - Added missing includes and removed includes that are not needed.
  - Nonessential code formatting.
2021-06-05 19:52:33 +03:00
Andrey Semashev
af6ac28b57 Added ERROR_BAD_NET_NAME to the list of errors indicating "file not found".
ERROR_BAD_NET_NAME is returned on Windows 10 21H1 x64 when a non-existent
share is accessed: "\\no-host\no-share".
2021-05-30 22:27:04 +03:00
Andrey Semashev
8c3c84e0c1 Nonessential formatting changes. 2021-05-30 03:09:41 +03:00
Andrey Semashev
0eb5290401 Added weakly_canonical overloads taking base path as an argument.
This can be useful when current_path is not supported by the system.
2021-05-29 18:40:51 +03:00
Andrey Semashev
9784bff897 Optimized path::has_root_directory and path::root_path.
Avoid creating root directory path only to test if it's empty. Avoid
calling root_directory multiple times in root_path.

Also, nonessential code reformatting.
2021-05-29 04:35:03 +03:00
Andrey Semashev
0cdb5a7d87 Use a safer check for dot and dot-dot paths in weakly_canonical.
Also, renamed a few variables to avoid name clashes and improve code
consistency.
2021-05-29 04:34:54 +03:00
Andrey Semashev
a7ff5b43f3 Implemented a limit on the number of symlinks resolved in canonical().
This protects from an infinite loop in case if symlinks form a loop.

The limit is currently system-dependent, with a lower bound of 40.
2021-05-29 03:09:29 +03:00
Andrey Semashev
997218c464 Nonessential code formatting. 2021-05-29 03:03:10 +03:00
Andrey Semashev
c76f91eae2 Added filesystem_error ctors from C-style strings for description. 2021-05-29 02:11:10 +03:00
Andrey Semashev
60ceb77b0f Extracted small path buffer size to a global constant. 2021-05-29 01:46:23 +03:00
Andrey Semashev
267b945993 Fail current_path on Windows CE with ERROR_NOT_SUPPORTED.
Windows CE does not support current directory.
2021-05-28 17:48:43 +03:00
Andrey Semashev
a12c413adf Start with double the small buffer in current_path fallback.
When current_path on POSIX falls back to the dynamically allocated
buffer for the resulting path, start with double the size of the
small stack buffer that was used initially.
2021-05-28 17:32:51 +03:00
Andrey Semashev
a42613369f Optimized canonical() wrt. symlinks containing dot elements. 2021-05-28 16:10:25 +03:00
Andrey Semashev
616dab9b8c Update root in canonical if resolved link is absolute with a different root.
When canonical() resolves symlink, it is possible that a symlink resolves
to an absolute path with a different root. We need to update the root
path so that when we restart symlink resolution the check for the
root path still works.

Also, slightly refactored the canonical() implementation to reduce code
size and possibly optimize the generated code.
2021-05-28 16:03:28 +03:00
Andrey Semashev
84440dd46f Prefer a buffer larger than the file in the read/write loop.
This allows to avoid an extra read syscall to detect the end of the file
if the file fits in the buffer exactly.
2021-05-24 13:37:15 +03:00
Andrey Semashev
a3745c8ba1 Removed unused macro defininition. 2021-05-21 00:56:47 +03:00
Andrey Semashev
3744ed73d4 Fixed compilation on 32-bit Windows and added support for multi-stream files.
There was a missing calling convention specification in the CopyFileEx
callback. This was not a problem in 64-bit builds since there is no
stdcall convention in 64-bit x86.

When CopyFileEx copies multi-stream files, the callback is executed for each
stream separately. Each stream is represented with a separate file handle,
so we have to flush buffers when the stream is fully copied, rather than the
whole file.
2021-05-20 23:27:29 +03:00
Andrey Semashev
26955d8a9f Changed handling of copy_options::synchronize(_data) on Windows.
Use FlushFileBuffers to force any buffered data written to the permanent
storage. The previously used COPY_FILE_NO_BUFFERING flag only guarantees
that no data is left in the OS filesystem cache, but does not ensure
that any device buffers are flushed.
2021-05-20 20:30:14 +03:00
Andrey Semashev
7651a8e90c Check for EINPROGRESS on closing the target file descriptor in copy_file.
This error code will be allowed in future POSIX revisions, according to
https://www.austingroupbugs.net/view.php?id=529#c1200.
2021-05-20 13:18:08 +03:00
Andrey Semashev
0bbc79b884 Remove Boost.Atomic dependency in single-threaded builds.
In single-threaded builds we can assume no thread synchronization
is necessary and avoid the dependency on Boost.Atomic. The dependency
caused single-threaded build failures because Boost.Atomic requires
multithreading to be enabled.

The CMake build currently does not support single-threaded builds, so
the dependency is left present there.

Closes https://github.com/boostorg/filesystem/issues/188.
2021-05-20 02:35:34 +03:00
Andrey Semashev
e01ae41298 Renamed max_send_size to max_batch_size for code clarity. 2021-05-19 13:57:17 +03:00
Andrey Semashev
dc2a162e5e Use a small stack buffer if heap memory allocation fails in read/write copy_file.
This allows the copy_file operation to succeed if the memory allocator reports
failure.
2021-05-19 13:43:54 +03:00
Andrey Semashev
d44b4ce865 Use a variable buffer size for read/write loop.
The buffer size is now selected based on the file size and filesystem block
size and is limited with min and max. This allows to reduce memory consumption
and possibly increase performance when copying smaller files.
2021-05-19 10:54:03 +03:00
Andrey Semashev
a59bce0708 Removed unused include. 2021-05-19 03:19:08 +03:00
Andrey Semashev
dc65ed5213 Added definitions of filesystem type magic constants. 2021-05-19 03:19:08 +03:00
Andrey Semashev
129d847f8f Added a link to LKML discussion re copy_file_range and procfs/sysfs/etc. 2021-05-19 02:37:28 +03:00
Andrey Semashev
88c2a2df8c Check the source filesystem type before using sendfile/copy_file_range.
Some filesystems have regular files with generated content. Such files have
arbitrary size, including zero, but have actual content. Linux system calls
sendfile or copy_file_range will not copy contents of such files, so we must
use a read/write loop to handle them.

Check the type of the source filesystem before using sendfile or
copy_file_range and fallback to the read/write loop if it matches one of
the blacklisted filesystems: procfs, sysfs, tracefs or debugfs.

Also, added a test to verify that copy_file works on procfs.
2021-05-19 01:43:22 +03:00
Andrey Semashev
9a35774ede Call posix_fadvise to indicate that source file will be read sequentially. 2021-05-19 00:48:03 +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
59e3644803 Added definition of COPY_FILE_NO_BUFFERING for Cygwin, MinGW and MinGW-w64. 2021-05-17 21:35:48 +03:00
Andrey Semashev
f5ebcfcd49 Don't indicate error in copy_file if close fails with EINTR. 2021-05-17 21:26:37 +03:00
Andrey Semashev
3c8408995f Added copy_options::synchronize_data and copy_options::synchronize.
These options allow to synchronize the copied data and attributes with
the permanent storage. Note that by default on POSIX systems copy_file
used to synchronize data in previous releases, and this commit changes
this. The caller now has to explicitly request syncing, as it has
significant performance implications.

Closes https://github.com/boostorg/filesystem/issues/186.
2021-05-17 20:33:57 +03:00
Andrey Semashev
be900df3e6 Added EINTR handling on close(2).
At least HP-UX is known to leave the file descriptor open if close() returns
EINTR. On other systems (Linux, BSD, Solaris, AIX) the file descriptor
is closed in the same situation, and closing it again may potentially close
the wrong descriptor if it is reused by another thread. We introduce
close_fd internal helper to abstract away these platform differences.
2021-05-17 18:39:46 +03:00
Andrey Semashev
8c676eaf8f Avoid comparing pointers to a literal zero. 2021-05-17 17:40:20 +03:00
Andrey Semashev
92262db736 Added EINTR handling for fsync/fdatasync. 2021-05-17 17:22:00 +03:00
Andrey Semashev
9dadc8c90f Minor code cleanup. 2021-05-16 23:41:31 +03:00
Andrey Semashev
8e03e44920 Cleanup portability functions. 2021-05-16 22:57:16 +03:00
Andrey Semashev
05de74a000 Added config macros for disabling use of some system APIs.
By defining these new config macros the user can configure the library
to avoid using some system APIs even if they are detected as available
by the library build scripts. This can be useful in case if the API
is known to consistently fail at runtime on the target system.

Related to https://github.com/boostorg/filesystem/issues/172.
2021-05-16 20:44:09 +03:00
Andrey Semashev
4319cf1388 Another attempt to workaround clang < 3.9 bug. 2021-04-25 02:48:56 +03:00
Andrey Semashev
d8dd339d91 Added a workaround for clang 3.5-3.8 compiler error due to no user-defined default ctor in error category. 2021-04-24 23:56:27 +03:00
Andrey Semashev
c03249c375 Reformatted code for more consistent look and better readability. 2021-04-24 22:37:57 +03:00
Andrey Semashev
83429c9bfd Check file status for status_error in create_directories.
create_directories used to ignore errors returned by status()
calls issued internally. The operation would likely fail anyway,
but the error codes returned by create_directories would be incorrect.
Also, it is better to terminate the operation as early as possible
when an error is encountered.

Reported in https://github.com/boostorg/filesystem/issues/182.
2021-03-29 20:20:34 +03:00
Andrey Semashev
cc57d28995 Fixed an exception being thrown by path::remove_filename if the path is "////".
Also added tests verifying the case.

Fixes https://github.com/boostorg/filesystem/issues/176.
2021-02-26 14:51:04 +03:00
Andrey Semashev
4137a9d6b1 Marked filesystem_error with VISIBLE and exported members with DECL macros.
This makes a difference in case if Boost.Filesystem is linked statically into
user's application. In this case filesystem_error used to be not marked as
publicly visible, which could make it impossible to catch the exception if
it crossed shared library boundary. By marking the class as publicly visible
we ensure that RTTI is always visible, even in static builds.

The exported members are also marked with dllexport/dllimport attributes
for compatibility with Windows.
2021-02-02 20:34:02 +03:00
Andrey Semashev
b4d606cdd0 Reduced preprocessor conditions. 2020-12-23 11:10:50 +03:00
whitequark
c6e5bdafce Update WASI platform support. 2020-12-23 11:10:50 +03:00
Andrey Semashev
6c2bf50c3a Fixed space operation on Windows not failing for a non-existing path.
Fixes https://github.com/boostorg/filesystem/issues/167.
2020-11-25 18:15:30 +03:00
Andrey Semashev
6b5e38134a On OpenBSD 4.4 and newer, use statvfs to obtain filesystem space info.
Closes https://github.com/boostorg/filesystem/pull/162.
2020-10-04 15:31:29 +03:00
Andrey Semashev
fe2a4fea13 Code cleanup to clear clang warnings and remove obsolete code.
Functions for stat/statx abstraction become unused when either of
the two APIs is used, which triggers clang warnings.

Ported copy_directory to statx and removed the BOOST_COPY_DIRECTORY
macro. One less usage of stat().

Removed workarounds for MSVC versions older than 7.0. Use portable
typedef for 64-bit integers.

Marked some internal functions inline. Removed zero initialization
of stat structs prior to stat calls, which is expected to initialize
the struct anyway.
2020-08-21 14:58:21 +03:00
Andrey Semashev
ec64afc0f5 Ported most of the operations to Linux statx system call.
The Linux statx system call allows to specify the data the caller is
interested in. This has the potential of improving performance
if some information is expensive to provide.

Also, changed hard_link_count to return static_cast<uintmax_t>(-1)
in case of errors. Changed file_size to report ENOSYS instead of
EPERM when the operation is invoked on a non-regular file.
2020-08-21 01:33:44 +03:00
Andrey Semashev
8d6eaeb5af Changed returned value of last_write_time in case of error to min std::time_t.
This follows C++20 definition, which returns a minimum representable time
point value in case of error.

Also, slight refactoring of last_write_time setter function and a fix
to ensure the error code is cleared incase of success.
2020-08-21 01:32:17 +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
4748f6e39d Added O_CLOEXEC to open calls in unique_path implementation. 2020-07-29 12:33:15 +03:00
Andrey Semashev
96ff4a1fe6 Corrected comments. 2020-07-28 15:01:45 +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
7c4fe07112 Fix copy(ec) operation not copying anything if the target does not exist.
The operation would use (symlink_)status internally to test if the target
file or directory exists. That operation can return an error code even if
it completes successfully. However, copy operation would abort in this case
before attempting to copy anything. This would not be caught by tests because
the tests use the overloads without an error code, and an exception is not
thrown by (symlink_)status in this case.

The fix is to test the returned file status and return if it indicates error.
Also, avoid using the external error code to receive error code from
(symlink_)status to keep it clean if copy operation succeeds.

A similar problem has been fixed in Windows implementation of space operation.

Fixes https://github.com/boostorg/filesystem/issues/152.
2020-07-07 15:49:05 +03:00
Andrey Semashev
d0a7a23a1a Marked windows_file_codecvt as visible instead of dllexport.
windows_file_codecvt is not exported from Boost.Filesystem and is
only used internally. It needs to be visible, where it matters
(which, given that this component is Windows-specific, is probably
nowhere).
2020-07-02 13:40:21 +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 c758552338 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
917f46f9f3 Avoid integer overflow and narrowing conversion in NTSTATUS error codes.
Closes https://github.com/boostorg/filesystem/pull/149.
2020-06-09 14:42:13 +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
5dff490d18 Fixed incorrect pointer adjustment. 2020-06-05 11:22:13 +03:00
Andrey Semashev
7487e33da9 Added unique_path implementation based on BCrypt API on Windows. 2020-06-05 03:17:24 +03:00
Andrey Semashev
5a2568af89 Ported unique_path wincrypt implementation to Boost.WinAPI. 2020-06-05 02:14:30 +03:00
Andrey Semashev
eab0e77f24 Added implementation of unique_path based on arc4random. 2020-06-05 01:40:52 +03:00
Andrey Semashev
e2e4b85ee0 Added unique_path based on Linux getrandom system call.
The new backend is not vulnerable to file descriptor exhaustion attacks.
2020-06-05 01:22:55 +03:00
Andrey Semashev
432f4da6ed Code cleanup in unique_path implementation.
Use the common functions for indicating failure.

In POSIX version, check for EINTR error code when reading from
/dev/(u)random and return the appropriate error code.

On Windows, use the proper type for error code. Also, include
winapi/config.hpp to let Boost.WinAPI define targer Windows version
macros.

Use unsigned types for sizes and indexes.
2020-06-05 01:21:57 +03:00
Andrey Semashev
0b50e1b527 Converted some uses of size() to empty().
c.size() methods were used to test if c was empty in a few places,
so the change is purely for code clarity.

Partly based on https://github.com/boostorg/filesystem/pull/145.
2020-06-05 00:24:59 +03:00
Andrey Semashev
6146fdf161 Use emit_error to unconditionally indicate BOOST_ERROR_NOT_SUPPORTED errors. 2020-05-23 17:22:23 +03:00
whitequark
c34025d5a4 Add WASI platform support.
WASI is a POSIX-like platform that has a few important differences:
  * There is no concept of a mutable current directory.
  * There is no concept of a file mode, and no `chmod` call.
  * There is no concept of a filesystem, and no `statfs` call.
  * There is no `readdir_r` call because there are no threads.
2020-05-23 14:13:46 +00: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