Skip to content

Commit

Permalink
Merge pull request #166 from DecoyFish/master
Browse files Browse the repository at this point in the history
Having LightningEnvironment.CopyTo return an MDBResultCode
  • Loading branch information
CoreyKaylor authored Oct 11, 2023
2 parents 6f6c362 + 29a96e6 commit 2b17bc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/LightningDB.Tests/EnvironmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,25 @@ public void EnvironmentShouldBeCopied(bool compact)
_env = new LightningEnvironment(_path);
_env.Open();

_env.CopyTo(_pathCopy, compact);
_env.CopyTo(_pathCopy, compact).ThrowOnError();

if (Directory.GetFiles(_pathCopy).Length == 0)
Assert.True(false, "Copied files doesn't exist");
}

[Fact]
public void EnvironmentShouldFailCopyIfPathIsFile()
{
_env = new LightningEnvironment(_path);
_env.Open();

string filePath = Path.Combine(_pathCopy, "test.txt");
File.WriteAllBytes(filePath, Array.Empty<byte>());

MDBResultCode result = _env.CopyTo(filePath);
Assert.NotEqual(MDBResultCode.Success, result);
}

[Fact]
public void CanOpenEnvironmentMoreThan50Mb()
{
Expand Down
4 changes: 2 additions & 2 deletions src/LightningDB/LightningEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ public LightningTransaction BeginTransaction(TransactionBeginFlags beginFlags)
/// </summary>
/// <param name="path">The directory in which the copy will reside. This directory must already exist and be writable but must otherwise be empty.</param>
/// <param name="compact">Omit empty pages when copying.</param>
public void CopyTo(string path, bool compact = false)
public MDBResultCode CopyTo(string path, bool compact = false)
{
EnsureOpened();

var flags = compact
? EnvironmentCopyFlags.Compact
: EnvironmentCopyFlags.None;

mdb_env_copy2(_handle, path, flags);
return mdb_env_copy2(_handle, path, flags);
}

/// <summary>
Expand Down

0 comments on commit 2b17bc8

Please sign in to comment.