public void testSimpleIterate() { var top = new FileTreeIterator(trash); Assert.IsTrue(top.first()); Assert.IsFalse(top.eof()); Assert.IsTrue(FileMode.RegularFile == top.EntryFileMode); Assert.AreEqual(Paths[0], NameOf(top)); Assert.AreEqual(Paths[0].Length, top.getEntryLength()); Assert.AreEqual(_mtime[0], top.getEntryLastModified()); top.next(1); Assert.IsFalse(top.first()); Assert.IsFalse(top.eof()); Assert.IsTrue(FileMode.RegularFile == top.EntryFileMode); Assert.AreEqual(Paths[1], NameOf(top)); Assert.AreEqual(Paths[1].Length, top.getEntryLength()); Assert.AreEqual(_mtime[1], top.getEntryLastModified()); top.next(1); Assert.IsFalse(top.first()); Assert.IsFalse(top.eof()); Assert.IsTrue(FileMode.Tree == top.EntryFileMode); AbstractTreeIterator sub = top.createSubtreeIterator(db); Assert.IsTrue(sub is FileTreeIterator); var subfti = (FileTreeIterator)sub; Assert.IsTrue(sub.first()); Assert.IsFalse(sub.eof()); Assert.AreEqual(Paths[2], NameOf(sub)); Assert.AreEqual(Paths[2].Length, subfti.getEntryLength()); Assert.AreEqual(_mtime[2], subfti.getEntryLastModified()); sub.next(1); Assert.IsTrue(sub.eof()); top.next(1); Assert.IsFalse(top.first()); Assert.IsFalse(top.eof()); Assert.IsTrue(FileMode.RegularFile == top.EntryFileMode); Assert.AreEqual(Paths[3], NameOf(top)); Assert.AreEqual(Paths[3].Length, top.getEntryLength()); Assert.AreEqual(_mtime[3], top.getEntryLastModified()); top.next(1); Assert.IsTrue(top.eof()); }
public virtual void testCreateSubtreeIterator() { EmptyTreeIterator etp = new EmptyTreeIterator(); AbstractTreeIterator sub = etp.createSubtreeIterator(db); Assert.IsNotNull(sub); Assert.IsTrue(sub.first()); Assert.IsTrue(sub.eof()); Assert.IsTrue(sub is EmptyTreeIterator); }
private AbstractTreeIterator FastMin() { _fastMinHasMatch = true; int i = 0; AbstractTreeIterator minRef = Trees[i]; while (minRef.eof() && ++i < Trees.Length) { minRef = Trees[i]; } if (minRef.eof()) { return(minRef); } minRef.Matches = minRef; while (++i < Trees.Length) { AbstractTreeIterator t = Trees[i]; if (t.eof()) { continue; } int cmp = t.pathCompare(minRef); if (cmp < 0) { if (_fastMinHasMatch && IsTree(minRef) && !IsTree(t) && NameEqual(minRef, t)) { // We used to be at a tree, but now we are at a file // with the same name. Allow the file to match the // tree anyway. // t.Matches = minRef; } else { _fastMinHasMatch = false; t.Matches = t; minRef = t; } } else if (cmp == 0) { // Exact name/mode match is best. // t.Matches = minRef; } else if (_fastMinHasMatch && IsTree(t) && !IsTree(minRef) && NameEqual(t, minRef)) { // The minimum is a file (non-tree) but the next entry // of this iterator is a tree whose name matches our file. // This is a classic D/F conflict and commonly occurs like // this, with no gaps in between the file and directory. // // Use the tree as the minimum instead (see CombineDF). // for (int k = 0; k < i; k++) { AbstractTreeIterator p = Trees[k]; if (p.Matches == minRef) { p.Matches = t; } } t.Matches = t; minRef = t; } else { _fastMinHasMatch = false; } } return(minRef); }