summaryrefslogtreecommitdiff
path: root/src/Util.hpp
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2021-07-19 13:29:53 +0200
committerJoel Rosdahl <joel@rosdahl.net>2021-07-20 19:42:54 +0200
commiteb266c997db8f13dd5f9e3e099f853f3a7505f7b (patch)
tree01412e5762fc0861cae68be380203124fc661c36 /src/Util.hpp
parent01e72eaa8a92cfd94cf56ccd1533804644f6a952 (diff)
downloadccache-eb266c997db8f13dd5f9e3e099f853f3a7505f7b.tar.gz
Move exceptions.hpp to core
Diffstat (limited to 'src/Util.hpp')
-rw-r--r--src/Util.hpp38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/Util.hpp b/src/Util.hpp
index 06ea153b..42c2e523 100644
--- a/src/Util.hpp
+++ b/src/Util.hpp
@@ -94,14 +94,15 @@ clamp(T value, T min, T max)
}
// Clone a file from `src` to `dest`. If `via_tmp_file` is true, `src` is cloned
-// to a temporary file and then renamed to `dest`. Throws `Error` on error.
+// to a temporary file and then renamed to `dest`. Throws `core::Error` on
+// error.
void clone_file(const std::string& src,
const std::string& dest,
bool via_tmp_file = false);
// Clone, hard link or copy a file from `source` to `dest` depending on settings
// in `ctx`. If cloning or hard linking cannot and should not be done the file
-// will be copied instead. Throws `Error` on error.
+// will be copied instead. Throws `core::Error` on error.
void clone_hard_link_or_copy_file(const Context& ctx,
const std::string& source,
const std::string& dest,
@@ -112,11 +113,11 @@ void clone_hard_link_or_copy_file(const Context& ctx,
size_t common_dir_prefix_length(nonstd::string_view dir,
nonstd::string_view path);
-// Copy all data from `fd_in` to `fd_out`. Throws `Error` on error.
+// Copy all data from `fd_in` to `fd_out`. Throws `core::Error` on error.
void copy_fd(int fd_in, int fd_out);
// Copy a file from `src` to `dest`. If via_tmp_file is true, `src` is copied to
-// a temporary file and then renamed to dest. Throws `Error` on error.
+// a temporary file and then renamed to dest. Throws `core::Error` on error.
void copy_file(const std::string& src,
const std::string& dest,
bool via_tmp_file = false);
@@ -133,7 +134,7 @@ nonstd::string_view dir_name(nonstd::string_view path);
void ensure_dir_exists(nonstd::string_view dir);
// Expand all instances of $VAR or ${VAR}, where VAR is an environment variable,
-// in `str`. Throws `Error` if one of the environment variables.
+// in `str`. Throws `core::Error` if one of the environment variables.
[[nodiscard]] std::string expand_environment_variables(const std::string& str);
// Extends file size to at least new_size by calling posix_fallocate() if
@@ -220,7 +221,7 @@ const char* get_hostname();
std::string get_relative_path(nonstd::string_view dir,
nonstd::string_view path);
-// Hard-link `oldpath` to `newpath`. Throws `Error` on error.
+// Hard-link `oldpath` to `newpath`. Throws `core::Error` on error.
void hard_link(const std::string& oldpath, const std::string& newpath);
// Write bytes in big endian order from an integer value.
@@ -305,12 +306,12 @@ bool matches_dir_prefix_or_file(nonstd::string_view dir_prefix_or_file,
std::string normalize_absolute_path(nonstd::string_view path);
// Parse `duration`, an unsigned integer with d (days) or s (seconds) suffix,
-// into seconds. Throws `Error` on error.
+// into seconds. Throws `core::Error` on error.
uint64_t parse_duration(const std::string& duration);
// Parse a "size value", i.e. a string that can end in k, M, G, T (10-based
// suffixes) or Ki, Mi, Gi, Ti (2-based suffixes). For backward compatibility, K
-// is also recognized as a synonym of k. Throws `Error` on parse error.
+// is also recognized as a synonym of k. Throws `core::Error` on parse error.
uint64_t parse_size(const std::string& value);
// Read data from `fd` until end of file and call `data_receiver` with the read
@@ -321,8 +322,8 @@ bool read_fd(int fd, DataReceiver data_receiver);
// Return `path`'s content as a string. If `size_hint` is not 0 then assume that
// `path` has this size (this saves system calls).
//
-// Throws `Error` on error. The description contains the error message without
-// the path.
+// Throws `core::Error` on error. The description contains the error message
+// without the path.
std::string read_file(const std::string& path, size_t size_hint = 0);
#ifndef _WIN32
@@ -340,7 +341,8 @@ std::string real_path(const std::string& path,
// extension as determined by `get_extension()`.
nonstd::string_view remove_extension(nonstd::string_view path);
-// Rename `oldpath` to `newpath` (deleting `newpath`). Throws `Error` on error.
+// Rename `oldpath` to `newpath` (deleting `newpath`). Throws `core::Error` on
+// error.
void rename(const std::string& oldpath, const std::string& newpath);
// Detmine if `program_name` is equal to `canonical_program_name`. On Windows,
@@ -351,8 +353,8 @@ bool same_program_name(nonstd::string_view program_name,
// Send `text` to STDERR_FILENO, optionally stripping ANSI color sequences if
// `ctx.args_info.strip_diagnostics_colors` is true and rewriting paths to
-// absolute if `ctx.config.absolute_paths_in_stderr` is true. Throws `Error` on
-// error.
+// absolute if `ctx.config.absolute_paths_in_stderr` is true. Throws
+// `core::Error` on error.
void send_to_stderr(const Context& ctx, const std::string& text);
// Set the FD_CLOEXEC on file descriptor `fd`. This is a NOP on Windows.
@@ -393,7 +395,7 @@ std::vector<std::string> split_into_strings(
// Traverse `path` recursively (postorder, i.e. files are visited before their
// parent directory).
//
-// Throws Error on error.
+// Throws core::Error on error.
void traverse(const std::string& path, const TraverseVisitor& visitor);
// Remove `path` (non-directory), NFS safe. Logs according to `unlink_log`.
@@ -420,18 +422,18 @@ void update_mtime(const std::string& path);
// Remove `path` (and its contents if it's a directory). A nonexistent path is
// not considered an error.
//
-// Throws Error on error.
+// Throws core::Error on error.
void wipe_path(const std::string& path);
-// Write `size` bytes from `data` to `fd`. Throws `Error` on error.
+// Write `size` bytes from `data` to `fd`. Throws `core::Error` on error.
void write_fd(int fd, const void* data, size_t size);
// Write `data` to `path`. The file will be opened according to `open_mode`,
// which always will include `std::ios::out` even if not specified at the call
// site.
//
-// Throws `Error` on error. The description contains the error message without
-// the path.
+// Throws `core::Error` on error. The description contains the error message
+// without the path.
void write_file(const std::string& path,
const std::string& data,
std::ios_base::openmode open_mode = std::ios::binary);