<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>436647</bug_id>
          
          <creation_ts>2021-05-05 17:27:44 +0000</creation_ts>
          <short_desc>Overwriting a gpg-encrypted file results in a zero byte file</short_desc>
          <delta_ts>2021-05-12 06:54:29 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>2</classification_id>
          <classification>Applications</classification>
          <product>kmymoney</product>
          <component>file</component>
          <version>5.1.1</version>
          <rep_platform>Microsoft Windows</rep_platform>
          <op_sys>Microsoft Windows</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>426400</blocked>
          <everconfirmed>0</everconfirmed>
          <reporter name="Ralf Habacker">ralf.habacker</reporter>
          <assigned_to name="KMyMoney Devel Mailing List">kmymoney-devel</assigned_to>
          
          
          <cf_commitlink>https://invent.kde.org/office/kmymoney/commit/646c4cb810a960699b1b659d72bef248992f4e40</cf_commitlink>
          <cf_versionfixedin>5.1.2</cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2030264</commentid>
    <comment_count>0</comment_count>
    <who name="Ralf Habacker">ralf.habacker</who>
    <bug_when>2021-05-05 17:27:44 +0000</bug_when>
    <thetext>STEPS TO REPRODUCE
1. make sure that there is a matching gpg key for the KMyMoney file you are using
2. download portable kmymoney package from https://kmymoney.org/snapshots.php
3. unpack portable archive, start KMyMoney and load encrypted KMyMoney file
4. overwrite the used file with File-&gt;&quot;save as&quot; (make a backup copy before)

OBSERVED RESULT
The created file has a length of 0 bytes and is not loadable anymore.

EXPECTED RESULT
The created file should be created completely

SOFTWARE/OS VERSIONS
Windows: 10
KDE Frameworks Version: 5.65.0
Qt Version: 5.11

ADDITIONAL INFORMATION
In explorer a file with a corresponding file name and an additional extension .1~ is displayed, which corresponds to the saved state. This suggests that the final renaming/copying failed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2031265</commentid>
    <comment_count>1</comment_count>
    <who name="Ralf Habacker">ralf.habacker</who>
    <bug_when>2021-05-09 14:41:25 +0000</bug_when>
    <thetext>An investigation shows that there is a problem when QTemporaryFile and QSaveFile are used together on Windows.

For the case of creating a local gpg-encrypted file, only one KSaveFile instance inside KMyMoneyView::saveToLocalFile() https://github.com/KDE/kmymoney/blob/07d368edf5098cb06774a1cecc41551ce3ad43c5/kmymoney/views/kmymoneyview.cpp#L1151 was used in the 4.8 branch, which also works as expected for the case that the file to be created already existed before.

In the 5.1 branch the procedure was changed so that in the mentioned function first a QTemporaryFile instance is created and if the resulting file already exists, the file name created in this way is passed to the KGPGFile instance, which internally uses a QSaveFile instance, which in turn creates a temporary file.

Something goes wrong with this multiple renaming or copying. If you omit the superfluous use of the QTemporaryFile instance in the case mentioned, it works as expected.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2032002</commentid>
    <comment_count>2</comment_count>
    <who name="Thomas Baumgart">thb</who>
    <bug_when>2021-05-12 06:33:45 +0000</bug_when>
    <thetext>Git commit 39785a3d80c56dc6e53f301d76c41bcc8ca048c6 by Thomas Baumgart.
Committed on 12/05/2021 at 06:33.
Pushed by tbaumgart into branch &apos;5.1&apos;.

Solve problems with usage of QTemporaryFile on MS-Windows

A call to QTemporaryFile::close() may not close the file but only rewind
the file pointer to the beginning allwing faster re-open. This causes
problems on MS-Windows filesystems, as one cannot e.g. rename the
temporary file in this case because it is still kept open from the
perspective of the filesystem. Only destroying the object really closes
the file on the filesystem.

This change makes sure, that the QTemporaryFile object only lives as
long as it is needed and closed immediately after by destroying the
object.
FIXED-IN: 5.1.2

M  +18   -10   kmymoney/plugins/xml/xmlstorage.cpp

https://invent.kde.org/office/kmymoney/commit/39785a3d80c56dc6e53f301d76c41bcc8ca048c6</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2032007</commentid>
    <comment_count>3</comment_count>
    <who name="Thomas Baumgart">thb</who>
    <bug_when>2021-05-12 06:54:29 +0000</bug_when>
    <thetext>Git commit 646c4cb810a960699b1b659d72bef248992f4e40 by Thomas Baumgart.
Committed on 12/05/2021 at 06:54.
Pushed by tbaumgart into branch &apos;master&apos;.

Solve problems with usage of QTemporaryFile on MS-Windows

A call to QTemporaryFile::close() may not close the file but only rewind
the file pointer to the beginning allwing faster re-open. This causes
problems on MS-Windows filesystems, as one cannot e.g. rename the
temporary file in this case because it is still kept open from the
perspective of the filesystem. Only destroying the object really closes
the file on the filesystem.

This change makes sure, that the QTemporaryFile object only lives as
long as it is needed and closed immediately after by destroying the
object.
FIXED-IN: 5.1.2
(cherry picked from commit 39785a3d80c56dc6e53f301d76c41bcc8ca048c6)

M  +18   -10   kmymoney/plugins/xml/xmlstorage.cpp

https://invent.kde.org/office/kmymoney/commit/646c4cb810a960699b1b659d72bef248992f4e40</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>