Solve some bugs related to archives, remove some duplicated code
Closed, ResolvedPublic

Description

SUMMARY

Solve two bugs related to archives:

  • Bug 417107: QCoreApplication::applicationDirPath: Please instantiate the QApplication object first
  • Bug 419396: When trying to open a 7z encrypted archive, Krusader does not ask for a password

and remove some duplicated code, add some comments in order to clarify the source code, and add minor improvements.

The performed changes have been grouped into several code reviews for an easier reviewing. However, the changes can be applied one after the other and tested at the end (at once, instead of testing each code review separately :-) ).

TEST PLAN

  • Steps to carry out some tests that can performed more easily:
    1. Before applying the changes:
      • In order to test later the solution to the "QCoreApplication::applicationDirPath: Please instantiate the QApplication object first" error:
        • Executing Krusader from the command line under a distribution with recent software (for example Kubuntu 19.10). Seeing that a "QCoreApplication::applicationDirPath: Please instantiate the QApplication object first" error appears", like it's reported in https://bugs.kde.org/show_bug.cgi?id=417107
      • In order to test later the solution to the "enter an encrypted 7z archive" problem:
        1. Creating a 7z encrypted archive that can not be browsed without a password (because its headers are also encrypted): 7z a /tmp/test-mhe.7z -mhe -ptest /etc/papersize /etc/hosts, entering the archive, and finding problems (like not being asked for a password, waiting a lot, and finally seeing only "..").
        2. Creating a 7z encrypted archive that can be browsed without the password: 7z a /tmp/test-without-mhe.7z -ptest /etc/hosts /etc/hosts.allow /etc/hosts.deny, entering the archive, and finding problems when trying to use F3 to see the content of e.g. its "hosts" file.
    2. Applying the changes.
    3. After applying the changes:
      • Executing Krusader from the command line under a distribution with recent software (for example Kubuntu 19.10). Seeing that the "QCoreApplication::applicationDirPath: Please instantiate the QApplication object first" error message does not appear.
      • Entering several archives of different types, reading files from each archive, adding files to archives, removing them.
      • Entering iso files, reading files from each iso file.
      • Entering again the /tmp/test-mhe.7z and /tmp/test-without-mhe.7z archives. Using F3 to see the contents of their files, answering "test" when prompted for a password, seeing that a password is asked (instead of waiting a lot, and finally seeing only "..").
      • Use Krusader to pack files into 7z archives, and other kind of archives (like zip ones).
  • Steps to carry out other tests that I performed:
    • If it may be useful, in order to test if the zip, 7z and 7za programs were found, and how different situations were dealt with, I followed steps similar to those:
      • defining the QT_DEBUG macro:
        • adding at the beginning of the "krdebuglogger.h" file: #define QT_DEBUG (or, alternatively, adding -DQT_DEBUG to the -DCMAKE_CXX_FLAGS when executing cmake);
      • compiling, installing (e.g. sudo make install copies "kio_krarc.so" to "/usr/lib/[...]") and executing Krusader;
      • I entered a zip archive, used F3 to view one file from the archive, closed Krusader and I backed up the trace file (/tmp/krdebug);
      • I executed sudo mv /usr/bin/unzip /usr/bin/unzipORIGINAL and again I entered a zip archive, used F3 to view one file from the archive, closed Krusader, backed up the trace file (/tmp/krdebug);
      • I compared the new trace with the previous one;
        • Note: this a command that usually helps because it suppresses the first column (the one that has a PID) of a trace, and suppresses whatever exists between parenthesis (because several line numbers are usually changed between development sessions):
          • cat "/tmp/krdebug" | cut -d ' ' -f 2- | sed 's/(.*)//g' > file_that_can_be_more_easily_compared
      • I performed similar steps, this time executing also sudo mv /usr/bin/zip /usr/bin/zipORIGINAL, next time also sudo mv /usr/bin/7z /usr/bin/7zORIGINAL and next time executing also sudo mv /usr/bin/7za /usr/bin/7zaORIGINAL
      • Similar tests were performed with 7z files.
      • At the end:
        • I restored the programs that still weren't restored. For example:
          • sudo mv /usr/bin/unzipORIGINAL /usr/bin/unzip
          • sudo mv /usr/bin/zipORIGINAL /usr/bin/zip
          • sudo mv /usr/bin/7zORIGINAL /usr/bin/7z
          • sudo mv /usr/bin/7zaORIGINAL /usr/bin/7za
        • I reversed the "defining the QT_DEBUG macro" step.