GH-1697 always stale files tolerate errors if a local copy is present
This fixes the situation when liteloader snapshot site is broken and there's an older local snapshot already present.
This commit is contained in:
parent
3d94fb8d24
commit
dd0e996081
@ -131,6 +131,11 @@ QList< std::shared_ptr< NetAction > > Library::getDownloads(OpSys system, class
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Net::Download::Options options;
|
||||||
|
if(isAlwaysStale)
|
||||||
|
{
|
||||||
|
options |= Net::Download::Option::AcceptLocalFiles;
|
||||||
|
}
|
||||||
if (isForge)
|
if (isForge)
|
||||||
{
|
{
|
||||||
out.append(ForgeXzDownload::make(storage, entry));
|
out.append(ForgeXzDownload::make(storage, entry));
|
||||||
@ -140,13 +145,13 @@ QList< std::shared_ptr< NetAction > > Library::getDownloads(OpSys system, class
|
|||||||
if(sha1.size())
|
if(sha1.size())
|
||||||
{
|
{
|
||||||
auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
|
auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
|
||||||
auto dl = Net::Download::makeCached(url, entry);
|
auto dl = Net::Download::makeCached(url, entry, options);
|
||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
|
||||||
out.append(dl);
|
out.append(dl);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
out.append(Net::Download::makeCached(url, entry));
|
out.append(Net::Download::makeCached(url, entry, options));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@ -51,6 +51,11 @@ public:
|
|||||||
return Job_Failed;
|
return Job_Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasLocalData() override
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QByteArray * m_output;
|
QByteArray * m_output;
|
||||||
};
|
};
|
||||||
|
@ -31,10 +31,11 @@ Download::Download():NetAction()
|
|||||||
m_status = Job_NotStarted;
|
m_status = Job_NotStarted;
|
||||||
}
|
}
|
||||||
|
|
||||||
Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry)
|
Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry, Options options)
|
||||||
{
|
{
|
||||||
Download * dl = new Download();
|
Download * dl = new Download();
|
||||||
dl->m_url = url;
|
dl->m_url = url;
|
||||||
|
dl->m_options = options;
|
||||||
auto md5Node = new ChecksumValidator(QCryptographicHash::Md5);
|
auto md5Node = new ChecksumValidator(QCryptographicHash::Md5);
|
||||||
auto cachedNode = new MetaCacheSink(entry, md5Node);
|
auto cachedNode = new MetaCacheSink(entry, md5Node);
|
||||||
dl->m_sink.reset(cachedNode);
|
dl->m_sink.reset(cachedNode);
|
||||||
@ -42,18 +43,20 @@ Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry)
|
|||||||
return std::shared_ptr<Download>(dl);
|
return std::shared_ptr<Download>(dl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output)
|
Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output, Options options)
|
||||||
{
|
{
|
||||||
Download * dl = new Download();
|
Download * dl = new Download();
|
||||||
dl->m_url = url;
|
dl->m_url = url;
|
||||||
|
dl->m_options = options;
|
||||||
dl->m_sink.reset(new ByteArraySink(output));
|
dl->m_sink.reset(new ByteArraySink(output));
|
||||||
return std::shared_ptr<Download>(dl);
|
return std::shared_ptr<Download>(dl);
|
||||||
}
|
}
|
||||||
|
|
||||||
Download::Ptr Download::makeFile(QUrl url, QString path)
|
Download::Ptr Download::makeFile(QUrl url, QString path, Options options)
|
||||||
{
|
{
|
||||||
Download * dl = new Download();
|
Download * dl = new Download();
|
||||||
dl->m_url = url;
|
dl->m_url = url;
|
||||||
|
dl->m_options = options;
|
||||||
dl->m_sink.reset(new FileSink(path));
|
dl->m_sink.reset(new FileSink(path));
|
||||||
return std::shared_ptr<Download>(dl);
|
return std::shared_ptr<Download>(dl);
|
||||||
}
|
}
|
||||||
@ -118,6 +121,14 @@ void Download::downloadError(QNetworkReply::NetworkError error)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if(m_options & Option::AcceptLocalFiles)
|
||||||
|
{
|
||||||
|
if(m_sink->hasLocalData())
|
||||||
|
{
|
||||||
|
m_status = Job_Failed_Proceed;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
// error happened during download.
|
// error happened during download.
|
||||||
qCritical() << "Failed " << m_url.toString() << " with reason " << error;
|
qCritical() << "Failed " << m_url.toString() << " with reason " << error;
|
||||||
m_status = Job_Failed;
|
m_status = Job_Failed;
|
||||||
@ -162,7 +173,15 @@ void Download::downloadFinished()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the download failed before this point ...
|
// if the download failed before this point ...
|
||||||
if (m_status == Job_Failed)
|
if (m_status == Job_Failed_Proceed)
|
||||||
|
{
|
||||||
|
qDebug() << "Download failed but we are allowed to proceed:" << m_url.toString();
|
||||||
|
m_sink->abort();
|
||||||
|
m_reply.reset();
|
||||||
|
emit succeeded(m_index_within_job);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (m_status == Job_Failed)
|
||||||
{
|
{
|
||||||
qDebug() << "Download failed in previous step:" << m_url.toString();
|
qDebug() << "Download failed in previous step:" << m_url.toString();
|
||||||
m_sink->abort();
|
m_sink->abort();
|
||||||
|
@ -28,14 +28,20 @@ class MULTIMC_LOGIC_EXPORT Download : public NetAction
|
|||||||
|
|
||||||
public: /* types */
|
public: /* types */
|
||||||
typedef std::shared_ptr<class Download> Ptr;
|
typedef std::shared_ptr<class Download> Ptr;
|
||||||
|
enum class Option
|
||||||
|
{
|
||||||
|
NoOptions = 0,
|
||||||
|
AcceptLocalFiles = 1
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(Options, Option)
|
||||||
|
|
||||||
protected: /* con/des */
|
protected: /* con/des */
|
||||||
explicit Download();
|
explicit Download();
|
||||||
public:
|
public:
|
||||||
virtual ~Download(){};
|
virtual ~Download(){};
|
||||||
static Download::Ptr makeCached(QUrl url, MetaEntryPtr entry);
|
static Download::Ptr makeCached(QUrl url, MetaEntryPtr entry, Options options = Option::NoOptions);
|
||||||
static Download::Ptr makeByteArray(QUrl url, QByteArray *output);
|
static Download::Ptr makeByteArray(QUrl url, QByteArray *output, Options options = Option::NoOptions);
|
||||||
static Download::Ptr makeFile(QUrl url, QString path);
|
static Download::Ptr makeFile(QUrl url, QString path, Options options = Option::NoOptions);
|
||||||
|
|
||||||
public: /* methods */
|
public: /* methods */
|
||||||
QString getTargetFilepath()
|
QString getTargetFilepath()
|
||||||
@ -62,5 +68,8 @@ private: /* data */
|
|||||||
// FIXME: remove this, it has no business being here.
|
// FIXME: remove this, it has no business being here.
|
||||||
QString m_target_path;
|
QString m_target_path;
|
||||||
std::unique_ptr<Sink> m_sink;
|
std::unique_ptr<Sink> m_sink;
|
||||||
|
Options m_options;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Net::Download::Options)
|
||||||
|
@ -97,4 +97,9 @@ JobStatus FileSink::finalizeCache(QNetworkReply &)
|
|||||||
return Job_Finished;
|
return Job_Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileSink::hasLocalData()
|
||||||
|
{
|
||||||
|
QFileInfo info(m_filename);
|
||||||
|
return info.exists() && info.size() != 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ public: /* methods */
|
|||||||
JobStatus write(QByteArray & data) override;
|
JobStatus write(QByteArray & data) override;
|
||||||
JobStatus abort() override;
|
JobStatus abort() override;
|
||||||
JobStatus finalize(QNetworkReply & reply) override;
|
JobStatus finalize(QNetworkReply & reply) override;
|
||||||
|
bool hasLocalData() override;
|
||||||
|
|
||||||
protected: /* methods */
|
protected: /* methods */
|
||||||
virtual JobStatus initCache(QNetworkRequest &);
|
virtual JobStatus initCache(QNetworkRequest &);
|
||||||
|
@ -56,4 +56,10 @@ JobStatus MetaCacheSink::finalizeCache(QNetworkReply & reply)
|
|||||||
ENV.metacache()->updateEntry(m_entry);
|
ENV.metacache()->updateEntry(m_entry);
|
||||||
return Job_Finished;
|
return Job_Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MetaCacheSink::hasLocalData()
|
||||||
|
{
|
||||||
|
QFileInfo info(m_filename);
|
||||||
|
return info.exists() && info.size() != 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ class MetaCacheSink : public FileSink
|
|||||||
public: /* con/des */
|
public: /* con/des */
|
||||||
MetaCacheSink(MetaEntryPtr entry, ChecksumValidator * md5sum);
|
MetaCacheSink(MetaEntryPtr entry, ChecksumValidator * md5sum);
|
||||||
virtual ~MetaCacheSink();
|
virtual ~MetaCacheSink();
|
||||||
|
bool hasLocalData() override;
|
||||||
|
|
||||||
protected: /* methods */
|
protected: /* methods */
|
||||||
JobStatus initCache(QNetworkRequest & request) override;
|
JobStatus initCache(QNetworkRequest & request) override;
|
||||||
|
@ -29,7 +29,8 @@ enum JobStatus
|
|||||||
Job_InProgress,
|
Job_InProgress,
|
||||||
Job_Finished,
|
Job_Finished,
|
||||||
Job_Failed,
|
Job_Failed,
|
||||||
Job_Aborted
|
Job_Aborted,
|
||||||
|
Job_Failed_Proceed
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<class NetAction> NetActionPtr;
|
typedef std::shared_ptr<class NetAction> NetActionPtr;
|
||||||
|
@ -17,6 +17,7 @@ public: /* methods */
|
|||||||
virtual JobStatus write(QByteArray & data) = 0;
|
virtual JobStatus write(QByteArray & data) = 0;
|
||||||
virtual JobStatus abort() = 0;
|
virtual JobStatus abort() = 0;
|
||||||
virtual JobStatus finalize(QNetworkReply & reply) = 0;
|
virtual JobStatus finalize(QNetworkReply & reply) = 0;
|
||||||
|
virtual bool hasLocalData() = 0;
|
||||||
|
|
||||||
void addValidator(Validator * validator)
|
void addValidator(Validator * validator)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user