mirror of
https://github.com/NixOS/nix
synced 2025-07-06 05:01:48 +02:00
Merge InputAccessor into SourceAccessor
After the removal of the InputAccessor::fetchToStore() method, the only remaining functionality in InputAccessor was `fingerprint` and `getLastModified()`, and there is no reason to keep those in a separate class.
This commit is contained in:
parent
00ca2b05b8
commit
ba5929c7be
35 changed files with 130 additions and 188 deletions
|
@ -1,27 +0,0 @@
|
|||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "source-accessor.hh"
|
||||
#include "ref.hh"
|
||||
#include "repair-flag.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
MakeError(RestrictedPathError, Error);
|
||||
|
||||
struct InputAccessor : virtual SourceAccessor, std::enable_shared_from_this<InputAccessor>
|
||||
{
|
||||
std::optional<std::string> fingerprint;
|
||||
|
||||
/**
|
||||
* Return the maximum last-modified time of the files in this
|
||||
* tree, if available.
|
||||
*/
|
||||
virtual std::optional<time_t> getLastModified()
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -108,7 +108,7 @@ std::string MemorySourceAccessor::readLink(const CanonPath & path)
|
|||
throw Error("file '%s' is not a symbolic link", path);
|
||||
}
|
||||
|
||||
CanonPath MemorySourceAccessor::addFile(CanonPath path, std::string && contents)
|
||||
SourcePath MemorySourceAccessor::addFile(CanonPath path, std::string && contents)
|
||||
{
|
||||
auto * f = open(path, File { File::Regular {} });
|
||||
if (!f)
|
||||
|
@ -118,7 +118,7 @@ CanonPath MemorySourceAccessor::addFile(CanonPath path, std::string && contents)
|
|||
else
|
||||
throw Error("file '%s' is not a regular file", path);
|
||||
|
||||
return path;
|
||||
return SourcePath{ref(shared_from_this()), path};
|
||||
}
|
||||
|
||||
|
||||
|
@ -184,4 +184,10 @@ void MemorySink::createSymlink(const Path & path, const std::string & target)
|
|||
throw Error("file '%s' is not a symbolic link", path);
|
||||
}
|
||||
|
||||
ref<SourceAccessor> makeEmptySourceAccessor()
|
||||
{
|
||||
static auto empty = make_ref<MemorySourceAccessor>().cast<SourceAccessor>();
|
||||
return empty;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "source-accessor.hh"
|
||||
#include "source-path.hh"
|
||||
#include "fs-sink.hh"
|
||||
#include "variant-wrapper.hh"
|
||||
|
||||
|
@ -69,7 +69,7 @@ struct MemorySourceAccessor : virtual SourceAccessor
|
|||
*/
|
||||
File * open(const CanonPath & path, std::optional<File> create);
|
||||
|
||||
CanonPath addFile(CanonPath path, std::string && contents);
|
||||
SourcePath addFile(CanonPath path, std::string && contents);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,7 +35,7 @@ enum class SymlinkResolution {
|
|||
* filesystem-like entities (such as the real filesystem, tarballs or
|
||||
* Git repositories).
|
||||
*/
|
||||
struct SourceAccessor
|
||||
struct SourceAccessor : std::enable_shared_from_this<SourceAccessor>
|
||||
{
|
||||
const size_t number;
|
||||
|
||||
|
@ -168,6 +168,30 @@ struct SourceAccessor
|
|||
CanonPath resolveSymlinks(
|
||||
const CanonPath & path,
|
||||
SymlinkResolution mode = SymlinkResolution::Full);
|
||||
|
||||
/**
|
||||
* A string that uniquely represents the contents of this
|
||||
* accessor. This is used for caching lookups (see `fetchToStore()`).
|
||||
*/
|
||||
std::optional<std::string> fingerprint;
|
||||
|
||||
/**
|
||||
* Return the maximum last-modified time of the files in this
|
||||
* tree, if available.
|
||||
*/
|
||||
virtual std::optional<time_t> getLastModified()
|
||||
{ return std::nullopt; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a source accessor that contains only an empty root directory.
|
||||
*/
|
||||
ref<SourceAccessor> makeEmptySourceAccessor();
|
||||
|
||||
/**
|
||||
* Exception thrown when accessing a filtered path (see
|
||||
* `FilteringInputAccessor`).
|
||||
*/
|
||||
MakeError(RestrictedPathError, Error);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@ std::string SourcePath::readFile() const
|
|||
bool SourcePath::pathExists() const
|
||||
{ return accessor->pathExists(path); }
|
||||
|
||||
InputAccessor::Stat SourcePath::lstat() const
|
||||
SourceAccessor::Stat SourcePath::lstat() const
|
||||
{ return accessor->lstat(path); }
|
||||
|
||||
std::optional<InputAccessor::Stat> SourcePath::maybeLstat() const
|
||||
std::optional<SourceAccessor::Stat> SourcePath::maybeLstat() const
|
||||
{ return accessor->maybeLstat(path); }
|
||||
|
||||
InputAccessor::DirEntries SourcePath::readDirectory() const
|
||||
SourceAccessor::DirEntries SourcePath::readDirectory() const
|
||||
{ return accessor->readDirectory(path); }
|
||||
|
||||
std::string SourcePath::readLink() const
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "ref.hh"
|
||||
#include "canon-path.hh"
|
||||
#include "input-accessor.hh"
|
||||
#include "source-accessor.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
@ -19,10 +19,10 @@ namespace nix {
|
|||
*/
|
||||
struct SourcePath
|
||||
{
|
||||
ref<InputAccessor> accessor;
|
||||
ref<SourceAccessor> accessor;
|
||||
CanonPath path;
|
||||
|
||||
SourcePath(ref<InputAccessor> accessor, CanonPath path = CanonPath::root)
|
||||
SourcePath(ref<SourceAccessor> accessor, CanonPath path = CanonPath::root)
|
||||
: accessor(std::move(accessor))
|
||||
, path(std::move(path))
|
||||
{ }
|
||||
|
@ -51,19 +51,19 @@ struct SourcePath
|
|||
* Return stats about this `SourcePath`, or throw an exception if
|
||||
* it doesn't exist.
|
||||
*/
|
||||
InputAccessor::Stat lstat() const;
|
||||
SourceAccessor::Stat lstat() const;
|
||||
|
||||
/**
|
||||
* Return stats about this `SourcePath`, or std::nullopt if it
|
||||
* doesn't exist.
|
||||
*/
|
||||
std::optional<InputAccessor::Stat> maybeLstat() const;
|
||||
std::optional<SourceAccessor::Stat> maybeLstat() const;
|
||||
|
||||
/**
|
||||
* If this `SourcePath` denotes a directory (not a symlink),
|
||||
* return its directory entries; otherwise throw an error.
|
||||
*/
|
||||
InputAccessor::DirEntries readDirectory() const;
|
||||
SourceAccessor::DirEntries readDirectory() const;
|
||||
|
||||
/**
|
||||
* If this `SourcePath` denotes a symlink, return its target;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue