@@ -2137,56 +2137,57 @@ iterator tryWalkDir*(dir: string; relative=false): WalkStep {.
21372137 else :
21382138 lastIter = true
21392139 res = sGetError (wsInterrupted, dir)
2140- when defined (nimNoArrayToCstringConversion):
2141- var y = $ cstring (addr x.d_name)
21422140 else :
2143- var y = $ x.d_name.cstring
2144- if y == " ." or y == " .." :
2145- yieldAllowed = false
2146- else :
2147- var s: Stat
2148- let path = dir / y
2149- if not relative:
2150- y = path
2151- var k = pcFile
2152-
2153- var use_lstat = false
2154- when defined (linux) or defined (macosx) or
2155- defined (bsd) or defined (genode) or defined (nintendoswitch):
2156- if x.d_type != DT_UNKNOWN :
2157- if x.d_type == DT_DIR :
2158- k = pcDir
2159- res = sNoErrors (k, y)
2160- elif x.d_type == DT_LNK :
2161- errno = 0
2162- if dirExists (path): k = pcLinkToDir
2163- else : k = pcLinkToFile
2164- if errno == 0 : # check error in dirExists
2141+ when defined (nimNoArrayToCstringConversion):
2142+ var y = $ cstring (addr x.d_name)
2143+ else :
2144+ var y = $ x.d_name.cstring
2145+ if y == " ." or y == " .." :
2146+ yieldAllowed = false
2147+ else :
2148+ var s: Stat
2149+ let path = dir / y
2150+ if not relative:
2151+ y = path
2152+ var k = pcFile
2153+
2154+ var use_lstat = false
2155+ when defined (linux) or defined (macosx) or
2156+ defined (bsd) or defined (genode) or defined (nintendoswitch):
2157+ if x.d_type != DT_UNKNOWN :
2158+ if x.d_type == DT_DIR :
2159+ k = pcDir
21652160 res = sNoErrors (k, y)
2161+ elif x.d_type == DT_LNK :
2162+ errno = 0
2163+ if dirExists (path): k = pcLinkToDir
2164+ else : k = pcLinkToFile
2165+ if errno == 0 : # check error in dirExists
2166+ res = sNoErrors (k, y)
2167+ else :
2168+ res = sGetError (wsEntryBad, y)
21662169 else :
2167- res = sGetError (wsEntryBad, y)
2170+ res = sNoErrors (k, y)
2171+ use_lstat = false
21682172 else :
2169- res = sNoErrors (k, y)
2170- use_lstat = false
2173+ use_lstat = true
21712174 else :
21722175 use_lstat = true
2173- else :
2174- use_lstat = true
2175- if use_lstat:
2176- # special case of DT_UNKNOWN: some filesystems can't detect that
2177- # entry is a directory and keep its d_type as 0=DT_UNKNOWN
2178- if lstat (path, s) < 0 'i32 :
2179- res = sGetError (wsEntryBad, y)
2180- else :
2181- errno = 0
2182- if S_ISDIR (s.st_mode):
2183- k = pcDir
2184- elif S_ISLNK (s.st_mode):
2185- k = getSymlinkFileKind (path)
2186- if errno == 0 : # check error in getSymlinkFileKind
2187- res = sNoErrors (k, y)
2188- else :
2176+ if use_lstat:
2177+ # special case of DT_UNKNOWN: some filesystems can't detect that
2178+ # entry is a directory and keep its d_type as 0=DT_UNKNOWN
2179+ if lstat (path, s) < 0 'i32 :
21892180 res = sGetError (wsEntryBad, y)
2181+ else :
2182+ errno = 0
2183+ if S_ISDIR (s.st_mode):
2184+ k = pcDir
2185+ elif S_ISLNK (s.st_mode):
2186+ k = getSymlinkFileKind (path)
2187+ if errno == 0 : # check error in getSymlinkFileKind
2188+ res = sNoErrors (k, y)
2189+ else :
2190+ res = sGetError (wsEntryBad, y)
21902191 if yieldAllowed: yield res
21912192
21922193proc tryOpenDir * (dir: string ): OpenDirStatus {.
0 commit comments