Skip to content

Commit

Permalink
Merge pull request #1292 from yast/broken-casefold
Browse files Browse the repository at this point in the history
Fix case-insensitive finding of LICENSE.*.TXT (bsc#1215698)
  • Loading branch information
mvidner authored Oct 6, 2023
2 parents c443e4d + e3b678e commit e5c76d7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
22 changes: 16 additions & 6 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 @@ -155,12 +155,22 @@ def fallback_path(directory)

# Return the path for the given file in specified directory
#
# @param directory [String] Directory where licenses were unpacked
# @param file [String] File name (without directory component)
#
# @param (see #find_case_insensitive)
# @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
def find_path_for(directory, fileglob)
find_case_insensitive(directory, fileglob).first
end

# Return paths for the given file glob in specified directory
#
# @param directory [String] Directory, whole subtree is searched
# @param fileglob [String] File name, with glob characters like `*` `{a,b}`, case insensitive
# @return [Array<String>] All found file paths
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 | File::FNM_EXTGLOB)
end
end
end
end
Expand Down
Binary file modified library/packages/test/data/rpm/licenses_test.tar.gz
Binary file not shown.
6 changes: 6 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Oct 5 08:50:25 UTC 2023 - Martin Vidner <mvidner@suse.com>

- Fix case-insensitive finding of LICENSE.*.TXT (bsc#1215698)
- 5.0.1

-------------------------------------------------------------------
Wed Aug 30 20:16:10 UTC 2023 - Josef Reidinger <jreidinger@suse.cz>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 5.0.0
Version: 5.0.1

Release: 0
Summary: YaST2 Main Package
Expand Down

0 comments on commit e5c76d7

Please sign in to comment.