mirror of
https://github.com/NixOS/nix
synced 2025-06-28 01:11:15 +02:00
Use std::filesystem
functions in more places
This makes for shorter and more portable code. The only tricky part is catching exceptions: I just searched for near by `catch (Error &)` or `catch (SysError &)` and adjusted them to `catch (std::filesystem::filesystem_error &)` according to my human judgement. Good for windows portability; will help @siddhantk232 with his GSOC project.
This commit is contained in:
parent
b4950404ba
commit
c371070580
14 changed files with 61 additions and 99 deletions
|
@ -27,13 +27,6 @@
|
|||
#include <sstream>
|
||||
#include <optional>
|
||||
|
||||
#ifndef HAVE_STRUCT_DIRENT_D_TYPE
|
||||
#define DT_UNKNOWN 0
|
||||
#define DT_REG 1
|
||||
#define DT_LNK 2
|
||||
#define DT_DIR 3
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Polyfill for MinGW
|
||||
*
|
||||
|
@ -132,20 +125,16 @@ bool isLink(const Path & path);
|
|||
struct DirEntry
|
||||
{
|
||||
std::string name;
|
||||
ino_t ino;
|
||||
/**
|
||||
* one of DT_*
|
||||
*/
|
||||
unsigned char type;
|
||||
DirEntry(std::string name, ino_t ino, unsigned char type)
|
||||
: name(std::move(name)), ino(ino), type(type) { }
|
||||
std::filesystem::file_type type;
|
||||
DirEntry(std::string name, std::filesystem::file_type type)
|
||||
: name(std::move(name)), type(type) { }
|
||||
};
|
||||
|
||||
typedef std::vector<DirEntry> DirEntries;
|
||||
|
||||
DirEntries readDirectory(const Path & path);
|
||||
|
||||
unsigned char getFileType(const Path & path);
|
||||
std::filesystem::file_type getFileType(const Path & path);
|
||||
|
||||
/**
|
||||
* Read the contents of a file into a string.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue