Skip to content

Commit

Permalink
Prevent overwriting of portable config on update
Browse files Browse the repository at this point in the history
* Move portable configuration files into a config subfolder from the executable. This prevents overwriting the stored config when the application is updated in-place.
* Use .portable file to signal a portable app
* Fix #4751
  • Loading branch information
droidmonkey committed Jun 3, 2020
1 parent 546ebe6 commit a13e7a9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
4 changes: 3 additions & 1 deletion release-tool
Original file line number Diff line number Diff line change
Expand Up @@ -987,13 +987,15 @@ build() {
cpack -G "${CPACK_GENERATORS};${build_generators}"

# Inject the portable config into the zip build and rename
touch .portable
for filename in ${APP_NAME}-*.zip; do
logInfo "Creating portable zip file"
local folder=$(echo ${filename} | sed -r 's/(.*)\.zip/\1/')
python -c 'import zipfile,sys ; zipfile.ZipFile(sys.argv[1],"a").write(sys.argv[2],sys.argv[3])' \
${filename} ${SRC_DIR}/share/keepassxc.ini ${folder}/keepassxc.ini
${filename} .portable ${folder}/.portable
mv ${filename} ${folder}-portable.zip
done
rm .portable

mv "${APP_NAME}-"*.* ../
else
Expand Down
10 changes: 0 additions & 10 deletions share/keepassxc.ini

This file was deleted.

8 changes: 4 additions & 4 deletions src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ Config::Config(const QString& fileName, QObject* parent)
Config::Config(QObject* parent)
: QObject(parent)
{
// Check if portable config is present (use it also to store local config)
QString portablePath = QDir::fromNativeSeparators(QCoreApplication::applicationDirPath()) + "/keepassxc.ini";
if (QFile::exists(portablePath)) {
init(portablePath);
// Check if we are running in portable mode, if so store the config files local to the app
auto appDir = QCoreApplication::applicationDirPath();
if (QFile::exists(appDir + QStringLiteral("/.portable"))) {
init(appDir + QStringLiteral("/config/keepassxc.ini"), appDir + QStringLiteral("/config/keepassxc_local.ini"));
return;
}

Expand Down

0 comments on commit a13e7a9

Please sign in to comment.