Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[auth][bugfix] Auth DB migrate #5546

Merged
merged 5 commits into from
Nov 7, 2017
Merged

[auth][bugfix] Auth DB migrate #5546

merged 5 commits into from
Nov 7, 2017

Conversation

elpaso
Copy link
Contributor

@elpaso elpaso commented Nov 6, 2017

Description

Add a migration step that copies the qgis authentication DB to the new profile folder.

Fixes https://issues.qgis.org/issues/17403 (Authentication DB is not migrated from 2 to 3)

@elpaso elpaso requested a review from NathanW2 November 6, 2017 12:43
QgsError authDbErrors = migrateAuthDb();
if ( !authDbErrors.isEmpty() )
{
for ( const auto &err : authDbErrors.messageList( ) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll need to make a const temporary copy of the list or stick to Q_FOREACH. Same above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn even if messageList is const (or at least that was it was mean to be) ?

Copy link
Member

@m-kuhn m-kuhn Nov 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so, but might really be that the const works here based on some research I did right now.

Even if this works, I would prefer to have this copy in place. The reason is, that if this is done wrong we have an expensive detach and detecting this in code reviews is impossible if at the place where it's used no copy is taken.

The alternative would be that someone gets ground truth for the iterate-on-const-return first and then modifies the whole code-source accordingly so we can assume this while reviewing.

else
{
QgsDebugMsg( QStringLiteral( "OLD AUTH DB FILE %1" ).arg( oldAuthDbFilePath ) );
QgsDebugMsg( QStringLiteral( "NEW AUTH DB FILE %1" ).arg( newAuthDbFilePath ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should probably stay quiet, there's enough info below I guess

* \brief messageList return the list of current error messages
* \return current list of error messages
*/
const QList<QgsErrorMessage> messageList() { return mMessageList; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That const here should be moved to the end of the signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that we don't want to "add" a const after the signature?
I wanted the getter to return a const list too, to feed the range loops.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the idea was to add one after the signature. And to remove the one before, but that's already discussed above.

@@ -132,7 +132,7 @@ class CORE_EXPORT QgsError
* \brief messageList return the list of current error messages
* \return current list of error messages
*/
const QList<QgsErrorMessage> messageList() { return mMessageList; }
const QList<QgsErrorMessage> messageList() const { return mMessageList; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @elpaso
Did you review if the const for the return type serves a purpose? I am asking because so far we always asked devs to drop it and it would be nice to have this done consistently throughout the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was convinced that returning a const here allowed you to range loop iterate on the list without the need to make a const copy of it. But I might be wrong. Let me check if I can get an answer from a debugger.
Btw, I'm now making a const copy as you requested so this const is now unnecessary, but I'm still convinced that if the const copy is not needed we should not make it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume even if we don't explicitly make a copy, a temporary for return will be created implicitly anyway, but looking forward to your findings 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    const QList<QgsErrorMessage> errorList( stylesErrors.messageList( ) );
    for ( const auto &err : errorList )
    {
      errors.append( err );
    }

    for ( const auto &err : stylesErrors.messageList( ) )
    {
      errors.append( err );
    }

@m-kuhn what I've found is that the instance address or err in the two loops is exactly the same when the messageList returns a const, but it is different if I remove the const from the signature (the one in front of it).

I think we can conclude that returning a const list allows to range loop iterate without the need to make a const copy of the list.

Btw, I guess you are right about the temporary (should we return a reference?) but to my limited understanding what matters here are the instances in the list, that are not copied, not the container itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be just my understanding:

What that means is, that if you compile with your compiler it actually does make a difference. And this might indeed be backed up by the C++ standard (from C++0x on).

What this also means is, that with the const copy of the list we are always on the safe side, since

... what matters here are the instances in the list, that are not copied, not the container itself.

Unless of course we modify all our return values from QList<X> to const QList<X>, then we will also be on the safe side with the other approach. But only for QGIS internal functions, I think the whole Qt codebase returns non-const lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problems to remove the first const if that's the "standard" way for Qt to return lists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked with Qt upstream, that's the response:

Making returned containers const inhibits move semantics, because const rvalues do not bind to the mutable rvalue references that move constructors and move assignment operators use.

Copy link
Member

@NathanW2 NathanW2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This looks fine to me logic wise. Thanks for adding the merge error message logic for me as well.

@elpaso elpaso merged commit 7c9cd49 into qgis:master Nov 7, 2017
@elpaso elpaso deleted the auth_migrate branch November 7, 2017 07:26
@NathanW2
Copy link
Member

NathanW2 commented Nov 7, 2017 via email

@elpaso
Copy link
Contributor Author

elpaso commented Nov 8, 2017

Thank you for taking care of our beloved users :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants