Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
Fixed a bug, where long resources weren't fetch fully, enhanced parti…
Browse files Browse the repository at this point in the history
…tion_setup output and enabled mismatch between tarballs and partition_info -> Win10 installation working now
  • Loading branch information
steilerDev authored and steilerDev committed Apr 19, 2017
1 parent 41b5c15 commit 8b34f42
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 53 deletions.
48 changes: 32 additions & 16 deletions recovery/InstallManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,22 +386,26 @@ bool InstallManager::writeImage(OSInfo &image) {
}

if (!curPartition->emptyFS()) {
LDEBUG << os_name.toUtf8().constData() << ": Mounting file system";

if(!curPartition->mountPartition("/mnt2")) {
LFATAL << os_name.toUtf8().constData() << ": Error mounting file system";
return false;
}

LINFO << os_name.toUtf8().constData() << ": Downloading and extracting filesystem";

if (!untar(curPartition->tarball())) {
LFATAL << "Download and extracting file system failed!";
curPartition->unmountPartition();
return false;
if(curPartition->tarball().isEmpty()) {
LWARNING << "No tarball available, this might be intentional!";
} else {
LINFO << "Download and extracting file system successfull!";
curPartition->unmountPartition();
LDEBUG << os_name.toUtf8().constData() << ": Mounting file system";

if(!curPartition->mountPartition("/mnt2")) {
LFATAL << os_name.toUtf8().constData() << ": Error mounting file system";
return false;
}

LINFO << os_name.toUtf8().constData() << ": Downloading and extracting filesystem";

if (!untar(curPartition->tarball())) {
LFATAL << "Download and extracting file system failed!";
curPartition->unmountPartition();
return false;
} else {
LINFO << "Download and extracting file system successfull!";
curPartition->unmountPartition();
}
}
}
}
Expand Down Expand Up @@ -483,12 +487,24 @@ bool InstallManager::writeImage(OSInfo &image) {
pnr++;
}

LDEBUG << "Executing: sh " << args.join(" ").toUtf8().constData();
LDEBUG << "Executing: /bin/sh " << args.join(" ").toUtf8().constData();
LDEBUG << "Env: " << env.toStringList().join(" ").toUtf8().constData();
proc.setProcessChannelMode(proc.MergedChannels);
proc.setProcessEnvironment(env);
proc.setWorkingDirectory("/mnt2");
proc.setProcessChannelMode(QProcess::MergedChannels);
proc.start("/bin/sh", args);

LDEBUG << "Waiting to start the script";
proc.waitForStarted();
LDEBUG << "Script started";
proc.waitForReadyRead(10000);
while(proc.state() != QProcess::NotRunning) {
if(!proc.waitForReadyRead(10000)) {
LDEBUG << proc.readAll().constData();
}
}
LDEBUG << "Waiting for finished";
proc.waitForFinished(-1);

if (proc.exitCode() != 0) {
Expand Down
36 changes: 20 additions & 16 deletions recovery/OSInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bool OSInfo::parseOS(const QMap<QString, QVariant> &os) {
} else if (url.isEmpty()) {
LWARNING << "Unable to find OS partition setup URL";
} else {
LDEBUG << "Found OS partition setup URL" << url.toUtf8().constData();
LDEBUG << "Found OS partition setup URL " << url.toUtf8().constData();
_partitionSetupScript = downloadRessource(url);
if(_partitionSetupScript.isEmpty()) {
LFATAL << "Unable to download OS partition setup script";
Expand Down Expand Up @@ -194,25 +194,29 @@ bool OSInfo::parsePartitionInfo(QString &url) {
if(!Utility::Json::parseEntry<QVariantList>(partitionInfo, OS_PARTITIONS, &partitionInfoList, false, "OS partitions")) {
return false;
} else {
if(partitionInfoList.size() != _tarballs.size()) {
LFATAL << "Mismatch between number of available tarballs and OS partitions!";
if(partitionInfoList.size() < _tarballs.size()) {
LFATAL << "More tarballs specified than partitions available";
return false;
} else {
PartitionInfo *partInfo;
int i = 0;
foreach(QVariant partition, partitionInfoList) {
if(partition.canConvert<QVariantMap>()) {
partInfo = new PartitionInfo(partition.toMap(), _tarballs[i++]);
if(partInfo->isValid()) {
_partitions.append(partInfo);
} else {
LFATAL << "Invalid partition info found";
return false;
}
} else if(partitionInfoList.size() > _tarballs.size()) {
LERROR << "More partitions specified than tarballs, this might be intentional, filling gap with empty partitions";
for (int i = partitionInfoList.size() - _tarballs.size(); i > 0; i--) {
_tarballs.append("");
}
}
PartitionInfo *partInfo;
int i = 0;
foreach(QVariant partition, partitionInfoList) {
if(partition.canConvert<QVariantMap>()) {
partInfo = new PartitionInfo(partition.toMap(), _tarballs[i++]);
if(partInfo->isValid()) {
_partitions.append(partInfo);
} else {
LFATAL << "Unable to parse partition due to type error";
LFATAL << "Invalid partition info found";
return false;
}
} else {
LFATAL << "Unable to parse partition due to type error";
return false;
}
}
}
Expand Down
63 changes: 42 additions & 21 deletions recovery/libs/Web/Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include "Web.h"
#include "../easylogging++.h"

#include <QtNetwork/QNetworkInterface>

using namespace std;

bool Web::Web::send() {
Expand Down Expand Up @@ -49,7 +47,8 @@ bool Web::Web::send() {
}

bool Web::Web::receive() {
LINFO << "Parsing received HTTP message";
_bytesRead = 0;
LINFO << "Receiving HTTP message";
string bufferString;
if(!readReceive(&bufferString)) {
LERROR << "Unable to read receive from socket";
Expand All @@ -61,32 +60,48 @@ bool Web::Web::send() {
return false;
}

bool continueRead = false;
int messageSize = -1;

if(header.find("Expect") != header.end() && header["Expect"].compare("100-continue\r") == 0) {
LDEBUG << "Found expect header, building continue response";
Web expectResponse(_socket);

expectResponse.headerLine = "HTTP/1.0 100 Continue";
LDEBUG << "Sending continue response";
expectResponse.send();
LDEBUG << "Continuing reading";
bufferString.clear();
if(!readReceive(&bufferString)) {
LERROR << "Unable to continue to read from socket";
return false;
}
if(!parseReceive(bufferString, true)) {
LERROR << "Unable to parse continue request";
return false;
}
continueRead = true;
}
if(header.find("Content-Length") != header.end() && std::stoi(header["Content-Length"]) > _bytesRead) {
messageSize = std::stoi(header["Content-Length"]);
// Removing last \n
this->body.pop_back();
LDEBUG << "Complete message not yet read (" << _bytesRead << " vs. " << messageSize << "), continuing read";
continueRead = true;
}

if(continueRead) {
LDEBUG << "Continuing reading";
bufferString.clear();
do {
if (!readReceive(&bufferString)) {
LERROR << "Unable to continue to read from socket";
return false;
}
} while(messageSize != -1 && _bytesRead < messageSize);

if(!parseReceive(bufferString, true)) {
LERROR << "Unable to parse continue request";
return false;
}
}

return true;
}

bool Web::Web::readReceive(string *bufferString) {
LDEBUG << "Reading HTTP message from socket";
static char buffer[BUFFER_SIZE];
ssize_t readCount;

fd_set set;
int rv;
Expand All @@ -109,19 +124,19 @@ bool Web::Web::readReceive(string *bufferString) {
rv = select(_socket + 1, &set, NULL, NULL, &timeout);
if(rv == -1) {
LERROR << "An error occurred within select";
readCount = -1;
_bytesRead = -1;
} else if (rv == 0) {
LWARNING << "Read timeout occurred, this should be okay and due to the fact, that the buffer size == request size";
readCount = 0;
_bytesRead = 0;
} else {
readCount = read(_socket, buffer, BUFFER_SIZE);
LDEBUG << "Read " << readCount << " bytes";
_bytesRead += read(_socket, buffer, BUFFER_SIZE);
LDEBUG << "Read " << _bytesRead << " bytes so far in total";
bufferString->append(buffer);
}
} while (readCount == BUFFER_SIZE);
} while (_bytesRead == BUFFER_SIZE);

LDEBUG << "Finished read";
if(readCount < 0) {
if(_bytesRead < 0) {
LERROR << "Error during read!";
return false;
}
Expand Down Expand Up @@ -160,6 +175,10 @@ bool Web::Web::parseReceive(const string &bufferString, const bool skipHeader) {
}
}
}
if(header) {
LERROR << "Didn't finish read of header, this will be a problem!";
return false;
}
LDEBUG << "Finished parsing request";
return true;
}
Expand Down Expand Up @@ -189,7 +208,7 @@ bool Web::Web::parseHeaderLine(const string &headerLineString) {
}

bool Web::Web::parseBodyLine(const string &bodyLineString) {
LDEBUG << "Found body line: " << bodyLineString;
//LDEBUG << "Found body line: " << bodyLineString;
this->body.append(bodyLineString);
this->body.append("\n");
return true;
Expand All @@ -206,6 +225,7 @@ vector<string> Web::split(const string &text, const char sep) {
return tokens;
}

#ifdef QT_CORE_LIB
QString Web::getIP() {
QString ip;
QList<QHostAddress> ipAddresses = QNetworkInterface::allAddresses();
Expand All @@ -225,4 +245,5 @@ QString Web::getIP() {
}
return ip;
}
#endif

9 changes: 9 additions & 0 deletions recovery/libs/Web/Web.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
#include <vector>
#include <fstream>
#include <sstream>

#ifdef QT_CORE_LIB
#include <QString>
#include <QtNetwork/QNetworkInterface>
#endif

#define BUFFER_SIZE 4096
#define HEADER_BUFFER 4096
Expand Down Expand Up @@ -68,12 +72,17 @@ namespace Web {
bool parseBodyLine(const string &bodyLineString);

int _socket;
ssize_t _bytesRead;
};

// This helper function splits the given string by the sep char
vector<string> split(const string &text, const char sep);

#ifdef QT_CORE_LIB
// This helper returns the IP address of all available interfaces using the QtNetworking API
QString getIP();
#endif

}

#endif //WEB_WEB_H

0 comments on commit 8b34f42

Please sign in to comment.