linux - Why does glob lstat matching entries? -
looking behavior in this question, surprised see perl lstat()s every path matching glob pattern:
$ mkdir dir $ touch dir/{foo,bar,baz}.txt $ strace -e trace=lstat perl -e 'say $^v; <dir/b*>' v5.10.1 lstat("dir/baz.txt", {st_mode=s_ifreg|0664, st_size=0, ...}) = 0 lstat("dir/bar.txt", {st_mode=s_ifreg|0664, st_size=0, ...}) = 0 i see same behavior on linux system glob(pattern) , <pattern>, , later versions of perl.
my expectation globbing opendir/readdir under hood, , not need inspect actual pathnames searching.
what purpose of lstat? affect glob()s return?
this strange behavior has been noticed before on perlmonks. turns out glob calls lstat support glob_mark flag, has effect that:
each pathname directory matches pattern has slash appended.
to find out whether directory entry refers subdir, need stat it. apparently done when flag not given.
Comments
Post a Comment