@@ -112,7 +112,7 @@ def __init__(self, pattern, flags=0, curdir=None):
112112
113113 self .is_bytes = isinstance (pattern [0 ], bytes )
114114 self .current = b'.' if self .is_bytes else '.'
115- self .curdir = curdir
115+ self .curdir = curdir if curdir is not None else self . current
116116 self .mark = bool (flags & MARK )
117117 if self .mark :
118118 flags ^= MARK
@@ -228,7 +228,7 @@ def _get_matcher(self, target):
228228 def _iter (self , curdir , dir_only , deep ):
229229 """Iterate the directory."""
230230
231- scandir = self .current if not curdir else curdir
231+ scandir = self .curdir if not curdir else curdir
232232
233233 # Python will never return . or .., so fake it.
234234 for special in self .specials :
@@ -381,7 +381,7 @@ def _glob(self, curdir, this, rest):
381381 else :
382382 yield path , is_dir
383383
384- def _get_starting_paths (self , curdir , dir_only ):
384+ def _get_starting_paths (self , curdir , dir_only , base ):
385385 """
386386 Get the starting location.
387387
@@ -394,14 +394,19 @@ def _get_starting_paths(self, curdir, dir_only):
394394 results = [(curdir , True )]
395395
396396 if not self ._is_parent (curdir ) and not self ._is_this (curdir ):
397- fullpath = os .path .abspath (curdir )
397+ fullpath = os .path .abspath (os . path . join ( base , curdir ) )
398398 basename = os .path .basename (fullpath )
399399 dirname = os .path .dirname (fullpath )
400400 if basename :
401401 matcher = self ._get_matcher (basename )
402- results = [
403- (os .path .basename (name ), is_dir ) for name , is_dir in self ._glob_dir (dirname , matcher , dir_only )
404- ]
402+ if base not in ('.' , b'.' ):
403+ results = [
404+ (name , is_dir ) for name , is_dir in self ._glob_dir (dirname , matcher , dir_only )
405+ ]
406+ else :
407+ results = [
408+ (os .path .basename (name ), is_dir ) for name , is_dir in self ._glob_dir (dirname , matcher , dir_only )
409+ ]
405410
406411 return results
407412
@@ -414,9 +419,10 @@ def glob(self):
414419 """Starts off the glob iterator."""
415420
416421 if self .is_bytes :
417- curdir = os . fsencode ( os . curdir ) if self . curdir is None else self .curdir
422+ curdir = self .curdir
418423 else :
419- curdir = os .curdir if self .curdir is None else self .curdir
424+ curdir = self .curdir
425+ base = curdir
420426
421427 for pattern in self .pattern :
422428 # If the pattern ends with `/` we return the files ending with `/`.
@@ -431,13 +437,13 @@ def glob(self):
431437 curdir = this [0 ]
432438
433439 # Abort if we cannot find the drive, or if current directory is empty
434- if not curdir or (this .is_drive and not os .path .lexists (curdir )):
440+ if not curdir or (this .is_drive and not os .path .lexists (os . path . join ( base , curdir ) )):
435441 continue
436442
437443 # Make sure case matches, but running case insensitive
438444 # on a case sensitive file system may return more than
439445 # one starting location.
440- results = [(curdir , True )] if this .is_drive else self ._get_starting_paths (curdir , dir_only )
446+ results = [(curdir , True )] if this .is_drive else self ._get_starting_paths (curdir , dir_only , base )
441447 if not results :
442448 continue
443449
0 commit comments