Skip to content

Commit

Permalink
Fix compatibility with Tar specification
Browse files Browse the repository at this point in the history
IB-7877

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Nov 8, 2023
1 parent d5bbd75 commit 7e67739
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions client/CDoc2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace cdoc20 {
return true;
return dispatchToMain([] {
auto *notification = new FadeInNotification(Application::mainWindow(),
ria::qdigidoc4::colors::WHITE, ria::qdigidoc4::colors::MANTIS, 110);
ria::qdigidoc4::colors::WHITE, ria::qdigidoc4::colors::MANTIS, 110);
notification->start(QCoreApplication::translate("MainWindow", "Check internet connection"), 750, 3000, 1200);
return false;
});
Expand Down Expand Up @@ -206,7 +206,7 @@ namespace cdoc20 {
return io->write(pad) == pad.size();
};
auto toPaxRecord = [](const QByteArray &keyword, const QByteArray &value) {
QByteArray record = " " + keyword + "=" + value + "\n";
QByteArray record = ' ' + keyword + '=' + value + '\n';
QByteArray result;
for(auto len = record.size(); result.size() != len; ++len)
result = QByteArray::number(len + 1) + record;
Expand Down Expand Up @@ -241,20 +241,23 @@ namespace cdoc20 {
if(auto size = copyIODevice(file.data.get(), io.get()); size < 0 || !writePadding(size))
return false;
}
Header eof{};
return io->write((const char*)&eof, Header::Size) == Header::Size;
return io->write((const char*)&Header::Empty, Header::Size) == Header::Size &&
io->write((const char*)&Header::Empty, Header::Size) == Header::Size;
}

std::vector<CDoc::File> files(bool &warning) const
{
std::vector<CDoc::File> result;
Header h {};
auto readHeader = [&h, this] { return io->read((char*)&h, Header::Size) == Header::Size; };
while(io->bytesAvailable() > 0)
{
if(io->read((char*)&h, Header::Size) != Header::Size)
if(!readHeader())
return {};
if(h.isNull())
{
if(!readHeader() && !h.isNull())
return {};
warning = io->bytesAvailable() > 0;
return result;
}
Expand All @@ -270,7 +273,7 @@ namespace cdoc20 {
if(paxData.size() != f.size)
return {};
io->skip(padding(f.size));
if(io->read((char*)&h, Header::Size) != Header::Size || h.isNull() || !h.verify())
if(!readHeader() || h.isNull() || !h.verify())
return {};
f.size = fromOctal(h.size);
for(const QByteArray &data: paxData.split('\n'))
Expand Down Expand Up @@ -338,8 +341,7 @@ namespace cdoc20 {
}

bool isNull() {
static const Header zeroBlock {};
return memcmp(this, &zeroBlock, sizeof(Header)) == 0;
return memcmp(this, &Empty, sizeof(Header)) == 0;
}

bool verify() {
Expand All @@ -352,6 +354,7 @@ namespace cdoc20 {
referenceChecksum == checkSum.second;
}

static const Header Empty;
static const int Size;
};

Expand Down Expand Up @@ -386,6 +389,7 @@ namespace cdoc20 {
}
};

const TAR::Header TAR::Header::Empty {};
const int TAR::Header::Size = int(sizeof(TAR::Header));
}

Expand Down

0 comments on commit 7e67739

Please sign in to comment.