From 4dc894d809d83ca6fbf1879bfc03da472e5f58db Mon Sep 17 00:00:00 2001 From: Mirian Margiani Date: Mon, 21 Dec 2020 10:34:52 +0100 Subject: Use complete filename when moving (to) a directory QFileInfo::baseName removes the path plus the complete suffix. We want to remove only the ".gpg" suffix manually, though. --- src/imitatepass.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/imitatepass.cpp b/src/imitatepass.cpp index ed926ba0..82be1d91 100644 --- a/src/imitatepass.cpp +++ b/src/imitatepass.cpp @@ -350,6 +350,7 @@ void ImitatePass::Move(const QString src, const QString dest, QFileInfo srcFileInfo(src); QFileInfo destFileInfo(dest); QString destFile; + QString srcFileBaseName = srcFileInfo.fileName(); if (srcFileInfo.isFile()) { if (destFileInfo.isFile()) { @@ -360,7 +361,7 @@ void ImitatePass::Move(const QString src, const QString dest, return; } } else if (destFileInfo.isDir()) { - destFile = QDir(dest).filePath(srcFileInfo.baseName()); + destFile = QDir(dest).filePath(srcFileBaseName); } else { destFile = dest; } @@ -370,7 +371,7 @@ void ImitatePass::Move(const QString src, const QString dest, } else if (srcFileInfo.isDir()) { if (destFileInfo.isDir()) { - destFile = QDir(dest).filePath(srcFileInfo.baseName()); + destFile = QDir(dest).filePath(srcFileBaseName); } else if (destFileInfo.isFile()) { #ifdef QT_DEBUG dbg() << "Destination is a file"; @@ -379,7 +380,6 @@ void ImitatePass::Move(const QString src, const QString dest, } else { destFile = dest; } - } else { #ifdef QT_DEBUG dbg() << "Source file does not exist"; -- cgit v1.2.3 From 525cf4a48bc8da26eeb6d57c142c5a20443a9e87 Mon Sep 17 00:00:00 2001 From: Mirian Margiani Date: Mon, 21 Dec 2020 10:42:53 +0100 Subject: Make sure filenames end with lowercase ".gpg" when moving --- src/imitatepass.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/imitatepass.cpp b/src/imitatepass.cpp index 82be1d91..2140505b 100644 --- a/src/imitatepass.cpp +++ b/src/imitatepass.cpp @@ -366,9 +366,9 @@ void ImitatePass::Move(const QString src, const QString dest, destFile = dest; } - if (!destFile.endsWith(".gpg")) - destFile.append(".gpg"); - + if (destFile.endsWith(".gpg", Qt::CaseInsensitive)) + destFile.chop(4); // make sure suffix is lowercase + destFile.append(".gpg"); } else if (srcFileInfo.isDir()) { if (destFileInfo.isDir()) { destFile = QDir(dest).filePath(srcFileBaseName); -- cgit v1.2.3