Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
tarfile.hh
Go to the documentation of this file.
1#pragma once
3
5
6#include <exception>
7
8struct archive;
9
10namespace nix {
11
12struct Source;
13struct Sink;
14class CanonPath;
15
16struct TarArchive
17{
18 ::archive * archive;
19 Source * source;
20 std::vector<unsigned char> buffer;
21 /* Exception encountered when reading the source. */
22 std::exception_ptr readException;
23
24 void check(int err, const std::string & reason = "failed to extract archive (%s)", bool warningsAreFatal = true);
25
26 explicit TarArchive(const std::filesystem::path & path);
27
35 TarArchive(Source & source, bool raw = false, std::optional<CompressionAlgo> compressionMethod = std::nullopt);
36 TarArchive(const TarArchive &) = delete;
37 TarArchive & operator=(const TarArchive &) = delete;
38 TarArchive(TarArchive &&) = delete;
39 TarArchive & operator=(TarArchive &&) = delete;
40 ~TarArchive();
41
42 void close();
43};
44
45void unpackTarfile(const std::filesystem::path & tarFile, const std::filesystem::path & destDir);
46
57struct TarSink
58{
59 virtual ~TarSink();
60
61 virtual void createDirectory(const CanonPath & path) = 0;
62
63 virtual void createRegularFile(const CanonPath & path, bool isExecutable, fun<void(Sink &)> callback) = 0;
64
65 virtual void createSymlink(const CanonPath & path, const std::string & target) = 0;
66
71 virtual void createHardlink(const CanonPath & path, const CanonPath & target) = 0;
72};
73
77struct NullTarSink : TarSink
78{
79 NullTarSink() {}
80
81 ~NullTarSink();
82
83 void createDirectory(const CanonPath & path) override {}
84
85 void createRegularFile(const CanonPath & path, bool isExecutable, fun<void(Sink &)> callback) override;
86
87 void createSymlink(const CanonPath & path, const std::string & target) override {}
88
89 void createHardlink(const CanonPath & path, const CanonPath & target) override {}
90};
91
92time_t unpackTarfileToSink(TarArchive & archive, TarSink & parseSink);
93
94} // namespace nix
Definition canon-path.hh:50
Definition fun.hh:19
void createHardlink(const CanonPath &path, const CanonPath &target) override
Definition tarfile.hh:89
Definition serialise.hh:18
Definition serialise.hh:95
Definition tarfile.hh:58
virtual void createHardlink(const CanonPath &path, const CanonPath &target)=0