Merge pull request #2666 from csoler/v0.6-BugFixing_20

Bug Fixing
This commit is contained in:
csoler 2023-01-19 09:49:43 +01:00 committed by GitHub
commit e2d9238ded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 97 additions and 40 deletions

View File

@ -122,9 +122,9 @@ RsRegularExpression::Expression* ExpressionWidget::getRsExpression()
highVal = exprParamElem->getIntHighValue();
if (lowVal >highVal)
{
lowVal = lowVal^highVal; // csoler: wow, that is some style!
highVal = lowVal^highVal;
lowVal = lowVal^highVal;
auto tmp=lowVal;
lowVal = highVal;
highVal = tmp;
}
}
@ -150,11 +150,33 @@ RsRegularExpression::Expression* ExpressionWidget::getRsExpression()
wordList);
break;
case DateSearch:
if (inRangedConfig) {
expr = new RsRegularExpression::DateExpression(exprCondElem->getRelOperator(), checkedConversion(lowVal), checkedConversion(highVal));
} else {
expr = new RsRegularExpression::DateExpression(exprCondElem->getRelOperator(), checkedConversion(exprParamElem->getIntValue()));
}
switch(exprCondElem->getRelOperator()) // we need to convert expressions so that the delta is 1 day (i.e. 86400 secs)
{
// The conditions below account for 3 things:
// - the swap between variables in rsexpr.h:214
// - the swap of variables when calling getRelOperator() (See guiexprelement.cpp:166)
// - the fact that some comparisions in the unit of days may add 86400 seconds.
default:
case RsRegularExpression::Equals:
expr = new RsRegularExpression::DateExpression(RsRegularExpression::InRange, checkedConversion(exprParamElem->getIntValue()), checkedConversion(86400+exprParamElem->getIntValue()));
break;
case RsRegularExpression::InRange:
expr = new RsRegularExpression::DateExpression(RsRegularExpression::InRange, checkedConversion(lowVal), 86400+checkedConversion(highVal));
break;
case RsRegularExpression::Greater: // means we expect file.date() < some day D. So file.date() < D, meaning Exp=Greater
expr = new RsRegularExpression::DateExpression(RsRegularExpression::Greater,checkedConversion(exprParamElem->getIntValue()));
break;
case RsRegularExpression::SmallerEquals: // means we expect file.date() >= some day D. So file.date() >= D, meaning Exp=SmallerEquals
expr = new RsRegularExpression::DateExpression(RsRegularExpression::SmallerEquals,checkedConversion(exprParamElem->getIntValue()));
break;
case RsRegularExpression::Smaller: // means we expect file.date() > some day D. So file.date() >= D+86400, meaning Exp=SmallerEquals
expr = new RsRegularExpression::DateExpression(RsRegularExpression::SmallerEquals, checkedConversion(86400+exprParamElem->getIntValue()-1));
break;
case RsRegularExpression::GreaterEquals: // means we expect file.date() <= some day D. So file.date() < D+86400, meaning Exp=Greater
expr = new RsRegularExpression::DateExpression(RsRegularExpression::Greater, checkedConversion(86400+exprParamElem->getIntValue()));
break;
}
break;
case PopSearch:
if (inRangedConfig) {
@ -174,11 +196,33 @@ RsRegularExpression::Expression* ExpressionWidget::getRsExpression()
else
{
uint64_t s = exprParamElem->getIntValue() ;
auto cond = exprCondElem->getRelOperator();
bool MB = false;
if(s >= (uint64_t)(1024*1024*1024))
expr = new RsRegularExpression::SizeExpressionMB(exprCondElem->getRelOperator(), (int)(s/(1024*1024))) ;
{
MB=true;
s >>= 20;
}
// Specific case for Equal operator, which we convert to a range, so as to avoid matching arbitrary digits
if(cond == RsRegularExpression::Equals)
{
// Now compute a proper interval. There is no optimal solution, so we aim for the simplest: add/remove 20% of the initial value.
if(MB)
expr = new RsRegularExpression::SizeExpressionMB(RsRegularExpression::InRange, (int)(s*0.8) , (int)(s*1.2));
else
expr = new RsRegularExpression::SizeExpression(RsRegularExpression::InRange, (int)(s*0.8) , (int)(s*1.2));
}
else
expr = new RsRegularExpression::SizeExpression(exprCondElem->getRelOperator(), (int)s) ;
{
if(MB)
expr = new RsRegularExpression::SizeExpressionMB(cond, (int)s);
else
expr = new RsRegularExpression::SizeExpression(cond, (int)s) ;
}
}
break;
};

View File

@ -155,18 +155,19 @@ void GuiExprElement::initialiseOptionsLists()
/* W A R N I N G !!!!
the cb elements correspond to their inverse rel op counterparts in rsexpr.h due to the nature of
the implementation.there
the implementation.
For example consider "size greater than 100kb" selected in the GUI.
The rsexpr.cc impl returns true if the CONDITION specified is greater than the file size passed as argument
as rsexpr iterates through the files. So, the user wants files that are greater than 100kb but the impl returns
files where the condition is greater than the file size i.e. files whose size is less than or equal to the condition
files where the condition is greater than the file size i.e. files whose size is less than to the condition
Therefore we invert the mapping of rel conditions here to match the behaviour of the impl.
Also the Equal nature of comparisons should be kept, since = is symmetric.
*/
GuiExprElement::relConditionIndexMap[GuiExprElement::LT_INDEX] = RsRegularExpression::GreaterEquals;
GuiExprElement::relConditionIndexMap[GuiExprElement::LTE_INDEX] = RsRegularExpression::Greater;
GuiExprElement::relConditionIndexMap[GuiExprElement::LT_INDEX] = RsRegularExpression::Greater;
GuiExprElement::relConditionIndexMap[GuiExprElement::LTE_INDEX] = RsRegularExpression::GreaterEquals;
GuiExprElement::relConditionIndexMap[GuiExprElement::EQUAL_INDEX] = RsRegularExpression::Equals;
GuiExprElement::relConditionIndexMap[GuiExprElement::GTE_INDEX] = RsRegularExpression::Smaller;
GuiExprElement::relConditionIndexMap[GuiExprElement::GT_INDEX] = RsRegularExpression::SmallerEquals;
GuiExprElement::relConditionIndexMap[GuiExprElement::GTE_INDEX] = RsRegularExpression::SmallerEquals;
GuiExprElement::relConditionIndexMap[GuiExprElement::GT_INDEX] = RsRegularExpression::Smaller;
GuiExprElement::relConditionIndexMap[GuiExprElement::RANGE_INDEX] = RsRegularExpression::InRange;
// the string to index map

View File

@ -947,30 +947,42 @@ bool Rshare::loadCertificate(const RsPeerId &accountId, bool autoLogin)
}
std::string lockFile;
int retVal = RsInit::LockAndLoadCertificates(autoLogin, lockFile);
switch (retVal) {
case 0: break;
case 1: QMessageBox::warning( 0,
QObject::tr("Multiple instances"),
QObject::tr("Another RetroShare using the same profile is "
"already running on your system. Please close "
"that instance first\n Lock file:\n") +
QString::fromUtf8(lockFile.c_str()));
return false;
case 2: QMessageBox::critical( 0,
QObject::tr("Multiple instances"),
QObject::tr("An unexpected error occurred when Retroshare "
"tried to acquire the single instance lock\n Lock file:\n") +
QString::fromUtf8(lockFile.c_str()));
return false;
case 3:
// case 3: QMessageBox::critical( 0,
// QObject::tr("Login Failure"),
// QObject::tr("Maybe password is wrong") );
return false;
default: std::cerr << "Rshare::loadCertificate() unexpected switch value " << retVal << std::endl;
return false;
}
RsInit::LoadCertificateStatus retVal = RsInit::LockAndLoadCertificates(autoLogin, lockFile);
switch (retVal)
{
case RsInit::OK:
break;
case RsInit::ERR_ALREADY_RUNNING: QMessageBox::warning( nullptr,
QObject::tr("Multiple instances"),
QObject::tr("Another RetroShare using the same profile is "
"already running on your system. Please close "
"that instance first\n Lock file:\n") +
QString::fromUtf8(lockFile.c_str()));
return false;
case RsInit::ERR_CANT_ACQUIRE_LOCK: QMessageBox::critical( nullptr,
QObject::tr("Multiple instances"),
QObject::tr("An unexpected error occurred when Retroshare "
"tried to acquire the single instance lock\n Lock file:\n") +
QString::fromUtf8(lockFile.c_str()));
return false;
case RsInit::ERR_CERT_CRYPTO_IS_TOO_WEAK: QMessageBox::critical( nullptr,
QObject::tr("Old certificate"),
QObject::tr("This node uses old certificate settings that are considered too "
"weak by your current OpenSSL library version. You need to create a new node "
"possibly using the same profile."));
return false;
case RsInit::ERR_CANNOT_CONFIGURE_TOR: QMessageBox::critical( nullptr,
QObject::tr("Tor error"),
QObject::tr("Cannot run/configure Tor. Make sure it is installed on your system."));
return false;
// case 3: QMessageBox::critical( 0,
// QObject::tr("Login Failure"),
// QObject::tr("Maybe password is wrong") );
return false;
default: std::cerr << "Rshare::loadCertificate() unexpected switch value " << retVal << std::endl;
return false;
}
return true;
}