summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnne Jan Brouwer <brouwer@annejan.com>2020-11-05 18:15:15 +0100
committerGitHub <noreply@github.com>2020-11-05 18:15:15 +0100
commit0d0f29657f2c9d2bc8e20a8806dc4cd7ee8d7121 (patch)
tree30fe6225be09eff07058b6b21e7866e069fc44a2
parentda8aeb3678eed52deb37c22ef640b69b4c991e59 (diff)
parent0455ab57968daee85ba5703715972dc8feff702e (diff)
Merge pull request #532 from ChaoticEnigma/master
Fix issues with renaming passwords and moving folders
-rw-r--r--src/imitatepass.cpp77
-rw-r--r--src/mainwindow.cpp5
2 files changed, 60 insertions, 22 deletions
diff --git a/src/imitatepass.cpp b/src/imitatepass.cpp
index 57395134..641ed546 100644
--- a/src/imitatepass.cpp
+++ b/src/imitatepass.cpp
@@ -125,7 +125,10 @@ void ImitatePass::Insert(QString file, QString newValue, bool overwrite) {
* @param msg
*/
void ImitatePass::GitCommit(const QString &file, const QString &msg) {
- executeGit(GIT_COMMIT, {"commit", "-m", msg, "--", pgit(file)});
+ if (file.isEmpty())
+ executeGit(GIT_COMMIT, {"commit", "-m", msg});
+ else
+ executeGit(GIT_COMMIT, {"commit", "-m", msg, "--", pgit(file)});
}
/**
@@ -342,8 +345,52 @@ void ImitatePass::reencryptPath(const QString &dir) {
void ImitatePass::Move(const QString src, const QString dest,
const bool force) {
- QFileInfo destFileInfo(dest);
transactionHelper trans(this, PASS_MOVE);
+ QFileInfo srcFileInfo(src);
+ QFileInfo destFileInfo(dest);
+ QString destFile;
+
+ if (srcFileInfo.isFile()) {
+ if (destFileInfo.isFile()) {
+ if (!force) {
+#ifdef QT_DEBUG
+ dbg() << "Destination file already exists";
+#endif
+ return;
+ }
+ } else if (destFileInfo.isDir()) {
+ destFile = QDir(dest).filePath(srcFileInfo.baseName());
+ } else {
+ destFile = dest;
+ }
+
+ if (!destFile.endsWith(".gpg"))
+ destFile.append(".gpg");
+
+ } else if (srcFileInfo.isDir()) {
+ if (destFileInfo.isDir()) {
+ destFile = QDir(dest).filePath(srcFileInfo.baseName());
+ } else if (destFileInfo.isFile()) {
+#ifdef QT_DEBUG
+ dbg() << "Destination is a file";
+#endif
+ return;
+ } else {
+ destFile = dest;
+ }
+
+ } else {
+#ifdef QT_DEBUG
+ dbg() << "Source file does not exist";
+#endif
+ return;
+ }
+
+#ifdef QT_DEBUG
+ dbg() << "Move Source: " << src;
+ dbg() << "Move Destination: " << destFile;
+#endif
+
if (QtPassSettings::isUseGit()) {
QStringList args;
args << "mv";
@@ -351,30 +398,22 @@ void ImitatePass::Move(const QString src, const QString dest,
args << "-f";
}
args << pgit(src);
- args << pgit(dest);
+ args << pgit(destFile);
executeGit(GIT_MOVE, args);
- QString message = QString("moved from %1 to %2 using QTPass.");
- message = message.arg(src).arg(dest);
+ QString relSrc = QDir(QtPassSettings::getPassStore()).relativeFilePath(src);
+ relSrc.replace(QRegExp("\\.gpg$"), "");
+ QString relDest = QDir(QtPassSettings::getPassStore()).relativeFilePath(destFile);
+ relDest.replace(QRegExp("\\.gpg$"), "");
+ QString message = QString("Moved for %1 to %2 using QtPass.");
+ message = message.arg(relSrc).arg(relDest);
GitCommit("", message);
} else {
QDir qDir;
- QFileInfo srcFileInfo(src);
- QString destCopy = dest;
- if (srcFileInfo.isFile() && destFileInfo.isDir()) {
- destCopy = destFileInfo.absoluteFilePath() + QDir::separator() +
- srcFileInfo.fileName();
- }
if (force) {
- qDir.remove(destCopy);
+ qDir.remove(destFile);
}
- qDir.rename(src, destCopy);
- }
- // reecrypt all files under the new folder
- if (destFileInfo.isDir()) {
- reencryptPath(destFileInfo.absoluteFilePath());
- } else if (destFileInfo.isFile()) {
- reencryptPath(destFileInfo.dir().path());
+ qDir.rename(src, destFile);
}
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 9134d3c6..036fba12 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1016,15 +1016,14 @@ void MainWindow::editPassword(const QString &file) {
void MainWindow::renamePassword() {
bool ok;
QString file = getFile(ui->treeView->currentIndex(), false);
+ QString filePath = QFileInfo(file).path();
QString fileName = QFileInfo(file).baseName();
QString newName =
QInputDialog::getText(this, tr("Rename file"), tr("Rename File To: "),
QLineEdit::Normal, fileName, &ok);
if (!ok || newName.isEmpty())
return;
- QString newFile = file;
- newFile.replace(file.lastIndexOf(fileName), fileName.length(), newName);
- newFile.replace(QRegExp("\\.gpg$"), "");
+ QString newFile = QDir(filePath).filePath(newName);
QtPassSettings::getPass()->Move(file, newFile);
}