From 2d17bdde19d6756d2b8d9b515ecf7964b1846ff0 Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Tue, 17 Jun 2025 14:56:52 +0200 Subject: [PATCH] add more logging while loading database to get more info regarding #2868 --- src/KeePassLib2Android/Serialization/KdbxFile.Read.cs | 4 +++- src/Kp2aBusinessLogic/database/Database.cs | 9 ++++++--- src/Kp2aBusinessLogic/database/edit/LoadDB.cs | 6 ++++-- src/keepass2android-app/app/App.cs | 5 +++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/KeePassLib2Android/Serialization/KdbxFile.Read.cs b/src/KeePassLib2Android/Serialization/KdbxFile.Read.cs index 930b3eaf..f1430ceb 100644 --- a/src/KeePassLib2Android/Serialization/KdbxFile.Read.cs +++ b/src/KeePassLib2Android/Serialization/KdbxFile.Read.cs @@ -83,6 +83,7 @@ namespace KeePassLib.Serialization if (m_bUsedOnce) throw new InvalidOperationException("Do not reuse KdbxFile objects!"); m_bUsedOnce = true; + Kp2aLog.Log("Starting to load KDBX file..."); #if KDBX_BENCHMARK Stopwatch swTime = Stopwatch.StartNew(); @@ -257,7 +258,8 @@ namespace KeePassLib.Serialization MessageService.ShowInfo("Loading KDBX took " + swTime.ElapsedMilliseconds.ToString() + " ms."); #endif - } + Kp2aLog.Log("Finished loading KDBX file."); + } private void CommonCleanUpRead(List lStreams, HashingStreamEx sHashing) { diff --git a/src/Kp2aBusinessLogic/database/Database.cs b/src/Kp2aBusinessLogic/database/Database.cs index f62572cd..1e97c166 100644 --- a/src/Kp2aBusinessLogic/database/Database.cs +++ b/src/Kp2aBusinessLogic/database/Database.cs @@ -90,9 +90,12 @@ namespace keepass2android PwDatabase pwDatabase = new PwDatabase(); IFileStorage fileStorage = _app.GetFileStorage(iocInfo); - Stream s = databaseData ?? fileStorage.OpenFileForRead(iocInfo); - var fileVersion = _app.GetFileStorage(iocInfo).GetCurrentFileVersionFast(iocInfo); - PopulateDatabaseFromStream(pwDatabase, s, iocInfo, compositeKey, status, databaseFormat); + Kp2aLog.Log("LoadData: Retrieving stream"); + Stream s = databaseData ?? fileStorage.OpenFileForRead(iocInfo); + Kp2aLog.Log("LoadData: GetCurrentFileVersion"); + var fileVersion = _app.GetFileStorage(iocInfo).GetCurrentFileVersionFast(iocInfo); + Kp2aLog.Log("LoadData: PopulateDatabaseFromStream"); + PopulateDatabaseFromStream(pwDatabase, s, iocInfo, compositeKey, status, databaseFormat); LastFileVersion = fileVersion; status.UpdateSubMessage(""); diff --git a/src/Kp2aBusinessLogic/database/edit/LoadDB.cs b/src/Kp2aBusinessLogic/database/edit/LoadDB.cs index 7a3b3597..d76e3502 100644 --- a/src/Kp2aBusinessLogic/database/edit/LoadDB.cs +++ b/src/Kp2aBusinessLogic/database/edit/LoadDB.cs @@ -138,6 +138,7 @@ namespace keepass2android Database TryLoad(MemoryStream databaseStream) { + Kp2aLog.Log("LoadDb: Copying database in memory"); //create a copy of the stream so we can try again if we get an exception which indicates we should change parameters //This is not optimal in terms of (short-time) memory usage but is hard to avoid because the Keepass library closes streams also in case of errors. //Alternatives would involve increased traffic (if file is on remote) and slower loading times, so this seems to be the best choice. @@ -146,8 +147,9 @@ namespace keepass2android workingCopy.Seek(0, SeekOrigin.Begin); //reset stream if we need to reuse it later: databaseStream.Seek(0, SeekOrigin.Begin); - //now let's go: - try + Kp2aLog.Log("LoadDb: Ready to start loading"); + //now let's go: + try { Database newDb = _app.LoadDatabase(_ioc, workingCopy, _compositeKey, StatusLogger, _format, _makeCurrent); Kp2aLog.Log("LoadDB OK"); diff --git a/src/keepass2android-app/app/App.cs b/src/keepass2android-app/app/App.cs index 7420a6f4..80324987 100644 --- a/src/keepass2android-app/app/App.cs +++ b/src/keepass2android-app/app/App.cs @@ -191,8 +191,8 @@ namespace keepass2android var prefs = PreferenceManager.GetDefaultSharedPreferences(LocaleManager.LocalizedAppContext); var createBackup = prefs.GetBoolean(LocaleManager.LocalizedAppContext.GetString(Resource.String.CreateBackups_key), true) && !(new LocalFileStorage(this).IsLocalBackup(ioConnectionInfo)); - - MemoryStream backupCopy = new MemoryStream(); + Kp2aLog.Log("LoadDb: Copying database for backup"); + MemoryStream backupCopy = new MemoryStream(); if (createBackup) { @@ -201,6 +201,7 @@ namespace keepass2android //reset stream if we need to reuse it later: memoryStream.Seek(0, SeekOrigin.Begin); } + Kp2aLog.Log("LoadDb: Checking open databases"); foreach (Database openDb in _openDatabases) {