LLVM: lib/Support/TarWriter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
29
30using namespace llvm;
31
32
34
55
58 memcpy(Hdr.Magic, "ustar", 5);
59 memcpy(Hdr.Version, "00", 2);
60 return Hdr;
61}
62
63
64
65
66
67
68
69
71 int Len = Key.size() + Val.size() + 3;
72
73
74
77 return (Twine(Total) + " " + Key + "=" + Val + "\n").str();
78}
79
80
81
86
87
89
90
92
93
94 unsigned Chksum = 0;
95 for (size_t I = 0; I < sizeof(Hdr); ++I)
96 Chksum += reinterpret_cast<uint8_t *>(&Hdr)[I];
98}
99
100
102
103
104 std::string PaxAttr = formatPax("path", Path);
105
106
108 snprintf(Hdr.Size, sizeof(Hdr.Size), "%011zo", PaxAttr.size());
109 Hdr.TypeFlag = 'x';
111
112
113 OS << StringRef(reinterpret_cast<char *>(&Hdr), sizeof(Hdr));
114 OS << PaxAttr;
116}
117
118
119
120
121
122
123
124
125
126
129 Prefix = "";
130 Name = Path;
131 return true;
132 }
133
134
135
136
137
138
139
140
141
142
143 const int MaxPrefix = 137;
144 size_t Sep = Path.rfind('/', MaxPrefix + 1);
146 return false;
148 return false;
149
150 Prefix = Path.substr(0, Sep);
151 Name = Path.substr(Sep + 1);
152 return true;
153}
154
155
156
160 memcpy(Hdr.Name, Name.data(), Name.size());
161 memcpy(Hdr.Mode, "0000664", 8);
162 snprintf(Hdr.Size, sizeof(Hdr.Size), "%011zo", Size);
163 memcpy(Hdr.Prefix, Prefix.data(), Prefix.size());
165 OS << StringRef(reinterpret_cast<char *>(&Hdr), sizeof(Hdr));
166}
167
168
172 int FD;
173 if (std::error_code EC =
174 openFileForWrite(OutputPath, FD, CD_CreateAlways, OF_None))
176 return std::unique_ptr(new TarWriter(FD, BaseDir));
177}
178
179TarWriter::TarWriter(int FD, StringRef BaseDir)
181 BaseDir(std::string(BaseDir)) {}
182
183
185
187
188
189 if (!Files.insert(Fullpath).second)
190 return;
191
194 if (splitUstar(Fullpath, Prefix, Name)) {
196 } else {
199 }
200
203
204
205
206
208 OS << std::string(BlockSize * 2, '\0');
209 OS.seek(Pos);
210 OS.flush();
211}
static void writePaxHeader(raw_fd_ostream &OS, StringRef Path)
Definition TarWriter.cpp:101
static void writeUstarHeader(raw_fd_ostream &OS, StringRef Prefix, StringRef Name, size_t Size)
Definition TarWriter.cpp:157
static void pad(raw_fd_ostream &OS)
Definition TarWriter.cpp:82
static std::string formatPax(StringRef Key, StringRef Val)
Definition TarWriter.cpp:70
static UstarHeader makeUstarHeader()
Definition TarWriter.cpp:56
static const int BlockSize
Definition TarWriter.cpp:33
static void computeChecksum(UstarHeader &Hdr)
Definition TarWriter.cpp:88
static bool splitUstar(StringRef Path, StringRef &Prefix, StringRef &Name)
Definition TarWriter.cpp:127
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
static constexpr size_t npos
constexpr size_t size() const
size - Get the string size.
static LLVM_ABI Expected< std::unique_ptr< TarWriter > > create(StringRef OutputPath, StringRef BaseDir)
Definition TarWriter.cpp:169
LLVM_ABI void append(StringRef Path, StringRef Data)
Definition TarWriter.cpp:184
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
A raw_ostream that writes to a file descriptor.
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
uint64_t tell() const
tell - Return the current offset with the file.
LLVM_ABI std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Implement std::hash so that hash_code can be used in STL containers.