Lintian::Util(3)

✨ NAME ✨

okay so bestie, welcome to Lintian::Util(3), the manual page from the Debian Package Checker family πŸ’–. And the actual name line? It's literally:

Lintian::Util β€” Lintian utility functions

that's it, that's the whole vibe. πŸŽ€


🌸 SYNOPSIS 🌸

use Lintian::Util;

πŸ¦‹ DESCRIPTION πŸ¦‹

So this module is basically the group chat of utility subs β€” the ones that are genuinely nice to have around, but that lowkey did not warrant their own whole entire module. They live here. Together. Slaying. πŸ’…

And heads up: most of these subs are imported only on request. They don't just show up uninvited, ok? iykyk. ✨


πŸ’œ VARIABLES πŸ’œ

  • $PKGNAME_REGEX β€” the regex that matches valid package names 🫢. It is not anchored, and it does not enforce any "boundary" characters. So it's giving "match in the middle if you want", fr fr.
  • $PKGREPACK_REGEX β€” the regex that matches "repacked" package names πŸ“¦. Also not anchored, also doesn't enforce "boundary" characters. And important: it should only be applied to the upstream portion (see #931846). no cap.
  • $PKGVERSION_REGEX β€” the regex that matches valid package versions 🌈. Not anchored, no "boundary" characters enforced either. consistent queen.

πŸ”₯ FUNCTIONS πŸ”₯

🧚 drain_pipe(FD)

Reads and discards whatever's still chillin' in FD, which is assumed to be a pipe. Why tho? Mostly so the "write"-end doesn't literally die from a SIGPIPE because of a "broken pipe" πŸ’€ (which is exactly what can happen if you just close the pipe and dip).

May cause an exception if there are issues reading from the pipe. πŸ™ˆ
CAVEAT: this will block until the pipe is closed from the "write"-end, so only use it with pipes where the "write"-end will eventually close their end by themselves (or something else will make them close it). don't get stuck bestie, that's not the move. 😭

πŸ“ get_file_digest(ALGO, FILE)

Creates an ALGO digest object that is seeded with the contents of FILE. But if all you want is the hex digest, please go use get_file_checksum(ALGO, FILE) instead, ok? use the right tool for the right job, that's the energy. ✨

ALGO can be 'md5' or shaX, where X is any number supported by Digest::SHA (e.g. 'sha256'). πŸ”

This sub is a convenience wrapper around Digest::{MD5,SHA}. cozy.

πŸ’– get_file_checksum(ALGO, FILE)

Returns a hexadecimal string of the message digest checksum that algorithm ALGO generated on FILE. 🧾

ALGO can be 'md5' or shaX, where X is any number supported by Digest::SHA (e.g. 'sha256'). πŸ”

Also a convenience wrapper around Digest::{MD5,SHA}. twins! πŸ‘‘

πŸ‘‘ perm2oct(PERM)

Translates PERM into an octal permission. PERM should be a string describing the permissions the way tar t or ls -l does it β€” like, a string like "-rw-r--r--". πŸ’…

If the string does not appear to be a valid permission, it will cause a trappable error. catch it or cry about it, your call πŸ™ˆ

Examples:

# Good
perm2oct('-rw-r--r--') == oct(644)
perm2oct('-rwxr-xr-x') == oct(755)

# Bad
perm2oct('broken')      # too short to be recognised
perm2oct('-resurunet')  # contains unknown permissions

see? good ones eat, bad ones get yelled at. ⭐

🌷 human_bytes(SIZE)

the manpage gives this one nothing but its name, bestie β€” so that's all I've got too. it's here. it exists. iconic behaviour honestly. 🫢

🌷 locate_executable (CMD)

again, just the signature on the page and no description. we love a mysterious queen. πŸŽ€

🌷 drop_relative_prefix(STRING)

Remove an initial ./ from STRING, if present. that's it, that's the whole job, and it does it flawlessly. slay. βœ‚οΈ

🌷 version_from_changelog

no description in the original, just the name sitting there looking cute. 🌸

πŸ¦‹ match_glob( $glob, @things_to_test )

Resembles the same semantic as Text::Glob's match_glob(), but with the proper escaping of Regexp::Wildcards and pre-configured for Lintian's purpose 🎯. And bonus: no more directly having to access module variables either. we love not touching globals. periodt. ✨

🌈 normalize_pkg_path(PATH)

Normalizes PATH by removing superfluous path segments. PATH is assumed to be relative to the package root πŸ“¦. And note: the result will never start nor end with a slash, even if PATH does. no slashes allowed, they're not on the guest list πŸ’…

As the name suggests, this is a path "normalization" rather than a true path resolution β€” for that, use Cwd::realpath. Particularly, it assumes none of the path segments are symlinks. πŸš«πŸ”—

normalize_pkg_path will return "q{}" (i.e. the empty string) if PATH is normalized to the root dir, and "undef" if the path cannot be normalized without escaping the package root. πŸƒβ€β™€οΈπŸ’¨

Normalizes the path you get by following a link with LINK_TARGET as its target, from CURDIR as the current directory. CURDIR is assumed to be relative to the package root. And same deal as before: the result will never start nor end with a slash, even if CURDIR or DEST does. ✨

normalize_pkg_path will return "q{}" (i.e. the empty string) if the target is the root dir, and "undef" if the path cannot be normalized without escaping the package root.

CAVEAT: this function is not always sufficient to test if it's safe to open a given symlink 😭. Use is_ancestor_of(PARENTDIR, PATH) for that. And if you must use this function, remember to check that the target is not a symlink β€” or if it is, that it can be resolved safely. pls pls pls be careful bestie, this is the serious part 🚨

πŸ’€ is_ancestor_of(PARENTDIR, PATH)

Returns true if and only if PATH is PARENTDIR or a path stored somewhere within PARENTDIR (or its subdirs). 🧬

This function will resolve the paths; any failure to resolve the path will cause a trappable error. πŸ™ˆ

🌷 read_md5sums

signature only, no description, keeping it mysterious. πŸŽ€

🌷 unescape_md5sum_filename

also just the name. no notes. πŸ’œ

🌷 utf8_clean_log

name only again, we respect the mystery ✨

🌷 utf8_clean_bytes

and this one too β€” the original page lists it and says nothing else, so I'm not about to make stuff up. fact-checked. 🫢


🌟 SEE ALSO 🌟

  • lintian(1) β€” go read the main character's page too, obviously πŸ‘‘

and that's the whole page, no crumbs left πŸ’– this was Lintian v2.139.0ubuntu2, dated 2026-10-08 β€” thanks for coming to my TED talk, mwah, stay normalized bestie πŸ’‹βœ¨πŸŽ€

πŸ“¦ where this page comes from