View file File name : ap-pkg-diversions.html Content : <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" /> <title>7. Diversions - overriding a package’s version of a file (from old Packaging Manual) — Debian Policy Manual v4.6.0.1</title> <link rel="stylesheet" type="text/css" href="_static/pygments.css" /> <link rel="stylesheet" type="text/css" href="_static/nature.css" /> <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script> <script src="_static/jquery.js"></script> <script src="_static/underscore.js"></script> <script src="_static/doctools.js"></script> <link rel="index" title="Index" href="genindex.html" /> <link rel="search" title="Search" href="search.html" /> <link rel="next" title="8. Debian Policy changes process" href="ap-process.html" /> <link rel="prev" title="6. Alternative versions of an interface - update-alternatives (from old Packaging Manual)" href="ap-pkg-alternatives.html" /> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="ap-process.html" title="8. Debian Policy changes process" accesskey="N">next</a> |</li> <li class="right" > <a href="ap-pkg-alternatives.html" title="6. Alternative versions of an interface - update-alternatives (from old Packaging Manual)" accesskey="P">previous</a> |</li> <li class="nav-item nav-item-0"><a href="index.html">Debian Policy Manual v4.6.0.1</a> »</li> <li class="nav-item nav-item-this"><a href=""><span class="section-number">7. </span>Diversions - overriding a package’s version of a file (from old Packaging Manual)</a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <section id="diversions-overriding-a-package-s-version-of-a-file-from-old-packaging-manual"> <h1><span class="section-number">7. </span>Diversions - overriding a package’s version of a file (from old Packaging Manual)<a class="headerlink" href="#diversions-overriding-a-package-s-version-of-a-file-from-old-packaging-manual" title="Permalink to this headline">¶</a></h1> <p>It is possible to have <code class="docutils literal notranslate"><span class="pre">dpkg</span></code> not overwrite a file when it reinstalls the package it belongs to, and to have it put the file from the package somewhere else instead.</p> <p>This can be used locally to override a package’s version of a file, or by one package to override another’s version (or provide a wrapper for it).</p> <p>Before deciding to use a diversion, read <a class="reference internal" href="ap-pkg-alternatives.html"><span class="doc">Alternative versions of an interface - update-alternatives (from old Packaging Manual)</span></a> to see if you really want a diversion rather than several alternative versions of a program.</p> <p>There is a diversion list, which is read by <code class="docutils literal notranslate"><span class="pre">dpkg</span></code>, and updated by a special program <code class="docutils literal notranslate"><span class="pre">dpkg-divert</span></code>. Please see <em class="manpage">dpkg-divert(8)</em> for full details of its operation.</p> <p>When a package wishes to divert a file from another, it should call <code class="docutils literal notranslate"><span class="pre">dpkg-divert</span></code> in its preinst to add the diversion and rename the existing file. For example, supposing that a <code class="docutils literal notranslate"><span class="pre">smailwrapper</span></code> package wishes to install a wrapper around <code class="docutils literal notranslate"><span class="pre">/usr/sbin/smail</span></code>:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">dpkg</span><span class="o">-</span><span class="n">divert</span> <span class="o">--</span><span class="n">package</span> <span class="n">smailwrapper</span> <span class="o">--</span><span class="n">add</span> <span class="o">--</span><span class="n">rename</span> \ <span class="o">--</span><span class="n">divert</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">sbin</span><span class="o">/</span><span class="n">smail</span><span class="o">.</span><span class="n">real</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">sbin</span><span class="o">/</span><span class="n">smail</span> </pre></div> </div> <p>The <code class="docutils literal notranslate"><span class="pre">--package</span> <span class="pre">smailwrapper</span></code> ensures that <code class="docutils literal notranslate"><span class="pre">smailwrapper</span></code>’s copy of <code class="docutils literal notranslate"><span class="pre">/usr/sbin/smail</span></code> can bypass the diversion and get installed as the true version. It’s safe to add the diversion unconditionally on upgrades since it will be left unchanged if it already exists, but <code class="docutils literal notranslate"><span class="pre">dpkg-divert</span></code> will display a message. To suppress that message, make the command conditional on the version from which the package is being upgraded:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>if [ upgrade != "$1 ] || dpkg --compare-versions "$2" lt 1.0-2; then dpkg-divert --package smailwrapper --add --rename \ --divert /usr/sbin/smail.real /usr/sbin/smail fi </pre></div> </div> <p>where <code class="docutils literal notranslate"><span class="pre">1.0-2</span></code> is the version at which the diversion was first added to the package. Running the command during abort-upgrade is pointless but harmless.</p> <p>The postrm has to do the reverse:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">[</span> <span class="n">remove</span> <span class="o">=</span> <span class="s2">"$1"</span> <span class="o">-</span><span class="n">o</span> <span class="n">abort</span><span class="o">-</span><span class="n">install</span> <span class="o">=</span> <span class="s2">"$1"</span> <span class="o">-</span><span class="n">o</span> <span class="n">disappear</span> <span class="o">=</span> <span class="s2">"$1 ]; then</span> <span class="n">dpkg</span><span class="o">-</span><span class="n">divert</span> <span class="o">--</span><span class="n">package</span> <span class="n">smailwrapper</span> <span class="o">--</span><span class="n">remove</span> <span class="o">--</span><span class="n">rename</span> \ <span class="o">--</span><span class="n">divert</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">sbin</span><span class="o">/</span><span class="n">smail</span><span class="o">.</span><span class="n">real</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">sbin</span><span class="o">/</span><span class="n">smail</span> <span class="n">fi</span> </pre></div> </div> <p>If the diversion was added at a particular version, the postrm should also handle the failure case of upgrading from an older version (unless the older version is so old that direct upgrades are no longer supported):</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>if [ abort-upgrade = "$1 ] && dpkg --compare-versions "$2" lt 1.0-2; then dpkg-divert --package smailwrapper --remove --rename \ --divert /usr/sbin/smail.real /usr/sbin/smail fi </pre></div> </div> <p>where <code class="docutils literal notranslate"><span class="pre">1.0-2</span></code> is the version at which the diversion was first added to the package. The postrm should not remove the diversion on upgrades both because there’s no reason to remove the diversion only to immediately re-add it and since the postrm of the old package is run after unpacking so the removal of the diversion will fail.</p> <p>Do not attempt to divert a file which is vitally important for the system’s operation - when using <code class="docutils literal notranslate"><span class="pre">dpkg-divert</span></code> there is a time, after it has been diverted but before <code class="docutils literal notranslate"><span class="pre">dpkg</span></code> has installed the new version, when the file does not exist.</p> <p>Do not attempt to divert a conffile, as <code class="docutils literal notranslate"><span class="pre">dpkg</span></code> does not handle it well.</p> </section> <div class="clearer"></div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h4>Previous topic</h4> <p class="topless"><a href="ap-pkg-alternatives.html" title="previous chapter"><span class="section-number">6. </span>Alternative versions of an interface - <code class="docutils literal notranslate"><span class="pre">update-alternatives</span></code> (from old Packaging Manual)</a></p> <h4>Next topic</h4> <p class="topless"><a href="ap-process.html" title="next chapter"><span class="section-number">8. </span>Debian Policy changes process</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/ap-pkg-diversions.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3 id="searchlabel">Quick search</h3> <div class="searchformwrapper"> <form class="search" action="search.html" method="get"> <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> <input type="submit" value="Go" /> </form> </div> </div> <script>$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="ap-process.html" title="8. Debian Policy changes process" >next</a> |</li> <li class="right" > <a href="ap-pkg-alternatives.html" title="6. Alternative versions of an interface - update-alternatives (from old Packaging Manual)" >previous</a> |</li> <li class="nav-item nav-item-0"><a href="index.html">Debian Policy Manual v4.6.0.1</a> »</li> <li class="nav-item nav-item-this"><a href=""><span class="section-number">7. </span>Diversions - overriding a package’s version of a file (from old Packaging Manual)</a></li> </ul> </div> <div class="footer" role="contentinfo"> Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.2.0. </div> </body> </html>