-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set correct case for DB file path on open (fix for #7139) #7214
Conversation
Does QFileInfo(path).absoluteFilePath() return the correct case? |
Scratch that, I manually closed the database and tried again. For a database called TEST.kdbx opened as test.kdbx, QFileInfo(filePath).absoluteFilePath() returns test.kdbx. It must've just reopened my last used database on the first try. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7214 +/- ##
========================================
Coverage 64.56% 64.56%
========================================
Files 339 339
Lines 43855 43856 +1
========================================
+ Hits 28312 28313 +1
Misses 15543 15543 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
Fixed. Just had to format the code. |
src/core/Database.cpp
Outdated
// Get correct case for Windows filename (fixes #7139) | ||
QFileInfo fileInfo(filePath); | ||
QDir dir = fileInfo.dir(); | ||
QFileInfoList files = dir.entryInfoList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified a bit (since by default entryList()
matches with case insensitive)
QStringList files = dir.entryList(QStringList{fileInfo.fileName()}, QDir::Files);
if (files.size() > 0) {
setFilePath(files.at(0));
}
Can we simplify the code any further? I don't like the brute force search approach. |
@droidmonkey Well, I also do not like it... If you want to "simplify" it, there is this solution: https://docs.microsoft.com/en-us/windows/win32/memory/obtaining-a-file-name-from-a-file-handle?redirectedfrom=MSDN |
You could use FindFirstFile Windows API: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfilea#examples Then extract the filename from the data structure. |
* Fix keepassxreboot#7139 - when opening database files from the command line, ensure the correct case is fed to the program to prevent case changes during saves. * Cleanup old code (checking for .json extension) from when KeePassXC app could act as a proxy.
59d35d0
to
b121269
Compare
I switched over to the native Windows function, moved the code closest to the source of input error (main.cpp), and cleaned up some old code. |
Fixes #7139. On database open, if OS is Windows, find correct case for database filename by searching through database parent folder. If found, overwrite internal database file path with corrected file path so that, on database modification, database is not saved under a new name. For example, if your database is DB.kdbx and you open db.kdbx on the Windows command line, then add a new entry and save your database, DB.kdbx is maintained as the filename. Previously, DB.kdbx would be overwritten with db.kdbx on save.
Screenshots
Old behavior:
old.mp4
New behavior:
new.mp4
Testing strategy
I tested the change manually, as you can see in the video included above. I also ran
make test
.Type of change