59 memcpy(Hdr.
Magic,
"ustar", 5);
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));
136 std::tie(Prefix, Name) =
splitPath(Path);
145 std::tie(Prefix, Name) =
splitPath(Path);
149 memcpy(Hdr.
Mode,
"0000664", 8);
150 snprintf(Hdr.
Size,
sizeof(Hdr.
Size),
"%011zo", Size);
153 OS << StringRef(reinterpret_cast<char *>(&Hdr),
sizeof(Hdr));
161 return make_error<StringError>(
"cannot open " + OutputPath, EC);
162 return std::unique_ptr<TarWriter>(
new TarWriter(FD, BaseDir));
165 TarWriter::TarWriter(
int FD,
StringRef BaseDir)
166 : OS(FD,
true,
false), BaseDir(BaseDir) {}
185 uint64_t Pos = OS.
tell();
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
static void writeUstarHeader(raw_fd_ostream &OS, StringRef Path, size_t Size)
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...
static std::pair< StringRef, StringRef > splitPath(StringRef Path)
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Tagged union holding either a T or a Error.
uint64_t tell() const
tell - Return the current offset with the file.
Function Alias Analysis false
static void computeChecksum(UstarHeader &Hdr)
static void pad(raw_fd_ostream &OS)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static UstarHeader makeUstarHeader()
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 void writePaxHeader(raw_fd_ostream &OS, StringRef Path)
static bool fitsInUstar(StringRef Path)
static Expected< std::unique_ptr< TarWriter > > create(StringRef OutputPath, StringRef BaseDir)
static std::string formatPax(StringRef Key, StringRef Val)
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
static const char *const Magic
static const int BlockSize
A raw_ostream that writes to a file descriptor.
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).
StringRef - Represent a constant reference to a string, i.e.
void append(StringRef Path, StringRef Data)
std::string convert_to_slash(StringRef path)
Replaces backslashes with slashes if Windows.
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, OpenFlags Flags, unsigned Mode=0666)