2016-02-25 16:43:19 +00:00
|
|
|
#pragma once
|
2023-04-01 03:18:41 +00:00
|
|
|
///@file
|
2016-02-25 16:43:19 +00:00
|
|
|
|
|
|
|
#include "types.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2023-04-07 13:55:28 +00:00
|
|
|
/**
|
|
|
|
* An abstract class for accessing a filesystem-like structure, such
|
|
|
|
* as a (possibly remote) Nix store or the contents of a NAR file.
|
|
|
|
*/
|
2016-02-25 16:43:19 +00:00
|
|
|
class FSAccessor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Type { tMissing, tRegular, tSymlink, tDirectory };
|
|
|
|
|
|
|
|
struct Stat
|
|
|
|
{
|
2017-12-06 21:44:08 +00:00
|
|
|
Type type = tMissing;
|
2023-04-07 13:55:28 +00:00
|
|
|
/**
|
|
|
|
* regular files only
|
|
|
|
*/
|
|
|
|
uint64_t fileSize = 0;
|
|
|
|
/**
|
|
|
|
* regular files only
|
|
|
|
*/
|
2017-12-06 21:44:08 +00:00
|
|
|
bool isExecutable = false; // regular files only
|
2023-04-07 13:55:28 +00:00
|
|
|
/**
|
|
|
|
* regular files only
|
|
|
|
*/
|
2017-12-06 21:44:08 +00:00
|
|
|
uint64_t narOffset = 0; // regular files only
|
2016-02-25 16:43:19 +00:00
|
|
|
};
|
|
|
|
|
2019-09-20 11:48:53 +00:00
|
|
|
virtual ~FSAccessor() { }
|
|
|
|
|
2016-02-25 16:43:19 +00:00
|
|
|
virtual Stat stat(const Path & path) = 0;
|
|
|
|
|
|
|
|
virtual StringSet readDirectory(const Path & path) = 0;
|
|
|
|
|
2020-12-15 09:54:24 +00:00
|
|
|
/**
|
|
|
|
* Read a file inside the store.
|
|
|
|
*
|
|
|
|
* If `requireValidPath` is set to `true` (the default), the path must be
|
|
|
|
* inside a valid store path, otherwise it just needs to be physically
|
|
|
|
* present (but not necessarily properly registered)
|
|
|
|
*/
|
|
|
|
virtual std::string readFile(const Path & path, bool requireValidPath = true) = 0;
|
2016-02-25 16:43:19 +00:00
|
|
|
|
|
|
|
virtual std::string readLink(const Path & path) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|