File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed
Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -194,8 +194,12 @@ bs_rb_scan_dir(VALUE self, VALUE abspath)
194194 struct stat st ;
195195 int dfd = -1 ;
196196
197- errno = 0 ;
198- while ((entry = readdir (dirp ))) {
197+ while (1 ) {
198+ errno = 0 ;
199+
200+ entry = readdir (dirp );
201+ if (entry == NULL ) break ;
202+
199203 if (entry -> d_name [0 ] == '.' ) continue ;
200204
201205 if (RB_UNLIKELY (entry -> d_type == DT_UNKNOWN || entry -> d_type == DT_LNK )) {
@@ -212,11 +216,8 @@ bs_rb_scan_dir(VALUE self, VALUE abspath)
212216 }
213217
214218 if (fstatat (dfd , entry -> d_name , & st , 0 )) {
215- if (errno == ENOENT ) {
216- // Broken symlinK
217- errno = 0 ;
218- continue ;
219- }
219+ if (errno == ENOENT ) continue ; // Broken symlink
220+
220221 int err = errno ;
221222 closedir (dirp );
222223 bs_syserr_fail_dir_entry ("fstatat" , err , abspath , entry -> d_name );
@@ -249,10 +250,15 @@ bs_rb_scan_dir(VALUE self, VALUE abspath)
249250 }
250251 }
251252
252- if (closedir (dirp )) {
253+ if (errno ) {
254+ int err = errno ;
255+ closedir (dirp );
256+ bs_syserr_fail_path ("readdir" , err , abspath );
257+ } else if (closedir (dirp )) {
253258 bs_syserr_fail_path ("closedir" , errno , abspath );
254259 return Qundef ;
255260 }
261+
256262 return result ;
257263}
258264#endif
You can’t perform that action at this time.
0 commit comments