31 #ifndef _SCC_UTIL_FS_H
32 #define _SCC_UTIL_FS_H
38 #include <system_error>
104 static void remove_file(
const std::string&, std::system_error*);
105 static void remove_dir(
const std::string&, std::system_error*);
106 static void remove_all(
const std::string&,
const FileType&, std::system_error*);
122 static std::map<std::string, FileType>
scan_dir(
const std::string&,
153 static void set_mode(
const std::string&,
unsigned, std::system_error* =
nullptr);
166 static void set_times(
const std::string&, uint64_t, uint64_t, std::system_error* =
nullptr);
177 static void set_ids(
const std::string&,
int,
int, std::system_error* =
nullptr);
192 static void set_size(
const std::string&, off_t, std::system_error* =
nullptr);
212 static std::map<off_t, off_t>
sparse_map(
const std::string&, std::system_error* =
nullptr);
216 static void remove(
const std::string&, std::system_error* =
nullptr);
222 static void rename(
const std::string&,
const std::string&, std::system_error* =
nullptr);
226 static void remove_all(
const std::string& fn, std::system_error* err =
nullptr)
230 remove_all(fn, ty, err);
240 static void create_dir(
const std::string&, std::system_error* =
nullptr);
253 static void create_reg(
const std::string&, std::system_error* =
nullptr);
261 static std::string
create_tmp_reg(
const std::string&, std::system_error* =
nullptr);
273 static void create_symlink(
const std::string&,
const std::string&, std::system_error* =
nullptr);
285 static void create_link(
const std::string&,
const std::string&, std::system_error* =
nullptr);
291 static void create_fifo(
const std::string&, std::system_error* =
nullptr);
295 static void change_dir(
const std::string&, std::system_error* =
nullptr);
311 static std::string
read_symlink(
const std::string&, std::system_error* =
nullptr);
335 static std::string
norm_path(
const std::string&,
const std::string&) noexcept;
340 static std::string
norm_path(
const std::string& path) noexcept
350 void PrintTo(
const FileStat&, std::ostream*);
352 void PrintTo(
const FileType&, std::ostream*);
Common file system utilities.
static std::string get_current_dir(std::system_error *=nullptr)
Get working directory.
static void create_reg(const std::string &, std::system_error *=nullptr)
Create a regular file.
static std::string norm_path(const std::string &, const std::string &) noexcept
Normalize a path with base directory.
static void create_symlink(const std::string &, const std::string &, std::system_error *=nullptr)
Create a symbolic link.
static void rename(const std::string &, const std::string &, std::system_error *=nullptr)
Rename the file or directory.
static void create_link(const std::string &, const std::string &, std::system_error *=nullptr)
Create a hard link.
static void set_ids(const std::string &, int, int, std::system_error *=nullptr)
Set the user id and/or group id.
static void create_fifo(const std::string &, std::system_error *=nullptr)
Create a named pipe (FIFO).
static FileType file_type(const std::string &, std::system_error *=nullptr)
Get the file type.
static std::map< std::string, FileType > scan_dir(const std::string &, std::function< bool(const std::string &, FileType)>=default_scan_filter, std::system_error *=nullptr)
Scan a directory, and return a map of names and file types.
static void remove_all(const std::string &fn, std::system_error *err=nullptr)
Recursively removes the file or directory.
static FileStat file_stat(const std::string &, std::system_error *=nullptr)
Get the file stat.
static std::string norm_path(const std::string &path) noexcept
Normalize a path.
static std::string read_symlink(const std::string &, std::system_error *=nullptr)
Read the location of a symbolic link target.
static void set_size(const std::string &, off_t, std::system_error *=nullptr)
Set the file size.
static std::string create_tmp_reg(const std::string &, std::system_error *=nullptr)
Create a temporary regular file.
static void change_dir(const std::string &, std::system_error *=nullptr)
Change working directory.
static void remove(const std::string &, std::system_error *=nullptr)
Remove the file or directory.
static std::map< off_t, off_t > sparse_map(const std::string &, std::system_error *=nullptr)
Map of file sparseness.
static void create_dir(const std::string &, std::system_error *=nullptr)
Create a directory.
static void set_mode(const std::string &, unsigned, std::system_error *=nullptr)
Set the file mode.
static void set_times(const std::string &, uint64_t, uint64_t, std::system_error *=nullptr)
Set the file times.
bool default_scan_filter(const std::string &, FileType)
Default scan filter.
@ unknown
unknown or does not exist
std::ostream & operator<<(std::ostream &, const scc::net::InetAddr &)
Print the socket address details to an output stream.
uint64_t alloc_size
Real allocated size on disk.
uint64_t change_time
Last status change time; writes, permission changes, etc. (ns since epoch)
uint64_t size
Size of file.
uint64_t access_time
Last access time; reads, etc. (ns since epoch)
uint16_t num_links
Number of hard links to this inode.
uint64_t inode
Inode number.
uint64_t mod_time
Last modification time; writes, etc. (ns since epoch)
unsigned mode
File mode 07777 format (bits/user/group/all 4=read, 2=write, 3=execute, or uid/gid/sticky)