Skip to content
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

Opening the same kbdx file in different ways results in two Local Paths #50

Closed
twistedvibe opened this issue Feb 2, 2018 · 6 comments
Closed
Assignees

Comments

@twistedvibe
Copy link

twistedvibe commented Feb 2, 2018

When opening a kbdx file via SharePoint using the File>Open menu works successfully and creates a Local Path in OneDriveSync Options as expected.

Opening the same local file via double clicking in Windows Explorer wants to create a second Local Path in OneDriveSync Options, with just the filename and not the full path. Once opened it errors:

"Failed to sync. Please don't switch to another database before done."

It seems the entries interfere with each other.

I've enclosed a screenshot, hopefully this makes sense.

keepasssync

@KoenZomers
Copy link
Owner

Thanks for sharing. Are you using the portable version of KeePass or the installer?

@twistedvibe
Copy link
Author

The installer, latest version of both KeePass and your plugin...

@KoenZomers KoenZomers self-assigned this Feb 5, 2018
@KoenZomers
Copy link
Owner

I can reproduce it. Will investigate where it goes wrong.

@KoenZomers
Copy link
Owner

This should be fixed in version 2.0.2.0. Can you give it a try and see if it resolves the issue for you?

@rangerxusa
Copy link

rangerxusa commented May 17, 2018

I like your plugin for syncing with onedrive. I too encounter problems with multiple entries in the config form and sync errors. I downloaded your code and tried to find the problem. NOTE: The source you posted under releases with the 2.0.2.0 plugin is actually code 2.0.1.2 so I wasted some time debugging the wrong code.
You had already seen that using Environment.Currentdirectoy was a problem as it is not the application folder but the working directory. When using KeePass option to run at startup the system uses c:\windows\system32 which broke your code. I changed the reference to use Application.StartupPath which fixed some problems. But there were still errors in the Configuration form display and when syncing getting "Please don't switch to another database before done".
Looking at the code further it seems there are a lot of methods that expect the full path and do not have the code to expand the relative path to the full path. I started to change the code but decided there were way to many places that needed to be changed.
I assume you use the relative patch for portable users so they can store their database in the KeePass folder and no matter where the portable KeePass is loaded it can use the existing settings for syncing. I decided to remove the relative path code from the plugin. There were four places 1) KoenZomersKeePassOneDriveSyncExt.cs KeePassDatabaseOpened, KoenZomersKeePassOneDriveSyncExt.cs MainWindowOnFileSaved, and OneDriveProvide.cs & SharePointProvder.cs (both in the IF statement after comment "Ensure the database that needs to be synced is still the database currently selected"). After recompile I have had no problems with duplicate paths in the Configuration form or error message when syncing.
It seemed to me instead of recoding many places to support relative paths it would be better to always store the full patch and do a test when opening a database. In Configuration.cs GetPasswordDatabaseConfiguration change code as follows: 1) If database not found then get the DB name to open and FOREACH the configuration.keys and see it it already exists with another path. If true and it's folder path contains the folder (not full path) of the keepass.exe then assume it is one and the same. Since you can't change the configuration.key add a new configuration entry with the new path + DB Name as key and old path's configuration.value and then delete the entire configuration entry of the old path. Now you have the full path and all your code will work. You need to to do a similar check and switch in the OneDriveConfigForm.cs so the form doesn't show database not found. I don't think there are other places that would need to be changed.
I started to make the above code changes but have ran out of time. I thought I would pass these thoughts on to you in case they are of any value.

@KoenZomers
Copy link
Owner

Thanks @rangerxusa for sharing your findings. I actually didn't notice them until now, which is more than a year later. Sorry for that. I have made attempts to make changes in this area as well and ran against the same challenge: the path is so tied in all the code that it will likely cause a lot of issues if I try to change it all to relative paths. I started on attempts to do so and after some hours decided to not go for it. Maybe in the future I will make another attempt. For now I'll close this issue as the issue for which this thread was opened has been resolved a while ago already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants