mbdavid/LiteDB

[BUG] LiteDatabase.Rebuild method reset password to empty, and fails

ArsenMkrt opened this issue · 1 comments

Version
5.0.18, 5.0.19

Describe the bug
When database is encrypted with password, database.Rebuild() call reset password to empty, than fails
This behavior have been changed from version 5.0.17, until version 5.0.18 it was just rebuilding the database and keeping password if no parameter have been provided to Rebuild method.

Error: Unhandled exception. LiteDB.LiteException: File is not encrypted.

Code to Reproduce
var connectionString = new LiteDB.ConnectionString() { Filename = "test.db", Password = "password", }; LiteDB.ILiteDatabase db = new LiteDB.LiteDatabase(connectionString); db.Rebuild();

Expected behavior
db.Rebuild() should just rebuild the database, as ILiteDatabase already contains the password

Screenshots/Stacktrace

Unhandled exception. LiteDB.LiteException: File is not encrypted.
at LiteDB.Engine.AesStream..ctor(String password, Stream stream)
at LiteDB.Engine.FileStreamFactory.GetStream(Boolean canWrite, Boolean sequencial)
at LiteDB.Engine.StreamPool.<>c__DisplayClass3_0.<.ctor>b__0()
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue() at System.Lazy1.get_Value()
at LiteDB.Engine.StreamPool.get_Writer()
at LiteDB.Engine.DiskService..ctor(EngineSettings settings, EngineState state, Int32[] memorySegmentSizes)
at LiteDB.Engine.LiteEngine.Open()
at LiteDB.Engine.LiteEngine..ctor(EngineSettings settings)
at LiteDB.ConnectionString.CreateEngine()
at LiteDB.LiteDatabase..ctor(ConnectionString connectionString, BsonMapper mapper)
at Program.

$(String[] args) in D:\tools\My\ConsoleApp2\ConsoleApp2\Program.cs:line 7

Additional context
As a workaround password can be provided one more time

db.Rebuild(new LiteDB.Engine.RebuildOptions { Password = "password" });

Checked the code, in method public long Rebuild(RebuildOptions options = null) it should use settings to build RebuildOptions when null

return _engine.Rebuild(options ?? new RebuildOptions()); // password is null here if options is passed as null