58 memcpy(Hdr.
Magic,
"ustar", 5);
71 int Len = Key.size() + Val.
size() + 3;
77 return (
Twine(
Total) +
" " + Key +
"=" + Val +
"\n").str();
95 for (
size_t I = 0;
I <
sizeof(Hdr); ++
I)
96 Chksum +=
reinterpret_cast<uint8_t *
>(&Hdr)[
I];
104 std::string PaxAttr =
formatPax(
"path", Path);
108 snprintf(Hdr.
Size,
sizeof(Hdr.
Size),
"%011zo", PaxAttr.size());
113 OS << StringRef(reinterpret_cast<char *>(&Hdr),
sizeof(Hdr));
143 const int MaxPrefix = 137;
144 size_t Sep = Path.rfind(
'/', MaxPrefix + 1);
150 Prefix = Path.substr(0, Sep);
151 Name = Path.substr(Sep + 1);
161 memcpy(Hdr.
Mode,
"0000664", 8);
163 memcpy(Hdr.
Prefix, Prefix.data(), Prefix.size());
165 OS << StringRef(reinterpret_cast<char *>(&Hdr),
sizeof(Hdr));
171 using namespace sys::fs;
173 if (std::error_code EC =
174 openFileForWrite(OutputPath, FD, CD_CreateAlways, OF_None))
175 return make_error<StringError>(
"cannot open " + OutputPath, EC);
176 return std::unique_ptr<TarWriter>(
new TarWriter(FD, BaseDir));
179TarWriter::TarWriter(
int FD,
StringRef BaseDir)
189 if (!Files.
insert(Fullpath).second)
static void writePaxHeader(raw_fd_ostream &OS, StringRef Path)
static void writeUstarHeader(raw_fd_ostream &OS, StringRef Prefix, StringRef Name, size_t Size)
static void pad(raw_fd_ostream &OS)
static std::string formatPax(StringRef Key, StringRef Val)
static UstarHeader makeUstarHeader()
static const int BlockSize
static void computeChecksum(UstarHeader &Hdr)
static bool splitUstar(StringRef Path, StringRef &Prefix, StringRef &Name)
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
static constexpr size_t npos
std::pair< typename Base::iterator, bool > insert(StringRef key)
static Expected< std::unique_ptr< TarWriter > > create(StringRef OutputPath, StringRef BaseDir)
void append(StringRef Path, StringRef Data)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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.
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.
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.