summaryrefslogtreecommitdiff
path: root/src/Stat.cpp
Commit message (Collapse)AuthorAgeFilesLines
* refactor: Use constructor member initializer listsJoel Rosdahl2023-04-191-2/+2
| | | | | As suggested by clang-tidy (cppcoreguidelines-prefer-member-initializer).
* enhance: Remember path in StatJoel Rosdahl2022-11-271-0/+1
|
* refactor: Use FMT macro to format exception messagesJoel Rosdahl2022-08-241-2/+3
| | | | | Using the FMT macro explicitly makes invalid format message constructions compile-time errors instead of run-time errors.
* Move exceptions.hpp to coreJoel Rosdahl2021-07-201-1/+2
|
* Remove system.hpp, including what’s needed insteadJoel Rosdahl2021-07-071-7/+8
| | | | This is the next step after a57f70eda32e99221de56f5499079b4f00dc2bc5.
* Stat: treat pending deletes as missing files on WindowsNicholas Hutchinson2021-04-041-0/+7
| | | | | | | | Win32 functions like `CreateFile` return `ERROR_ACCESS_DENIED` when a file is in the process of being deleted, which gets mapped to an errno of `EACCES`. For the purposes of `Stat::stat` and `Stat::lstat`, it's more useful to treat this as a missing file and mapping this to an errno of `ENOENT`.
* Implement a better Stat::stat(), Stat::lstat() for Windows (#819)Nicholas Hutchinson2021-03-181-0/+199
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `stat()` as implemented in msvcrt.dll (used by mingw-w64) has a number of flaws: - `st_ino` is always 0 - other file attributes are queried from the parent directory instead of the file itself, and so can be incorrect/stale, e.g. if a file is modified via another hard link. The implementation in the UCRT is slightly better -- it prefers to query attributes from the file itself if possible, but it still doesn't populate `st_ino` and can silently fall back to querying from the parent directory and giving stale results. I don't believe the msvcrt.dll source is available (you have to infer its behaviour from e.g. Process Monitor) but the ucrtbase.dll source code is available in the Windows 10 SDK. Write an implementation of `stat`/`lstat` that sidesteps these issues by using Win32 APIs to query file information. A few implementation notes: - We do not fall back to querying the parent directory (as the UCRT `stat()` implementation and [Python's `stat()`][1] do) if we can't get a handle to the actual file. If we don't have `FILE_READ_ATTRIBUTES` permissions, we fail with `EACCES` instead of returning incomplete/stale results fetched from the parent directory. - Windows-specific `Stat::file_attributes()` / `Stat::reparse_tag()` added to provide the Win32 file attributes and file reparse tag. - `lstat()` sets the `S_IFLNK` bit in `st_mode` for symlinks. On Windows, there are other symlink-like things ("name surrogate reparse points") such as directory junctions and mountpoints. To identify these, the caller can check the reparse tag to identify a directory junction/mountpoint. - We use Python's mapping of Win32 error codes to C errno. [1]: https://github.com/python/cpython/blob/6086ae7fd4aeb4089282189673f9bd0cc33abf9b/Modules/posixmodule.c#L1884
* Detect errors in log strings at compile timeJoel Rosdahl2020-10-231-3/+1
| | | | | | | | | | | | | | | | | | | fmtlib can detect format string errors at compile time if (1) applying FMT_STRING to the format string literal and (2) compiling for C++14 or higher. Requirement 1 is implemented by introducing a LOG macro which applies FMT_STRING to the first argument and calls Logging::log (if logging is enabled). Also added are a companion LOG_RAW macro (since C++11 requires at least one argument for the “...” part in variadic macros) and a BULK_LOG macro which calls Logging::bulk_log (if logging is enabled). Requirement 2 is implemented by setting CMAKE_CXX_STANDARD to 14 for one CI build with a known C++14-capable compiler. We can’t set it to 14 by default since we still want the code to be buildable with C++11 compilers. This will catch errors such as the one fixed by PR #691.
* Let Error constructor forward arguments to fmt::formatJoel Rosdahl2020-08-031-3/+1
|
* Convert cc_log calls to Logging::logJoel Rosdahl2020-08-031-1/+3
|
* C++-ify logging routinesJoel Rosdahl2020-08-031-1/+1
| | | | | | | | | | | | | | | - Simplified and C++-ified logging code. - Added Logging::log and Logging::bulk_log functions corresponding to the old cc_log and cc_bulklog functions. The new functions pass their arguments to fmt::format. - Replacements: * init_log → Logging::init * cc_log → Logging::log * cc_bulklog → Logging::bulk_log * cc_log_argv → Logging::log plus Util::format_argv_for_logging * cc_dump_debug_log_buffer -> Logging::dump_log - A legacy cc_log implementation is still available so that logging can be converted gradually to the new functionality.
* Move logging into separate file (#532)Thomas Otto2020-02-081-1/+1
|
* Split ccache.hpp into per-.cpp file headersJoel Rosdahl2020-01-221-2/+2
| | | | This reduces code dependencies that hamper refactoring.
* Improve functions related to (l)stat-ingJoel Rosdahl2019-10-191-0/+45
Introduced a Stat class that represents a “struct stat”. The class replaces the utility functions x_lstat, x_stat, file_size_on_disk and is_symlink, and it provides an easier to use interface than the macros associated with stat structs.