Skip to content

Commit

Permalink
fix: tar node with raw and cms files
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jun 1, 2019
1 parent aca8cc9 commit f3c5591
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/CoreApi/FileSystemApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,14 @@ async Task<FileSystemNode> CreateDirectoryAsync (IEnumerable<IFileSystemLink> li
async Task AddTarNodeAsync(Cid cid, string name, TarOutputStream tar, CancellationToken cancel)
{
var block = await ipfs.Block.GetAsync(cid, cancel).ConfigureAwait(false);
var dag = new DagNode(block.DataStream);
var dm = Serializer.Deserialize<DataMessage>(dag.DataStream);
var dm = new DataMessage { Type = DataType.Raw };
DagNode dag = null;

if (cid.ContentType == "dag-pb")
{
dag = new DagNode(block.DataStream);
dm = Serializer.Deserialize<DataMessage>(dag.DataStream);
}
var entry = new TarEntry(new TarHeader());
var header = entry.TarHeader;
header.Mode = 0x1ff; // 777 in octal
Expand Down Expand Up @@ -307,7 +312,7 @@ async Task AddTarNodeAsync(Cid cid, string name, TarOutputStream tar, Cancellati
tar.CloseEntry();
}

// TODO: recurse over files and subdirectories
// Recurse over files and subdirectories
if (dm.Type == DataType.Directory)
{
foreach (var link in dag.Links)
Expand Down
37 changes: 37 additions & 0 deletions test/CoreApi/FileSystemApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,43 @@ public async Task GetTar()
}
}

[TestMethod]
public async Task GetTar_RawLeaves()
{
var ipfs = TestFixture.Ipfs;
var temp = MakeTemp();
try
{
var options = new AddFileOptions
{
RawLeaves = true
};
var dir = ipfs.FileSystem.AddDirectoryAsync(temp, true, options).Result;
var dirid = dir.Id.Encode();

var tar = await ipfs.FileSystem.GetAsync(dir.Id);
var archive = TarArchive.CreateInputTarArchive(tar);
var files = new List<string>();
archive.ProgressMessageEvent += (a, e, m) =>
{
files.Add(e.Name);
};
archive.ListContents();

Assert.AreEqual($"{dirid}", files[0]);
Assert.AreEqual($"{dirid}/alpha.txt", files[1]);
Assert.AreEqual($"{dirid}/beta.txt", files[2]);
Assert.AreEqual($"{dirid}/x", files[3]);
Assert.AreEqual($"{dirid}/x/x.txt", files[4]);
Assert.AreEqual($"{dirid}/x/y", files[5]);
Assert.AreEqual($"{dirid}/x/y/y.txt", files[6]);
}
finally
{
Directory.Delete(temp, true);
}
}

[TestMethod]
public async Task GetTar_EmptyDirectory()
{
Expand Down

0 comments on commit f3c5591

Please sign in to comment.