[yast-devel] Globbing in Shell and in Ruby
Hi, I was debugging a random build failure of the yast2 package in OBS [1] and I'd like to share my findings. You can use `ls *.foo` in shell or `Dir.glob("*.foo")` in Ruby to get the files matching the glob pattern. However, there is a tiny but in some cases a crucial difference!
From "man bash":
bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern The Ruby implementation does not do any sorting so `ls *.foo | head -n 1` is not the same as `Dir.glob("*.foo").first` !! (The same implementation would be `Dir.glob("*.foo").sort.first`.) The Ruby result depends on the low level system state (file system, disk fragmentation, etc.), the order is not guaranteed. That's why the test randomly failed. The code has been fixed in [2]. [1] https://github.com/yast/yast-yast2/issues/895 [2] https://github.com/yast/yast-yast2/pull/897 -- Best Regards Ladislav Slezák Yast Developer ------------------------------------------------------------------------ SUSE LINUX, s.r.o. e-mail: lslezak@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Prague 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On 2/18/19 8:40 AM, Ladislav Slezak wrote:
Hi,
I was debugging a random build failure of the yast2 package in OBS [1] and I'd like to share my findings.
You can use `ls *.foo` in shell or `Dir.glob("*.foo")` in Ruby to get the files matching the glob pattern. However, there is a tiny but in some cases a crucial difference!
From "man bash":
bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern
The Ruby implementation does not do any sorting so `ls *.foo | head -n 1` is not the same as `Dir.glob("*.foo").first` !! (The same implementation would be `Dir.glob("*.foo").sort.first`.)
Good catch! Thanks for sharing.
The Ruby result depends on the low level system state (file system, disk fragmentation, etc.), the order is not guaranteed. That's why the test randomly failed.
The code has been fixed in [2].
[1] https://github.com/yast/yast-yast2/issues/895 [2] https://github.com/yast/yast-yast2/pull/897
--
Best Regards
Ladislav Slezák Yast Developer ------------------------------------------------------------------------ SUSE LINUX, s.r.o. e-mail: lslezak@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Prague 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/
-- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
participants (2)
-
José Iván López González
-
Ladislav Slezak