Skip to content

Commit 7d533a0

Browse files
author
Lauris Kaplinski
committed
Fix tar filenames if only PAX size is used
1 parent 4dfb83d commit 7d533a0

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

cdoc/Tar.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ libcdoc::TarConsumer::writeHeader(const Header &h) noexcept {
153153
}
154154

155155
libcdoc::result_t
156-
libcdoc::TarConsumer::writeHeader(Header &h, const std::string& name, int64_t size) noexcept {
156+
libcdoc::TarConsumer::writeHeader(const std::string& name, int64_t size, char typeflag) noexcept {
157+
Header h {};
158+
h.typeflag = typeflag;
157159
h.chksum.fill(' ');
158160
size_t len = std::min(name.size(), h.name.size());
159161
std::copy_n(name.cbegin(), len, h.name.begin());
@@ -214,7 +216,6 @@ libcdoc::TarConsumer::open(const std::string& name, int64_t size)
214216

215217
_current_size = size;
216218
_current_written = 0;
217-
Header h {};
218219

219220
bool need_pax_name = (name.size() >= 100);
220221
for (auto c : name) {
@@ -225,7 +226,6 @@ libcdoc::TarConsumer::open(const std::string& name, int64_t size)
225226
}
226227
if(need_pax_name || size > 07777777) {
227228
LOG_DBG("Writing Pax header: name {} size {}", name, size);
228-
h.typeflag = 'x';
229229
std::string paxData;
230230
if(need_pax_name)
231231
paxData += toPaxRecord("path", name);
@@ -238,15 +238,14 @@ libcdoc::TarConsumer::open(const std::string& name, int64_t size)
238238
path = std::filesystem::path("./PaxHeaders.X") / path.filename();
239239
}
240240
LOG_DBG("Pax path: {}", path.string());
241-
if (auto rv = writeHeader(h, path.string(), paxData.size()); rv != OK)
241+
if (auto rv = writeHeader(path.string(), paxData.size(), 'x'); rv != OK)
242242
return rv;
243243
if (auto rv = _dst->write((const uint8_t *) paxData.data(), paxData.size()); rv != paxData.size())
244244
return rv < OK ? rv : OUTPUT_ERROR;
245245
if (auto rv = writePadding(paxData.size()); rv != OK)
246246
return rv;
247247
}
248-
h.typeflag = '0';
249-
return writeHeader(h, name, size);
248+
return writeHeader(name, size, '0');
250249
}
251250

252251
libcdoc::TarSource::TarSource(DataSource *src, bool take_ownership)
@@ -297,8 +296,8 @@ libcdoc::result_t
297296
libcdoc::TarSource::readPaxHeader(const Header& hdr, std::string& name, int64_t& size)
298297
{
299298
int64_t h_size = hdr.getSize();
300-
std::string paxData(h_size, 0);
301-
result_t result = _src->read((uint8_t *) paxData.data(), paxData.size());
299+
std::string paxData(h_size, 0);
300+
result_t result = _src->read((uint8_t *) paxData.data(), paxData.size());
302301
if (result != h_size) {
303302
_error = INPUT_STREAM_ERROR;
304303
return _error;

cdoc/Tar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct TarConsumer final : public MultiDataConsumer
3737
libcdoc::result_t open(const std::string& name, int64_t size) final;
3838
private:
3939
result_t writeHeader(const Header &h) noexcept;
40-
result_t writeHeader(Header &h, const std::string& name, int64_t size) noexcept;
40+
result_t writeHeader(const std::string& name, int64_t size, char typeflag = '0') noexcept;
4141
result_t writePadding(int64_t size) noexcept;
4242

4343
DataConsumer *_dst;

0 commit comments

Comments
 (0)