Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/xml/xmlstorage.cpp
Show First 20 Lines • Show All 446 Lines • ▼ Show 20 Line(s) | 446 | if (encryptFile == true) { | |||
---|---|---|---|---|---|
447 | QString msg = i18n("<p>You have configured to save your data in encrypted form using GPG. Make sure you understand that you might lose all your data if you encrypt it, but cannot decrypt it later on. If unsure, answer <b>No</b>.</p>"); | 447 | QString msg = i18n("<p>You have configured to save your data in encrypted form using GPG. Make sure you understand that you might lose all your data if you encrypt it, but cannot decrypt it later on. If unsure, answer <b>No</b>.</p>"); | ||
448 | if (KMessageBox::questionYesNo(nullptr, msg, i18n("Store GPG encrypted"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "StoreEncrypted") == KMessageBox::No) { | 448 | if (KMessageBox::questionYesNo(nullptr, msg, i18n("Store GPG encrypted"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "StoreEncrypted") == KMessageBox::No) { | ||
449 | encryptFile = false; | 449 | encryptFile = false; | ||
450 | } | 450 | } | ||
451 | } | 451 | } | ||
452 | } | 452 | } | ||
453 | } | 453 | } | ||
454 | 454 | | |||
455 | // Permissions to apply to new file | ||||
456 | QFileDevice::Permissions fmode = QFileDevice::ReadUser | QFileDevice::WriteUser; | ||||
455 | 457 | | |||
456 | // Create a temporary file if needed | 458 | // Create a temporary file if needed | ||
457 | QString writeFile = localFile; | 459 | QString writeFile = localFile; | ||
458 | QTemporaryFile tmpFile(writeFile); | 460 | QTemporaryFile tmpFile(writeFile); | ||
459 | if (QFile::exists(localFile)) { | 461 | if (QFile::exists(localFile)) { | ||
460 | tmpFile.open(); | 462 | tmpFile.open(); | ||
461 | writeFile = tmpFile.fileName(); | 463 | writeFile = tmpFile.fileName(); | ||
462 | tmpFile.close(); | 464 | tmpFile.close(); | ||
465 | // Since file is going to be replaced, stash the original permissions so they can be restored | ||||
466 | fmode = QFile::permissions(localFile); | ||||
463 | } | 467 | } | ||
464 | 468 | | |||
465 | /** | 469 | /** | ||
466 | * @brief Automatically restore settings when scope is left | 470 | * @brief Automatically restore settings when scope is left | ||
467 | */ | 471 | */ | ||
468 | struct restorePreviousSettingsHelper { | 472 | struct restorePreviousSettingsHelper { | ||
469 | restorePreviousSettingsHelper() | 473 | restorePreviousSettingsHelper() | ||
470 | : m_signalsWereBlocked{MyMoneyFile::instance()->signalsBlocked()} | 474 | : m_signalsWereBlocked{MyMoneyFile::instance()->signalsBlocked()} | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 525 | if (writeFile != localFile) { | |||
525 | 529 | | |||
526 | // on Windows QTemporaryFile does not release file handle even after close() | 530 | // on Windows QTemporaryFile does not release file handle even after close() | ||
527 | // so QFile::rename(writeFile, localFile) will fail since Windows does not allow moving files in use | 531 | // so QFile::rename(writeFile, localFile) will fail since Windows does not allow moving files in use | ||
528 | // as a workaround QFile::copy is used instead of QFile::rename below | 532 | // as a workaround QFile::copy is used instead of QFile::rename below | ||
529 | // writeFile (i.e. tmpFile) will be deleted by QTemporaryFile dtor when it falls out of scope | 533 | // writeFile (i.e. tmpFile) will be deleted by QTemporaryFile dtor when it falls out of scope | ||
530 | if (!QFile::remove(localFile) || !QFile::copy(writeFile, localFile)) | 534 | if (!QFile::remove(localFile) || !QFile::copy(writeFile, localFile)) | ||
531 | throw MYMONEYEXCEPTION(QString::fromLatin1("Failure while writing to '%1'").arg(localFile)); | 535 | throw MYMONEYEXCEPTION(QString::fromLatin1("Failure while writing to '%1'").arg(localFile)); | ||
532 | } | 536 | } | ||
533 | QFile::setPermissions(localFile, QFileDevice::ReadUser | QFileDevice::WriteUser); | 537 | QFile::setPermissions(localFile, fmode); | ||
534 | pWriter->setProgressCallback(0); | 538 | pWriter->setProgressCallback(0); | ||
535 | } | 539 | } | ||
536 | 540 | | |||
537 | void XMLStorage::checkRecoveryKeyValidity() | 541 | void XMLStorage::checkRecoveryKeyValidity() | ||
538 | { | 542 | { | ||
539 | // check if the recovery key is still valid or expires soon | 543 | // check if the recovery key is still valid or expires soon | ||
540 | 544 | | |||
541 | if (KMyMoneySettings::writeDataEncrypted() && KMyMoneySettings::encryptRecover()) { | 545 | if (KMyMoneySettings::writeDataEncrypted() && KMyMoneySettings::encryptRecover()) { | ||
Show All 31 Lines |