add more logging while loading database to get more info regarding #2868

This commit is contained in:
Philipp Crocoll
2025-06-17 14:56:52 +02:00
parent adbbfa0ac1
commit 2d17bdde19
4 changed files with 16 additions and 8 deletions

View File

@@ -83,6 +83,7 @@ namespace KeePassLib.Serialization
if (m_bUsedOnce) if (m_bUsedOnce)
throw new InvalidOperationException("Do not reuse KdbxFile objects!"); throw new InvalidOperationException("Do not reuse KdbxFile objects!");
m_bUsedOnce = true; m_bUsedOnce = true;
Kp2aLog.Log("Starting to load KDBX file...");
#if KDBX_BENCHMARK #if KDBX_BENCHMARK
Stopwatch swTime = Stopwatch.StartNew(); Stopwatch swTime = Stopwatch.StartNew();
@@ -257,7 +258,8 @@ namespace KeePassLib.Serialization
MessageService.ShowInfo("Loading KDBX took " + MessageService.ShowInfo("Loading KDBX took " +
swTime.ElapsedMilliseconds.ToString() + " ms."); swTime.ElapsedMilliseconds.ToString() + " ms.");
#endif #endif
} Kp2aLog.Log("Finished loading KDBX file.");
}
private void CommonCleanUpRead(List<Stream> lStreams, HashingStreamEx sHashing) private void CommonCleanUpRead(List<Stream> lStreams, HashingStreamEx sHashing)
{ {

View File

@@ -90,9 +90,12 @@ namespace keepass2android
PwDatabase pwDatabase = new PwDatabase(); PwDatabase pwDatabase = new PwDatabase();
IFileStorage fileStorage = _app.GetFileStorage(iocInfo); IFileStorage fileStorage = _app.GetFileStorage(iocInfo);
Stream s = databaseData ?? fileStorage.OpenFileForRead(iocInfo); Kp2aLog.Log("LoadData: Retrieving stream");
var fileVersion = _app.GetFileStorage(iocInfo).GetCurrentFileVersionFast(iocInfo); Stream s = databaseData ?? fileStorage.OpenFileForRead(iocInfo);
PopulateDatabaseFromStream(pwDatabase, s, iocInfo, compositeKey, status, databaseFormat); Kp2aLog.Log("LoadData: GetCurrentFileVersion");
var fileVersion = _app.GetFileStorage(iocInfo).GetCurrentFileVersionFast(iocInfo);
Kp2aLog.Log("LoadData: PopulateDatabaseFromStream");
PopulateDatabaseFromStream(pwDatabase, s, iocInfo, compositeKey, status, databaseFormat);
LastFileVersion = fileVersion; LastFileVersion = fileVersion;
status.UpdateSubMessage(""); status.UpdateSubMessage("");

View File

@@ -138,6 +138,7 @@ namespace keepass2android
Database TryLoad(MemoryStream databaseStream) 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 //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. //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. //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); workingCopy.Seek(0, SeekOrigin.Begin);
//reset stream if we need to reuse it later: //reset stream if we need to reuse it later:
databaseStream.Seek(0, SeekOrigin.Begin); databaseStream.Seek(0, SeekOrigin.Begin);
//now let's go: Kp2aLog.Log("LoadDb: Ready to start loading");
try //now let's go:
try
{ {
Database newDb = _app.LoadDatabase(_ioc, workingCopy, _compositeKey, StatusLogger, _format, _makeCurrent); Database newDb = _app.LoadDatabase(_ioc, workingCopy, _compositeKey, StatusLogger, _format, _makeCurrent);
Kp2aLog.Log("LoadDB OK"); Kp2aLog.Log("LoadDB OK");

View File

@@ -191,8 +191,8 @@ namespace keepass2android
var prefs = PreferenceManager.GetDefaultSharedPreferences(LocaleManager.LocalizedAppContext); var prefs = PreferenceManager.GetDefaultSharedPreferences(LocaleManager.LocalizedAppContext);
var createBackup = prefs.GetBoolean(LocaleManager.LocalizedAppContext.GetString(Resource.String.CreateBackups_key), true) var createBackup = prefs.GetBoolean(LocaleManager.LocalizedAppContext.GetString(Resource.String.CreateBackups_key), true)
&& !(new LocalFileStorage(this).IsLocalBackup(ioConnectionInfo)); && !(new LocalFileStorage(this).IsLocalBackup(ioConnectionInfo));
Kp2aLog.Log("LoadDb: Copying database for backup");
MemoryStream backupCopy = new MemoryStream(); MemoryStream backupCopy = new MemoryStream();
if (createBackup) if (createBackup)
{ {
@@ -201,6 +201,7 @@ namespace keepass2android
//reset stream if we need to reuse it later: //reset stream if we need to reuse it later:
memoryStream.Seek(0, SeekOrigin.Begin); memoryStream.Seek(0, SeekOrigin.Begin);
} }
Kp2aLog.Log("LoadDb: Checking open databases");
foreach (Database openDb in _openDatabases) foreach (Database openDb in _openDatabases)
{ {