MUTILS_API quint32 next_rand32(void);
MUTILS_API quint64 next_rand64(void);
+ //Temp File Name
+ MUTILS_API QString make_temp_file(const QString &basePath, const QString &extension, const bool placeholder = false);
+
//Parity
MUTILS_API bool parity(quint32 value);
}
///////////////////////////////////////////////////////////////////////////////
+// GET TEMP FILE NAME
+///////////////////////////////////////////////////////////////////////////////
+
+QString MUtils::make_temp_file(const QString &basePath, const QString &extension, const bool placeholder)
+{
+ for(int i = 0; i < 4096; i++)
+ {
+ const QString tempFileName = QString("%1/%2.%3").arg(basePath, rand_str(), extension);
+ if(!QFileInfo(tempFileName).exists())
+ {
+ if(placeholder)
+ {
+ QFile file(tempFileName);
+ if(file.open(QFile::ReadWrite))
+ {
+ file.close();
+ return tempFileName;
+ }
+ }
+ else
+ {
+ return tempFileName;
+ }
+ }
+ }
+
+ qWarning("Failed to generate unique temp file name!");
+ return QString();
+}
+
+///////////////////////////////////////////////////////////////////////////////
// COMPUTE PARITY
///////////////////////////////////////////////////////////////////////////////
static void temp_folder_cleaup(void)
{
QWriteLocker writeLock(&g_temp_folder_lock);
-
+ qWarning("------------ temp_folder_cleaup ------------");
+
//Clean the directory
while(!g_temp_folder_file.isNull())
{
return false;
}
+ QString keyRingPath(m_binaryKeys);
+ bool removeKeyring = false;
if(QFileInfo(file).absolutePath().compare(QFileInfo(m_binaryKeys).absolutePath(), Qt::CaseInsensitive) != 0)
{
- qWarning("CheckSignature: File and keyring should be in same folder!");
- return false;
+ keyRingPath = make_temp_file(QFileInfo(file).absolutePath(), "gpg");
+ removeKeyring = true;
+ if(!QFile::copy(m_binaryKeys, keyRingPath))
+ {
+ qWarning("CheckSignature: Failed to copy the key-ring file!");
+ return false;
+ }
}
QProcess process;
connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
connect(&process, SIGNAL(readyRead()), &loop, SLOT(quit()));
- process.start(m_binaryGnuPG, QStringList() << "--homedir" << "." << "--keyring" << QFileInfo(m_binaryKeys).fileName() << QFileInfo(signature).fileName() << QFileInfo(file).fileName());
+ process.start(m_binaryGnuPG, QStringList() << "--homedir" << "." << "--keyring" << QFileInfo(keyRingPath).fileName() << QFileInfo(signature).fileName() << QFileInfo(file).fileName());
if(!process.waitForStarted())
{
+ if(removeKeyring)
+ {
+ remove_file(keyRingPath);
+ }
return false;
}
}
}
+ if(removeKeyring)
+ {
+ remove_file(keyRingPath);
+ }
+
log(QString().sprintf("Exited with code %d", process.exitCode()));
return (process.exitCode() == 0);
}