Commit Graph

1414 Commits

Author SHA1 Message Date
Andrey Semashev
c9f808d4d8 Added AppVeyor CI job for MinGW-w64 gcc 8. 2021-06-09 15:58:31 +03:00
Andrey Semashev
915a5739be Made wide character concatenation more explicit. 2021-06-09 15:23:57 +03:00
Andrey Semashev
639b5aaf8c Added path assignment from rvalue reference to string. 2021-06-07 00:20:04 +03:00
Andrey Semashev
2ba6fa38a1 Added path constructor from rvalue reference to string. 2021-06-07 00:16:55 +03:00
Andrey Semashev
179878d39e Enable wide character paths for file streams with more standard libraries.
libstdc++ starting 8.1.0 in C++17 mode support std::filesystem and is able to
open the file streams with std::filesystem::path constructible from wide
strings.

libc++ starting 7.0 also supports std::filesystem::path in C++17 mode and may
also support passing `const wchar_t*` strings to open files.

Closes https://github.com/boostorg/filesystem/issues/181.
2021-06-07 00:10: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
c11764e38a Fixed path_test on POSIX systems. 2021-06-06 12:25:55 +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
491369de3f Removed mention of error code for current_path when it is not supported.
We may change error codes reported for unsupported functions in the future,
so don't document them for now.

[ci skip]
2021-05-29 17:15:27 +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
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
45606c2f23 Disable building examples in tests by default. 2021-05-20 23:39:06 +03:00
Andrey Semashev
d5360cf925 Added copy_sile tests for multi-stream files on Windows. 2021-05-20 23:33:31 +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
d50b800a37 Revert "Switched clang 10-12 to Focal in Travis CI."
This reverts commit 98adf24841.

Reason for revert: Package installation errors on Focal.
2021-05-20 12:37:05 +03:00
Andrey Semashev
98adf24841 Switched clang 10-12 to Focal in Travis CI.
This improves testing diversity.
2021-05-20 03:18:08 +03:00
Andrey Semashev
bc5b49e239 Added single-threaded builds to CI. 2021-05-20 02:48:55 +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
8124c115ed Compile examples on a newer gcc as some examples require C++11. 2021-05-19 04:16:15 +03:00
Andrey Semashev
0ada9c0ec2 Force C++11 for compiling examples that are using C++11 features. 2021-05-19 04:14:24 +03:00
Andrey Semashev
4849b6c506 Added building examples in CI. 2021-05-19 03:19:08 +03:00
Andrey Semashev
bb116b96f6 Removed example testing scripts as they are unused. 2021-05-19 03:19:08 +03:00
Andrey Semashev
2accecc330 Removed machine-specific scripts that are not used anymore. 2021-05-19 03:19:08 +03:00
Andrey Semashev
8dbb31f686 Removed files with test results. 2021-05-19 03:19:08 +03:00
Andrey Semashev
a59bce0708 Removed unused include. 2021-05-19 03:19:08 +03:00