Skip to content

Commit

Permalink
Fix case-insensitive finding of LICENSE.*.TXT (bsc#1215698)
Browse files Browse the repository at this point in the history
Ruby 3.1 drops the formerly working FNM_CASEFOLD for `Dir.glob`
but it keeps working for `File.fnmatch?`
  • Loading branch information
mvidner committed Oct 3, 2023
1 parent c443e4d commit d2ff5d7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/packages/src/lib/y2packager/licenses_fetchers/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def locales
begin
unpack_archive

license_files = Dir.glob(File.join(archive_dir, "**", "LICENSE.*.TXT"), File::FNM_CASEFOLD)
license_files = find_case_insensitive(archive_dir, "LICENSE.*.TXT")
# NOTE: despite the use of the case-insensitive flag, the captured group will be
# returned as it is.
languages = license_files.map { |path| path[/LICENSE.(\w*).TXT/i, 1] }
Expand Down Expand Up @@ -160,7 +160,15 @@ def fallback_path(directory)
#
# @return [String, nil] The file path; nil if was not found
def find_path_for(directory, file)
Dir.glob(File.join(directory, "**", file), File::FNM_CASEFOLD).first
find_case_insensitive(directory, file).first
end

# TODO: doc, test
def find_case_insensitive(directory, fileglob)
files = Dir.glob(File.join(directory, "**", "*"))
files.find_all do |fn|
File.fnmatch?(File.join(directory, "**", fileglob), fn, File::FNM_CASEFOLD)
end
end
end
end
Expand Down

0 comments on commit d2ff5d7

Please sign in to comment.