Skip to content

Commit 2b17bc8

Browse files
authored
Merge pull request #166 from DecoyFish/master
Having LightningEnvironment.CopyTo return an MDBResultCode
2 parents 6f6c362 + 29a96e6 commit 2b17bc8

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/LightningDB.Tests/EnvironmentTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,25 @@ public void EnvironmentShouldBeCopied(bool compact)
137137
_env = new LightningEnvironment(_path);
138138
_env.Open();
139139

140-
_env.CopyTo(_pathCopy, compact);
140+
_env.CopyTo(_pathCopy, compact).ThrowOnError();
141141

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

146+
[Fact]
147+
public void EnvironmentShouldFailCopyIfPathIsFile()
148+
{
149+
_env = new LightningEnvironment(_path);
150+
_env.Open();
151+
152+
string filePath = Path.Combine(_pathCopy, "test.txt");
153+
File.WriteAllBytes(filePath, Array.Empty<byte>());
154+
155+
MDBResultCode result = _env.CopyTo(filePath);
156+
Assert.NotEqual(MDBResultCode.Success, result);
157+
}
158+
146159
[Fact]
147160
public void CanOpenEnvironmentMoreThan50Mb()
148161
{

src/LightningDB/LightningEnvironment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@ public LightningTransaction BeginTransaction(TransactionBeginFlags beginFlags)
245245
/// </summary>
246246
/// <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>
247247
/// <param name="compact">Omit empty pages when copying.</param>
248-
public void CopyTo(string path, bool compact = false)
248+
public MDBResultCode CopyTo(string path, bool compact = false)
249249
{
250250
EnsureOpened();
251251

252252
var flags = compact
253253
? EnvironmentCopyFlags.Compact
254254
: EnvironmentCopyFlags.None;
255255

256-
mdb_env_copy2(_handle, path, flags);
256+
return mdb_env_copy2(_handle, path, flags);
257257
}
258258

259259
/// <summary>

0 commit comments

Comments
 (0)