@@ -3687,6 +3687,12 @@ assert(de2.name == "/usr/share/include");
3687
3687
+/
3688
3688
@property string name() const return scope ;
3689
3689
3690
+ /+ +
3691
+ Returns the path to the file represented by this `DirEntry`.
3692
+
3693
+ Unlike `name`, this property returns the internal name as-is,
3694
+ potentially starting with an unexpected prefix.
3695
+ +/
3690
3696
@property string nameWithPrefix() const return scope ;
3691
3697
3692
3698
/+ +
@@ -3881,6 +3887,11 @@ else version (Windows)
3881
3887
return _name;
3882
3888
}
3883
3889
3890
+ private @property string namePrefix() const pure nothrow return scope
3891
+ {
3892
+ return _namePrefix;
3893
+ }
3894
+
3884
3895
@property bool isDir() const pure nothrow scope
3885
3896
{
3886
3897
return (attributes & FILE_ATTRIBUTE_DIRECTORY ) != 0 ;
@@ -4013,6 +4024,11 @@ else version (Posix)
4013
4024
return _name;
4014
4025
}
4015
4026
4027
+ private @property string namePrefix() const pure nothrow return scope
4028
+ {
4029
+ return _namePrefix;
4030
+ }
4031
+
4016
4032
@property bool isDir() scope
4017
4033
{
4018
4034
_ensureStatOrLStatDone();
@@ -4675,7 +4691,7 @@ private struct DirIteratorImpl
4675
4691
DirEntry _cur;
4676
4692
DirHandle[] _stack;
4677
4693
DirEntry [] _stashed; // used in depth first mode
4678
- string _pathPrefix = null ;
4694
+ string _namePrefix = null ;
4679
4695
4680
4696
// stack helpers
4681
4697
void pushExtra (DirEntry de)
@@ -4733,7 +4749,6 @@ private struct DirIteratorImpl
4733
4749
bool toNext (bool fetch, scope WIN32_FIND_DATAW * findinfo) @trusted
4734
4750
{
4735
4751
import core.stdc.wchar_ : wcscmp;
4736
- import std.string : chompPrefix;
4737
4752
4738
4753
if (fetch)
4739
4754
{
@@ -4750,7 +4765,7 @@ private struct DirIteratorImpl
4750
4765
popDirStack();
4751
4766
return false ;
4752
4767
}
4753
- _cur = DirEntry (_stack[$- 1 ].dirpath.chompPrefix(_pathPrefix) , findinfo);
4768
+ _cur = DirEntry (_stack[$- 1 ].dirpath, findinfo, _namePrefix );
4754
4769
return true ;
4755
4770
}
4756
4771
@@ -4795,8 +4810,6 @@ private struct DirIteratorImpl
4795
4810
4796
4811
bool next () @trusted
4797
4812
{
4798
- import std.string : chompPrefix;
4799
-
4800
4813
if (_stack.length == 0 )
4801
4814
return false ;
4802
4815
@@ -4806,7 +4819,7 @@ private struct DirIteratorImpl
4806
4819
if (core.stdc.string.strcmp (&fdata.d_name[0 ], " ." ) &&
4807
4820
core.stdc.string.strcmp (&fdata.d_name[0 ], " .." ))
4808
4821
{
4809
- _cur = DirEntry (_stack[$- 1 ].dirpath.chompPrefix(_pathPrefix) , fdata);
4822
+ _cur = DirEntry (_stack[$- 1 ].dirpath, fdata, _namePrefix );
4810
4823
return true ;
4811
4824
}
4812
4825
}
@@ -4848,7 +4861,7 @@ private struct DirIteratorImpl
4848
4861
pathname = pathname.absolutePath;
4849
4862
4850
4863
const offset = pathnameAbs.length - pathnameRel.length;
4851
- _pathPrefix = pathnameAbs[0 .. offset];
4864
+ _namePrefix = pathnameAbs[0 .. offset];
4852
4865
}
4853
4866
4854
4867
if (stepIn(pathname))
@@ -4857,7 +4870,7 @@ private struct DirIteratorImpl
4857
4870
while (mayStepIn())
4858
4871
{
4859
4872
auto thisDir = _cur;
4860
- if (stepIn(_cur.name ))
4873
+ if (stepIn(_cur.nameWithPrefix ))
4861
4874
{
4862
4875
pushExtra(thisDir);
4863
4876
}
@@ -4887,7 +4900,7 @@ private struct DirIteratorImpl
4887
4900
while (mayStepIn())
4888
4901
{
4889
4902
auto thisDir = _cur;
4890
- if (stepIn(_cur.name ))
4903
+ if (stepIn(_cur.nameWithPrefix ))
4891
4904
{
4892
4905
pushExtra(thisDir);
4893
4906
}
@@ -4901,7 +4914,7 @@ private struct DirIteratorImpl
4901
4914
case SpanMode.breadth:
4902
4915
if (mayStepIn())
4903
4916
{
4904
- if (! stepIn(_cur.name ))
4917
+ if (! stepIn(_cur.nameWithPrefix ))
4905
4918
while (! empty && ! next()){}
4906
4919
}
4907
4920
else
0 commit comments