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

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

Open
ArsenMkrt opened this issue Mar 15, 2024 · 1 comment
Open
Labels

Comments

@ArsenMkrt
Copy link

ArsenMkrt commented Mar 15, 2024

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" });

@ArsenMkrt ArsenMkrt added the bug label Mar 15, 2024
@ArsenMkrt
Copy link
Author

ArsenMkrt commented Mar 15, 2024

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

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

No branches or pull requests

1 participant