72 int Len = Key.
size() + Val.
size() + 3;
76 int Total = Len +
Twine(Len).
str().size();
77 Total = Len +
Twine(Total).
str().size();
78 return (
Twine(Total) +
" " + Key +
"=" + Val +
"\n").str();
84 uint64_t Pos = OS.
tell();
96 for (
size_t I = 0;
I <
sizeof(Hdr); ++
I)
97 Chksum += reinterpret_cast<uint8_t *>(&Hdr)[
I];
105 std::string PaxAttr =
formatPax(
"path", Path);
109 snprintf(Hdr.
Size,
sizeof(Hdr.
Size),
"%011zo", PaxAttr.size());
114 OS << StringRef(reinterpret_cast<char *>(&Hdr),
sizeof(Hdr));
141 Prefix = Path.
substr(0, Sep);
142 Name = Path.
substr(Sep + 1);
153 snprintf(Hdr.
Size,
sizeof(Hdr.
Size),
"%011zo", Size);
156 OS << StringRef(reinterpret_cast<char *>(&Hdr),
sizeof(Hdr));
162 using namespace sys::fs;
164 if (std::error_code EC =
166 return make_error<StringError>(
"cannot open " + OutputPath, EC);
167 return std::unique_ptr<TarWriter>(
new TarWriter(FD, BaseDir));
170 TarWriter::TarWriter(
int FD,
StringRef BaseDir)
171 : OS(FD,
true,
false), BaseDir(BaseDir) {}
179 if (!Files.insert(Fullpath).second)
197 uint64_t Pos = OS.tell();
This class represents lattice values for constants.
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
std::string convert_to_slash(StringRef path, Style style=Style::native)
Replaces backslashes with slashes if Windows.
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Tagged union holding either a T or a Error.
static bool splitUstar(StringRef Path, StringRef &Prefix, StringRef &Name)
static void computeChecksum(UstarHeader &Hdr)
static void pad(raw_fd_ostream &OS)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static UstarHeader makeUstarHeader()
static void writePaxHeader(raw_fd_ostream &OS, StringRef Path)
static Expected< std::unique_ptr< TarWriter > > create(StringRef OutputPath, StringRef BaseDir)
static std::string formatPax(StringRef Key, StringRef Val)
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
static const char *const Magic
static const int BlockSize
static void writeUstarHeader(raw_fd_ostream &OS, StringRef Prefix, StringRef Name, size_t Size)
A raw_ostream that writes to a file descriptor.
std::string str() const
Return the twine contents as a std::string.
CD_CreateAlways - When opening a file:
uint64_t tell() const
tell - Return the current offset with the file.
StringRef - Represent a constant reference to a string, i.e.
void append(StringRef Path, StringRef Data)