Dpkg::Path(3perl) libdpkg-perl Dpkg::Path(3perl)

# [NAME](#NAME)

Dpkg::Path - some common path handling functions

# [DESCRIPTION](#DESCRIPTION)

It provides some functions to handle various path.

# [FUNCTIONS](#FUNCTIONS)

$pathname = get\_pkg\_root\_dir($file)

This function will scan upwards the hierarchy of directory to find out the directory which contains the "DEBIAN" sub-directory and it will return its path. This directory is the root directory of a package being built.

If no DEBIAN subdirectory is found, it will return undef.

$pathname = relative\_to\_pkg\_root($file)

Returns the filename relative to get\_pkg\_root\_dir($file).

$pathname = guess\_pkg\_root\_dir($file)

This function tries to guess the root directory of the package build tree. It will first use **get\_pkg\_root\_dir()**, but it will fallback to a more imprecise check: namely it will use the parent directory that is a sub-directory of the debian directory.

It can still return undef if a file outside of the debian sub-directory is provided.

$bool = check\_files\_are\_the\_same($file1, $file2, $resolve\_symlink)

This function verifies that both files are the same by checking that the device numbers and the inode numbers returned by **stat()**/**lstat()** are the same. If $resolve\_symlink is true then **stat()** is used, otherwise **lstat()** is used.

$pathname = canonpath($file)

This function returns a cleaned path. It simplifies double //, and remove /./ and /../ intelligently. For /../ it simplifies the path only if the previous element is not a symlink. Thus it should only be used on real filenames.

$pathname = resolve\_symlink($symlink)

Return the filename of the file pointed by the symlink. The new name is canonicalized by **canonpath()**.

[check\_directory\_traversal($basedir, $dir)](#check_directory_traversal%28$basedir,)

This function verifies that the directory $dir does not contain any symlink that goes beyond $basedir (which should be either equal or a parent of $dir).

$pathname = find\_command($command)

Return the path of the command if defined and available on an absolute or relative path or on the $PATH, undef otherwise.

$pathname = get\_control\_path($pkg, $filetype)

Return the path of the control file of type $filetype for the given package.

@pathname\_list = get\_control\_path($pkg)

Return the path of all available control files for the given package.

$file = find\_build\_file($basename)

Selects the right variant of the given file: the arch-specific variant ("$basename.$arch") has priority over the OS-specific variant ("$basename.$os") which has priority over the default variant ("$basename"). If none of the files exists, then it returns undef.

@files = find\_build\_file($basename)

Return the available variants of the given file. Returns an empty list if none of the files exists.

# [CHANGES](#CHANGES)

## [Version 1.05 (dpkg 1.20.4)](#Version_1.05_%28dpkg_1.20.4%29)

New function: **check\_directory\_traversal()**.

## [Version 1.04 (dpkg 1.17.11)](#Version_1.04_%28dpkg_1.17.11%29)

Update semantics: **find\_command()** now handles an empty or undef argument.

## [Version 1.03 (dpkg 1.16.1)](#Version_1.03_%28dpkg_1.16.1%29)

New function: **find\_build\_file()**

## [Version 1.02 (dpkg 1.16.0)](#Version_1.02_%28dpkg_1.16.0%29)

New function: **get\_control\_path()**

## [Version 1.01 (dpkg 1.15.8)](#Version_1.01_%28dpkg_1.15.8%29)

New function: **find\_command()**

## [Version 1.00 (dpkg 1.15.6)](#Version_1.00_%28dpkg_1.15.6%29)

Mark the module as public.

2026-09-09 1.23.11-dirty

---

Document: Dpkg::Path(3perl) from dpkg 1.23.11-r1 (Chainguard OS)
Source: https://git.dpkg.org/git/dpkg/dpkg.git
