Permalink
Browse files

Fixed GridFS bug where deleting by filename didn't delete the file ch…

…unks.
  • Loading branch information...
1 parent ce841da commit 3a68dc116f5e320709c8dfdf83207a306e4dda48 @samus committed Jun 20, 2010
@@ -68,9 +68,11 @@ public class GridFileInfoTest : GridTestBase
String filename = "gfi-delete.txt";
GridFile gf = new GridFile(DB,"gfdelete");
GridFileInfo gfi = new GridFileInfo(DB,"gfdelete", filename);
+ var id = gfi.Id;
GridFileStream gfs = gfi.Create(); //TODO Expand Test to make sure that chunks for the file got deleted too.
gfi.Delete();
Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
+ Assert.IsTrue(0 == gf.Chunks.Count(new Document("_id", id)));
}
[Test]
@@ -54,6 +54,23 @@ public class GridFileTest : GridTestBase
tw.Close();
}
Assert.AreEqual(1, CountChunks("gfcreate", id));
- }
+ }
+
+ [Test]
+ public void TestDeleteRemovesChunks(){
+ Object id;
+ string filename = "deletebyname.txt";
+ string fs = "fs";
+ GridFile gf = new GridFile(DB,fs);
+ using(GridFileStream gfs = gf.Create(filename, FileMode.CreateNew)){
+ id = gfs.GridFileInfo.Id;
+ TextWriter tw = new StreamWriter(gfs);
+ tw.WriteLine("test");
+ tw.Close();
+ }
+ Assert.AreEqual(1, CountChunks(fs, id), "Chunks not found");
+ gf.Delete("deletebyname.txt");
+ Assert.AreEqual(0, CountChunks(fs, id), "Chunks found");
+ }
}
}
@@ -1,5 +1,5 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -54,12 +54,12 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
- <Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\redist\nunit.framework.dll</HintPath>
</Reference>
- <Reference Include="System" />
- <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GridFileInfoTest.cs" />
@@ -71,6 +71,7 @@
</None>
<None Include="..\MongoDB.Tests\App.config">
<Link>App.config</Link>
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="MongoDB.GridFS.Tests.csproj" />
</ItemGroup>
@@ -56,6 +56,7 @@ public IMongoCollection Chunks
this.files = db[bucket + ".files"];
this.chunks = db[bucket + ".chunks"];
this.chunks.MetaData.CreateIndex(new Document().Add("files_id", 1).Add("n", 1), true);
+ this.files.MetaData.CreateIndex(new Document().Add("filename", 1).Add("n", 1), false);
this.name = bucket;
}
@@ -199,7 +200,7 @@ public ICursor ListFiles(Document query)
/// Permanently removes a file from the database.
/// </summary>
public void Delete(String filename){
- files.Remove(new Document().Add("filename", filename));
+ this.Delete(new Document().Add("filename", filename));
}
/// <summary>

0 comments on commit 3a68dc1

Please sign in to comment.