.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Lintian::Util 3" .TH Lintian::Util 3 "2017-06-03" "Lintian v2.5.50.4" "Debian Package Checker" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Lintian::Util \- Lintian utility functions .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Lintian::Util qw(slurp_entire_file normalize_pkg_path); \& \& my $text = slurp_entire_file(\*(Aqsome\-file\*(Aq); \& if ($text =~ m/regex/) { \& # ... \& } \& \& my $path = normalize_pkg_path(\*(Aqusr/bin/\*(Aq, \*(Aq../lib/git\-core/git\-pull\*(Aq); \& if (defined $path) { \& # ... \& } \& \& my (@paragraphs); \& eval { @paragraphs = read_dpkg_control_utf8(\*(Aqsome/debian/ctrl/file\*(Aq); }; \& if ($@) { \& # syntax error etc. \& die "ctrl/file: $@"; \& } \& \& foreach my $para (@paragraphs) { \& my $value = $para\->{\*(Aqsome\-field\*(Aq}; \& if (defined $value) { \& # ... \& } \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module contains a number of utility subs that are nice to have, but on their own did not warrant their own module. .PP Most subs are imported only on request. .SS "Debian control parsers" .IX Subsection "Debian control parsers" At first glance, this module appears to contain several debian control parsers. In practise, there is only one real parser (\*(L"visit_dpkg_paragraph\*(R") \- the rest are convenience functions around it. .PP If you have very large files (e.g. Packages_amd64), you almost certainly want \*(L"visit_dpkg_paragraph\*(R". Otherwise, one of the convenience functions are probably what you are looking for. .ie n .IP "Use ""get_deb_info"" when" 4 .el .IP "Use ``get_deb_info'' when" 4 .IX Item "Use get_deb_info when" You have a \fI.deb\fR (or \fI.udeb\fR) file and you want the control file from it. .ie n .IP "Use ""get_dsc_info"" when" 4 .el .IP "Use ``get_dsc_info'' when" 4 .IX Item "Use get_dsc_info when" You have a \fI.dsc\fR (or \fI.changes\fR) file. Alternative, it is also useful if you have a control file and only care about the first paragraph. .ie n .IP "Use ""read_dpkg_control_utf8"" or ""read_dpkg_control"" when" 4 .el .IP "Use ``read_dpkg_control_utf8'' or ``read_dpkg_control'' when" 4 .IX Item "Use read_dpkg_control_utf8 or read_dpkg_control when" You have a debian control file (such \fIdebian/control\fR) and you want a number of paragraphs from it. .ie n .IP "Use ""parse_dpkg_control"" when" 4 .el .IP "Use ``parse_dpkg_control'' when" 4 .IX Item "Use parse_dpkg_control when" When you would have used \*(L"read_dpkg_control_utf8\*(R", except you have an open filehandle rather than a file name. .SH "CONSTANTS" .IX Header "CONSTANTS" The following constants can be passed to the Debian control file parser functions to alter their parsing flag. .IP "\s-1DCTRL_DEBCONF_TEMPLATE\s0" 4 .IX Item "DCTRL_DEBCONF_TEMPLATE" The file should be parsed as debconf template. These have slightly syntax rules for whitespace in some cases. .IP "\s-1DCTRL_NO_COMMENTS\s0" 4 .IX Item "DCTRL_NO_COMMENTS" The file do not allow comments. With this flag, any comment in the file is considered a syntax error. .SH "VARIABLES" .IX Header "VARIABLES" .ie n .IP "$PKGNAME_REGEX" 4 .el .IP "\f(CW$PKGNAME_REGEX\fR" 4 .IX Item "$PKGNAME_REGEX" Regular expression that matches valid package names. The expression is not anchored and does not enforce any \*(L"boundary\*(R" characters. .ie n .IP "$PKGVERSION_REGEX" 4 .el .IP "\f(CW$PKGVERSION_REGEX\fR" 4 .IX Item "$PKGVERSION_REGEX" Regular expression that matches valid package versions. The expression is not anchored and does not enforce any \*(L"boundary\*(R" characters. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .IP "parse_dpkg_control(HANDLE[, FLAGS[, \s-1LINES\s0]])" 4 .IX Item "parse_dpkg_control(HANDLE[, FLAGS[, LINES]])" Reads a debian control file from \s-1HANDLE\s0 and returns a list of paragraphs in it. A paragraph is represented via a hashref, which maps (lower cased) field names to their values. .Sp \&\s-1FLAGS \s0(if given) is a bitmask of the \fIDCTRL_*\fR constants. Please refer to \*(L"\s-1CONSTANTS\*(R"\s0 for the list of constants and their meaning. The default value for \s-1FLAGS\s0 is 0. .Sp If \s-1LINES\s0 is given, it should be a reference to an empty list. On return, \s-1LINES\s0 will be populated with a hashref for each paragraph (in the same order as the returned list). Each hashref will also have a special key "\fISTART-OF-PARAGRAPH\fR" that gives the line number of the first field in that paragraph. These hashrefs will map the field name of the given paragraph to the line number where the field name appeared. .Sp This is a convenience sub around \*(L"visit_dpkg_paragraph\*(R" and can therefore produce the same errors as it. Please see \&\*(L"visit_dpkg_paragraph\*(R" for the finer semantics of how the control file is parsed. .Sp \&\s-1NB:\s0 parse_dpkg_control does \fInot\fR close the handle for the caller. .IP "visit_dpkg_paragraph (\s-1CODE,\s0 HANDLE[, \s-1FLAGS\s0])" 4 .IX Item "visit_dpkg_paragraph (CODE, HANDLE[, FLAGS])" Reads a debian control file from \s-1HANDLE\s0 and passes each paragraph to \&\s-1CODE. A\s0 paragraph is represented via a hashref, which maps (lower cased) field names to their values. .Sp \&\s-1FLAGS \s0(if given) is a bitmask of the \fIDCTRL_*\fR constants. Please refer to \*(L"\s-1CONSTANTS\*(R"\s0 for the list of constants and their meaning. The default value for \s-1FLAGS\s0 is 0. .Sp If the file is empty (i.e. it contains no paragraphs), the method will contain an \fIempty\fR list. The deb822 contents may be inside a \&\fIsigned\fR \s-1PGP\s0 message with a signature. .Sp visit_dpkg_paragraph will require the \s-1PGP\s0 headers to be correct (if present) and require that the entire file is covered by the signature. However, it will \fInot\fR validate the signature (in fact, the contents of the \s-1PGP SIGNATURE\s0 part can be empty). The signature should be validated separately. .Sp visit_dpkg_paragraph will pass paragraphs to \s-1CODE\s0 as they are completed. If \s-1CODE\s0 can process the paragraphs as they are seen, very large control files can be processed without keeping all the paragraphs in memory. .Sp As a consequence of how the file is parsed, \s-1CODE\s0 may be passed a number of (valid) paragraphs before parsing is stopped due to a syntax error. .Sp \&\s-1NB:\s0 visit_dpkg_paragraph does \fInot\fR close the handle for the caller. .Sp \&\s-1CODE\s0 is expected to be a callable reference (e.g. a sub) and will be invoked as the following: .RS 4 .IP "\s-1CODE\-\s0>(\s-1PARA, LINE_NUMBERS\s0)" 4 .IX Item "CODE->(PARA, LINE_NUMBERS)" The first argument, \s-1PARA,\s0 is a hashref to the most recent paragraph parsed. The second argument, \s-1LINE_NUMBERS,\s0 is a hashref mapping each of the field names to the line number where the field name appeared. \&\s-1LINE_NUMBERS\s0 will also have a special key "\fISTART-OF-PARAGRAPH\fR" that gives the line number of the first field in that paragraph. .Sp The return value of \s-1CODE\s0 is ignored. .Sp If the \s-1CODE\s0 invokes die (or similar) the error is propagated to the caller. .RE .RS 4 .Sp \&\fIOn syntax errors\fR, visit_dpkg_paragraph will call die with the following string: .Sp .Vb 1 \& "syntax error at line %d: %s\en" .Ve .Sp Where \f(CW%d\fR is the line number of the issue and \f(CW%s\fR is one of: .ie n .IP "Duplicate field %s" 4 .el .IP "Duplicate field \f(CW%s\fR" 4 .IX Item "Duplicate field %s" The field appeared twice in the paragraph. .ie n .IP "Continuation line outside a paragraph (maybe line %d should be "" ."")" 4 .el .IP "Continuation line outside a paragraph (maybe line \f(CW%d\fR should be `` .'')" 4 .IX Item "Continuation line outside a paragraph (maybe line %d should be .)" A continuation line appears outside a paragraph \- usually caused by an unintended empty line before it. .ie n .IP "Whitespace line not allowed (possibly missing a ""."")" 4 .el .IP "Whitespace line not allowed (possibly missing a ``.'')" 4 .IX Item "Whitespace line not allowed (possibly missing a .)" An empty continuation line was found. This usually means that a period is missing to denote an \*(L"empty line\*(R" in (e.g.) the long description of a package. .ie n .IP "Cannot parse line ""%s""" 4 .el .IP "Cannot parse line ``%s''" 4 .IX Item "Cannot parse line %s" Generic error containing the text of the line that confused the parser. Note that all non-printables in \f(CW%s\fR will be replaced by underscores. .IP "Comments are not allowed" 4 .IX Item "Comments are not allowed" A comment line appeared and \s-1FLAGS\s0 contained \s-1DCTRL_NO_COMMENTS.\s0 .IP "\s-1PGP\s0 signature seen before start of signed message" 4 .IX Item "PGP signature seen before start of signed message" A \*(L"\s-1BEGIN PGP SIGNATURE\*(R"\s0 header is seen and a \*(L"\s-1BEGIN PGP MESSAGE\*(R"\s0 has not been seen yet. .ie n .IP "Two \s-1PGP\s0 signatures (first one at line %d)" 4 .el .IP "Two \s-1PGP\s0 signatures (first one at line \f(CW%d\fR)" 4 .IX Item "Two PGP signatures (first one at line %d)" Two \*(L"\s-1BEGIN PGP SIGNATURE\*(R"\s0 headers are seen in the same file. .ie n .IP "Unexpected %s header" 4 .el .IP "Unexpected \f(CW%s\fR header" 4 .IX Item "Unexpected %s header" A valid \s-1PGP\s0 header appears (e.g. \*(L"\s-1BEGIN PUBLIC KEY BLOCK\*(R"\s0). .IP "Malformed \s-1PGP\s0 header" 4 .IX Item "Malformed PGP header" An invalid or malformed \s-1PGP\s0 header appears. .ie n .IP "Expected at most one signed message (previous at line %d)" 4 .el .IP "Expected at most one signed message (previous at line \f(CW%d\fR)" 4 .IX Item "Expected at most one signed message (previous at line %d)" Two \*(L"\s-1BEGIN PGP MESSAGE\*(R"\s0 headers appears in the same message. .ie n .IP "End of file but expected an ""\s-1END PGP SIGNATURE""\s0 header" 4 .el .IP "End of file but expected an ``\s-1END PGP SIGNATURE''\s0 header" 4 .IX Item "End of file but expected an END PGP SIGNATURE header" The file ended after a \*(L"\s-1BEGIN PGP SIGNATURE\*(R"\s0 header without being followed by an \*(L"\s-1END PGP SIGNATURE\*(R".\s0 .IP "\s-1PGP MESSAGE\s0 header must be first content if present" 4 .IX Item "PGP MESSAGE header must be first content if present" The file had content before \s-1PGP MESSAGE.\s0 .IP "Data after the \s-1PGP SIGNATURE\s0" 4 .IX Item "Data after the PGP SIGNATURE" The file had data after the \s-1PGP SIGNATURE\s0 block ended. .ie n .IP "End of file before ""\s-1BEGIN PGP SIGNATURE""\s0" 4 .el .IP "End of file before ``\s-1BEGIN PGP SIGNATURE''\s0" 4 .IX Item "End of file before BEGIN PGP SIGNATURE" The file had a \*(L"\s-1BEGIN PGP MESSAGE\*(R"\s0 header, but no signature was present. .RE .RS 4 .RE .IP "read_dpkg_control_utf8(FILE[, FLAGS[, \s-1LINES\s0]])" 4 .IX Item "read_dpkg_control_utf8(FILE[, FLAGS[, LINES]])" .PD 0 .IP "read_dpkg_control(FILE[, FLAGS[, \s-1LINES\s0]])" 4 .IX Item "read_dpkg_control(FILE[, FLAGS[, LINES]])" .PD This is a convenience function to ease using \*(L"parse_dpkg_control\*(R" with paths to files (rather than open handles). The first argument must be the path to a \s-1FILE,\s0 which should be read as a debian control file. If the file is empty, an empty list is returned. .Sp Otherwise, this behaves like: .Sp .Vb 1 \& use autodie; \& \& open(my $fd, \*(Aq<:encoding(UTF\-8)\*(Aq, FILE); # or \*(Aq<\*(Aq \& my @p = parse_dpkg_control($fd, FLAGS, LINES); \& close($fd); \& return @p; .Ve .Sp This goes without saying that may fail with any of the messages that \&\*(L"parse_dpkg_control(HANDLE[, FLAGS[, \s-1LINES\s0]])\*(R" do. It can also emit autodie exceptions if open or close fails. .IP "\fIdpkg_deb_has_ctrl_tarfile()\fR" 4 .IX Item "dpkg_deb_has_ctrl_tarfile()" Check if lintian could use dpkg-deb instead of ar and tar .IP "get_deb_info(\s-1DEBFILE\s0)" 4 .IX Item "get_deb_info(DEBFILE)" Extracts the control file from \s-1DEBFILE\s0 and returns it as a hashref. .Sp Basically, this is a fancy convenience for setting up an ar + tar pipe and passing said pipe to \*(L"parse_dpkg_control(HANDLE[, FLAGS[, \s-1LINES\s0]])\*(R". .Sp \&\s-1DEBFILE\s0 must be an ar file containing a \*(L"control.tar.gz\*(R" member, which in turn should contain a \*(L"control\*(R" file. If the \*(L"control\*(R" file is empty this will return an empty list. .Sp Note: the control file is only expected to have a single paragraph and thus only the first is returned (in the unlikely case that there are more than one). .Sp This function may fail with any of the messages that \&\*(L"parse_dpkg_control\*(R" do. It can also emit: .Sp .Vb 1 \& "cannot fork to unpack %s: %s\en" .Ve .IP "get_dsc_control (\s-1DSCFILE\s0)" 4 .IX Item "get_dsc_control (DSCFILE)" Convenience function for reading dsc files. It will read the \s-1DSCFILE\s0 using \*(L"read_dpkg_control(FILE[, FLAGS[, \s-1LINES\s0]])\*(R" and then return the first paragraph. If the file has no paragraphs, \f(CW\*(C`undef\*(C'\fR is returned instead. .Sp Note: the control file is only expected to have a single paragraph and thus only the first is returned (in the unlikely case that there are more than one). .Sp This function may fail with any of the messages that \&\*(L"read_dpkg_control(FILE[, FLAGS[, \s-1LINES\s0]])\*(R" do. .IP "slurp_entire_file (FOH[, \s-1NOCLOSE\s0])" 4 .IX Item "slurp_entire_file (FOH[, NOCLOSE])" Reads the contents of \s-1FOH\s0 into memory and return it as a scalar. \s-1FOH\s0 can be either the path to a file or an open file handle. .Sp If it is a handle, the optional \s-1NOCLOSE\s0 parameter can be used to prevent the sub from closing the handle. The \s-1NOCLOSE\s0 parameter has no effect if \s-1FOH\s0 is not a handle. .IP "drain_pipe(\s-1FD\s0)" 4 .IX Item "drain_pipe(FD)" Reads and discards any remaining contents from \s-1FD,\s0 which is assumed to be a pipe. This is mostly done to avoid having the \*(L"write\*(R"\-end die with a \s-1SIGPIPE\s0 due to a \*(L"broken pipe\*(R" (which can happen if you just close the pipe). .Sp May cause an exception if there are issues reading from the pipe. .Sp Caveat: This will block until the pipe is closed from the \*(L"write\*(R"\-end, so only use it with pipes where the \*(L"write\*(R"\-end will eventually close their end by themselves (or something else will make them close it). .IP "get_file_digest(\s-1ALGO, FILE\s0)" 4 .IX Item "get_file_digest(ALGO, FILE)" Creates an \s-1ALGO\s0 digest object that is seeded with the contents of \&\s-1FILE. \s0 If you just want the hex digest, please use \&\*(L"get_file_checksum(\s-1ALGO, FILE\s0)\*(R" instead. .Sp \&\s-1ALGO\s0 can be 'md5' or shaX, where X is any number supported by Digest::SHA (e.g. 'sha256'). .Sp This sub is a convenience wrapper around Digest::{\s-1MD5,SHA\s0}. .IP "get_file_checksum(\s-1ALGO, FILE\s0)" 4 .IX Item "get_file_checksum(ALGO, FILE)" Returns a hexadecimal string of the message digest checksum generated by the algorithm \s-1ALGO\s0 on \s-1FILE.\s0 .Sp \&\s-1ALGO\s0 can be 'md5' or shaX, where X is any number supported by Digest::SHA (e.g. 'sha256'). .Sp This sub is a convenience wrapper around Digest::{\s-1MD5,SHA\s0}. .IP "is_string_utf8_encoded(\s-1STRING\s0)" 4 .IX Item "is_string_utf8_encoded(STRING)" Returns a truth value if \s-1STRING\s0 can be decoded as valid \s-1UTF\-8.\s0 .IP "file_is_encoded_in_non_utf8 (...)" 4 .IX Item "file_is_encoded_in_non_utf8 (...)" Undocumented .IP "\fIdo_fork()\fR" 4 .IX Item "do_fork()" Overrides fork to reset signal handlers etc. in the child. .IP "system_env (\s-1CMD\s0)" 4 .IX Item "system_env (CMD)" Behaves like system (\s-1CMD\s0) except that the environment of \s-1CMD\s0 is cleaned (as defined by \*(L"clean_env\*(R"(1)). .IP "clean_env ([\s-1CLOC\s0])" 4 .IX Item "clean_env ([CLOC])" Destructively cleans \f(CW%ENV\fR \- removes all variables \f(CW%ENV\fR except a selected few whitelisted variables. .Sp The list of whitelisted \f(CW%ENV\fR variables are: .Sp .Vb 3 \& PATH \& LC_ALL (*) \& TMPDIR .Ve .Sp (*) \s-1LC_ALL\s0 is a special case as clean_env will change its value to either \*(L"C.UTF\-8\*(R" or \*(L"C\*(R" (if \s-1CLOC\s0 is given and a truth value). .IP "perm2oct(\s-1PERM\s0)" 4 .IX Item "perm2oct(PERM)" Translates \s-1PERM\s0 to an octal permission. \s-1PERM\s0 should be a string describing the permissions as done by \fItar t\fR or \fIls \-l\fR. That is, it should be a string like \*(L"\-rw\-r\*(--r\-\-\*(R". .Sp If the string does not appear to be a valid permission, it will cause a trappable error. .Sp Examples: .Sp .Vb 3 \& # Good \& perm2oct(\*(Aq\-rw\-r\-\-r\-\-\*(Aq) == 0644 \& perm2oct(\*(Aq\-rwxr\-xr\-x\*(Aq) == 0755 \& \& # Bad \& perm2oct(\*(Aqbroken\*(Aq) # too short to be recognised \& perm2oct(\*(Aq\-resurunet\*(Aq) # contains unknown permissions .Ve .IP "delete_dir (\s-1ARGS\s0)" 4 .IX Item "delete_dir (ARGS)" Convenient way of calling \fIrm \-fr \s-1ARGS\s0\fR. .IP "copy_dir (\s-1ARGS\s0)" 4 .IX Item "copy_dir (ARGS)" Convenient way of calling \fIcp \-a \s-1ARGS\s0\fR. .IP "gunzip_file (\s-1IN, OUT\s0)" 4 .IX Item "gunzip_file (IN, OUT)" Decompresses contents of the file \s-1IN\s0 and stores the contents in the file \s-1OUT. IN\s0 is \fInot\fR removed by this call. On error, this function will cause a trappable error. .IP "open_gz (\s-1FILE\s0)" 4 .IX Item "open_gz (FILE)" Opens a handle that reads from the GZip compressed \s-1FILE.\s0 .Sp On failure, this sub emits a trappable error. .Sp Note: The handle may be a pipe from an external processes. .IP "touch_file(\s-1FILE\s0)" 4 .IX Item "touch_file(FILE)" Updates the \*(L"mtime\*(R" of \s-1FILE. \s0 If \s-1FILE\s0 does not exist, it will be created. .Sp On failure, this sub will emit a trappable error. .IP "fail (MSG[, ...])" 4 .IX Item "fail (MSG[, ...])" Use to signal an internal error. The argument(s) will used to print a diagnostic message to the user. .Sp If multiple arguments are given, they will be merged into a single string (by join (' ', \f(CW@_\fR)). If only one argument is given it will be stringified and used directly. .IP "locate_helper_tool(\s-1TOOLNAME\s0)" 4 .IX Item "locate_helper_tool(TOOLNAME)" Given the name of a helper tool, returns the path to it. The tool must be available in the \*(L"helpers\*(R" subdir of one of the \*(L"lintian root\*(R" directories used by Lintian. .Sp The tool name should follow the same rules as check names. Particularly, third-party checks should namespace their tools in the same way they namespace their checks. E.g. \*(L"python/some\-helper\*(R". .Sp If the tool cannot be found, this sub will cause a trappable error. .IP "strip ([\s-1LINE\s0])" 4 .IX Item "strip ([LINE])" Strips whitespace from the beginning and the end of \s-1LINE\s0 and returns it. If \s-1LINE\s0 is omitted, \f(CW$_\fR will be used instead. Example .Sp .Vb 1 \& @lines = map { strip } <$fd>; .Ve .Sp In void context, the input argument will be modified so it can be used as a replacement for chomp in some cases: .Sp .Vb 4 \& while ( my $line = <$fd> ) { \& strip ($line); \& # $line no longer has any leading or trailing whitespace \& } .Ve .Sp Otherwise, a copy of the string is returned: .Sp .Vb 6 \& while ( my $orig = <$fd> ) { \& my $stripped = strip ($orig); \& if ($stripped ne $orig) { \& # $orig had leading or/and trailing whitespace \& } \& } .Ve .IP "lstrip ([\s-1LINE\s0])" 4 .IX Item "lstrip ([LINE])" Like strip but only strip leading whitespace. .IP "rstrip ([\s-1LINE\s0])" 4 .IX Item "rstrip ([LINE])" Like strip but only strip trailing whitespace. .IP "check_path (\s-1CMD\s0)" 4 .IX Item "check_path (CMD)" Returns 1 if \s-1CMD\s0 can be found in \s-1PATH \s0(i.e. \f(CW$ENV\fR{\s-1PATH\s0}) and is executable. Otherwise, the function return 0. .IP "dequote_name(\s-1STR, REMOVESLASH\s0)" 4 .IX Item "dequote_name(STR, REMOVESLASH)" Strip an extra layer quoting in index file names and optionally remove an initial \*(L"./\*(R" if any. .Sp Remove initial ./ by default .IP "signal_number2name(\s-1NUM\s0)" 4 .IX Item "signal_number2name(NUM)" Given a number, returns the name of the signal (without leading \&\*(L"\s-1SIG\*(R"\s0). Example: .Sp .Vb 1 \& signal_number2name(2) eq \*(AqINT\*(Aq .Ve .IP "normalize_pkg_path(\s-1PATH\s0)" 4 .IX Item "normalize_pkg_path(PATH)" Normalize \s-1PATH\s0 by removing superfluous path segments. \s-1PATH\s0 is assumed to be relative the package root. Note that the result will never start nor end with a slash, even if \s-1PATH\s0 does. .Sp As the name suggests, this is a path \*(L"normalization\*(R" rather than a true path resolution (for that use Cwd::realpath). Particularly, it assumes none of the path segments are symlinks. .Sp normalize_pkg_path will return \f(CW\*(C`q{}\*(C'\fR (i.e. the empty string) if \s-1PATH\s0 is normalized to the root dir and \f(CW\*(C`undef\*(C'\fR if the path cannot be normalized without escaping the package root. .Sp Examples: normalize_pkg_path('usr/share/java/../../../usr/share/ant/file') eq 'usr/share/ant/file' normalize_pkg_path('usr/..') eq q{}; .Sp .Vb 2 \& The following will return C: \& normalize_pkg_path(\*(Aqusr/bin/../../../../etc/passwd\*(Aq) .Ve .IP "normalize_pkg_path(\s-1CURDIR, LINK_TARGET\s0)" 4 .IX Item "normalize_pkg_path(CURDIR, LINK_TARGET)" Normalize the path obtained by following a link with \s-1LINK_TARGET\s0 as its target from \s-1CURDIR\s0 as the current directory. \s-1CURDIR\s0 is assumed to be relative to the package root. Note that the result will never start nor end with a slash, even if \s-1CURDIR\s0 or \s-1DEST\s0 does. .Sp normalize_pkg_path will return \f(CW\*(C`q{}\*(C'\fR (i.e. the empty string) if the target is the root dir and \f(CW\*(C`undef\*(C'\fR if the path cannot be normalized without escaping the package root. .Sp \&\fB\s-1CAVEAT\s0\fR: This function is \fInot always sufficient\fR to test if it is safe to open a given symlink. Use is_ancestor_of for that. 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). .Sp Examples: .Sp .Vb 6 \& normalize_pkg_path(\*(Aqusr/share/java\*(Aq, \*(Aq../ant/file\*(Aq) eq \*(Aqusr/share/ant/file\*(Aq \& normalize_pkg_path(\*(Aqusr/share/java\*(Aq, \*(Aq../../../usr/share/ant/file\*(Aq) \& normalize_pkg_path(\*(Aqusr/share/java\*(Aq, \*(Aq/usr/share/ant/file\*(Aq) \& eq \*(Aqusr/share/ant/file\*(Aq \& normalize_pkg_path(\*(Aq/usr/share/java\*(Aq, \*(Aq/\*(Aq) eq q{}; \& normalize_pkg_path(\*(Aq/\*(Aq, \*(Aqusr/..\*(Aq) eq q{}; \& \& The following will return C: \& normalize_pkg_path(\*(Aqusr/bin\*(Aq, \*(Aq../../../../etc/passwd\*(Aq) \& normalize_pkg_path(\*(Aqusr/bin\*(Aq, \*(Aq/../etc/passwd\*(Aq) .Ve .IP "parse_boolean (\s-1STR\s0)" 4 .IX Item "parse_boolean (STR)" Attempt to parse \s-1STR\s0 as a boolean and return its value. If \s-1STR\s0 is not a valid/recognised boolean, the sub will invoke croak. .Sp The following values recognised (string checks are not case sensitive): .RS 4 .IP "The integer 0 is considered false" 4 .IX Item "The integer 0 is considered false" .PD 0 .IP "Any non-zero integer is considered true" 4 .IX Item "Any non-zero integer is considered true" .ie n .IP """true"", ""y"" and ""yes"" are considered true" 4 .el .IP "``true'', ``y'' and ``yes'' are considered true" 4 .IX Item "true, y and yes are considered true" .ie n .IP """false"", ""n"" and ""no"" are considered false" 4 .el .IP "``false'', ``n'' and ``no'' are considered false" 4 .IX Item "false, n and no are considered false" .RE .RS 4 .RE .IP "is_ancestor_of(\s-1PARENTDIR, PATH\s0)" 4 .IX Item "is_ancestor_of(PARENTDIR, PATH)" .PD Returns true if and only if \s-1PATH\s0 is \s-1PARENTDIR\s0 or a path stored somewhere within \s-1PARENTDIR \s0(or its subdirs). .Sp This function will resolve the paths; any failure to resolve the path will cause a trappable error. .IP "unix_locale_split(\s-1STR\s0)" 4 .IX Item "unix_locale_split(STR)" Read \s-1STR\s0 as a locale code (e.g. en_GB.UTF\-8) and return a list of locale codes ordered by preference. As an example, en_GB.UTF\-8 might return .Sp .Vb 2 \& en_GB \& en .Ve .Sp Note encoding \fIis ignored\fR as all Lintian files are always encoded in \&\s-1UTF\-8.\s0 .Sp \&\fBSpecial cases\fR: The \*(L"C\*(R" or \*(L"\s-1POSIX\*(R"\s0 locale returns the empty list. Other strings that do not match the expected format causes a trappable error. .IP "pipe_tee(\s-1INHANDLE,\s0 OUTHANDLES[, \s-1OPTS\s0])" 4 .IX Item "pipe_tee(INHANDLE, OUTHANDLES[, OPTS])" Read bytes from \s-1INHANDLE\s0 and copy them into all of the handles in the listref \s-1OUTHANDLES.\s0 The optional \s-1OPTS\s0 argument is a hashref of options, see below. .Sp The subroutine will continue to read from \s-1INHANDLE\s0 until it is exhausted or an error occurs (either during read or write). In case of errors, a trappable error will be raised. The handles are left open when the subroutine returns, caller must close them afterwards. .Sp Caller should ensure that handles are using \*(L"blocking\*(R" I/O. The subroutine will use sysread and syswrite when reading and writing. .Sp \&\s-1OPTS,\s0 if given, may contain the following key-value pairs: .RS 4 .IP "chunk_size" 4 .IX Item "chunk_size" A suggested buffer size for read/write. If given, it will be to sysread as \s-1LENGTH\s0 argument when reading from \s-1INHANDLE.\s0 .RE .RS 4 .RE .IP "load_state_cache(\s-1STATE_DIR\s0)" 4 .IX Item "load_state_cache(STATE_DIR)" [Reporting tools only] Load the state cache from \s-1STATE_DIR.\s0 .IP "save_state_cache(\s-1STATE_DIR, STATE\s0)" 4 .IX Item "save_state_cache(STATE_DIR, STATE)" [Reporting tools only] Save the \s-1STATE\s0 cache to \s-1STATE_DIR.\s0 .IP "find_backlog(\s-1LINTIAN_VERSION, STATE\s0)" 4 .IX Item "find_backlog(LINTIAN_VERSION, STATE)" [Reporting tools only] Given the current lintian version and the harness state, return a list of group ids that are part of the backlog. The list is sorted based on what version of Lintian processed the package. .Sp Note the result is by design not deterministic to reduce the risk of all large packages being in the same run (e.g. like gcc\-5 + gcc\-5\-cross + gcc\-6 + gcc\-6\-cross). .IP "untaint(\s-1VALUE\s0)" 4 .IX Item "untaint(VALUE)" Untaint \s-1VALUE\s0 .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fIlintian\fR\|(1)