Debian Bug report logs - #204363
"cleanlinks" removes non-dangling symlinks to directories

Package: xutils-dev; Maintainer for xutils-dev is Debian X Strike Force <debian-x@lists.debian.org>; Source for xutils-dev is src:xutils-dev.

Reported by: Florian Ernst <florian@uni-hd.de>

Date: Wed, 6 Aug 2003 18:03:01 UTC

Severity: important

Tags: patch, upstream

Forwarded to https://bugs.freedesktop.org/show_bug.cgi?id=10019

Reply or subscribe to this bug.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Branden Robinson <branden@debian.org>:
Bug#204363; Package xutils. Full text and rfc822 format available.

Acknowledgement sent to Florian Ernst <florian@uni-hd.de>:
New Bug report received and forwarded. Copy sent to Branden Robinson <branden@debian.org>. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Florian Ernst <florian@uni-hd.de>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: "cleanlinks" removes non-dangling symlinks to directories
Date: Wed, 6 Aug 2003 19:56:00 +0200
Package: xutils
Version: 4.2.1-6
Severity: normal
Tags: upstream patch

According to its manpage "cleanlinks" does only remove dangling 
symlinks and empty directories, so I'd expect it not to remove a 
symlink to an existing unempty directory. But:

fernst@live:~/test$ ls -Al
total 0
lrwxrwxrwx    1 fernst   fernst          5 2003-08-06 18:22 home ->
/home/
lrwxrwxrwx    1 fernst   fernst         21 2003-08-06 18:22 .xinitrc 
-> /home/fernst/.xinitrc*
fernst@live:~/test$ cleanlinks
./home is a dangling symlink, removing
Removing empty directories ...
fernst@live:~/test$ ls -Al
total 0
lrwxrwxrwx    1 fernst   fernst         21 2003-08-06 18:22 .xinitrc 
-> /home/fernst/.xinitrc*


It appears the "cleanlinks"-script only checks for the symlinks-target
"file" but not for "directory", so the following patch could fix it:

--- /usr/bin/X11/cleanlinks.old  2003-02-26 01:52:11.000000000 +0100
+++ /usr/bin/X11/cleanlinks  2003-08-06 18:40:30.000000000 +0200
@@ -13,7 +13,7 @@
 (
        read i
        while [ X"$i" != X ]; do
-               if [ ! -f "$i" ]; then
+               if [ ! \( -f "$i" -o -d "$i" \) ]; then
                        echo $i is a dangling symlink, removing
                        rm -f "$i"
                fi


After applying this patch:

fernst@live:~/test$ ls -Al
total 0
lrwxrwxrwx    1 fernst   fernst          5 2003-08-06 18:40 home -> 
/home/
lrwxrwxrwx    1 fernst   fernst         21 2003-08-06 18:22 .xinitrc 
-> /home/fernst/.xinitrc*
fernst@live:~/test$ cleanlinks
Removing empty directories ...
fernst@live:~/test$ ls -Al
total 0
lrwxrwxrwx    1 fernst   fernst          5 2003-08-06 18:40 home -> 
/home/
lrwxrwxrwx    1 fernst   fernst         21 2003-08-06 18:22 .xinitrc 
-> /home/fernst/.xinitrc*


Cheers,
Flo


-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux live 2.4.21-live-preempt-oly #2 Mon Jun 30 18:03:16 CEST 
2003 i686
Locale: LANG=de_DE@euro, LC_CTYPE=de_DE@euro

Versions of packages xutils depends on:
ii  libc6                     2.3.1-16       GNU C Library: Shared 
libraries an
ii  libncurses5               5.3.20030719-1 Shared libraries for 
terminal hand
ii  xfree86-common            4.2.1-6        X Window System (XFree86) 
infrastr
ii  zlib1g                    1:1.1.4-14     compression library - 
runtime

-- no debconf information




Information forwarded to debian-bugs-dist@lists.debian.org, Branden Robinson <branden@debian.org>:
Bug#204363; Package xutils. Full text and rfc822 format available.

Acknowledgement sent to Colin Watson <cjwatson@debian.org>:
Extra info received and forwarded to list. Copy sent to Branden Robinson <branden@debian.org>. Full text and rfc822 format available.

Message #10 received at 204363@bugs.debian.org (full text, mbox):

From: Colin Watson <cjwatson@debian.org>
To: Florian Ernst <florian@uni-hd.de>, 204363@bugs.debian.org
Subject: Re: Bug#204363: "cleanlinks" removes non-dangling symlinks to directories
Date: Fri, 8 Aug 2003 04:53:20 -0500
On Wed, Aug 06, 2003 at 07:56:00PM +0200, Florian Ernst wrote:
> It appears the "cleanlinks"-script only checks for the symlinks-target
> "file" but not for "directory", so the following patch could fix it:
> 
> --- /usr/bin/X11/cleanlinks.old  2003-02-26 01:52:11.000000000 +0100
> +++ /usr/bin/X11/cleanlinks  2003-08-06 18:40:30.000000000 +0200
> @@ -13,7 +13,7 @@
>  (
>         read i
>         while [ X"$i" != X ]; do
> -               if [ ! -f "$i" ]; then
> +               if [ ! \( -f "$i" -o -d "$i" \) ]; then
>                         echo $i is a dangling symlink, removing
>                         rm -f "$i"
>                 fi

A slightly more portable version would be better, I think (using
parenthesis-grouping in [] is a bit dodgy):

-               if [ ! -f "$i" ]; then
+               if ! ([ -f "$i" ] || [ -d "$i" ]); then

This still seems incomplete, though. What if it's a symlink to a device
node? We could simply do this instead to test whether the symlink is
truly dangling:

-               if [ ! -f "$i" ]; then
+               if [ ! -e "$i" ]; then

XFree86 might not be able to do this if they want to run on Solaris,
whose /bin/sh doesn't understand test -e, but it's fine on any POSIX
system. Somebody might want to make sure that other shells return the
same result from test -e on a dangling symlink, but my reading of
http://www.opengroup.org/onlinepubs/007904975/utilities/test.html is
that any shell that doesn't is buggy.

Cheers,

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Information forwarded to debian-bugs-dist@lists.debian.org, Debian X Strike Force <debian-x@lists.debian.org>:
Bug#204363; Package xutils. Full text and rfc822 format available.

Acknowledgement sent to Sam Watkins <swatkins@fastmail.fm>:
Extra info received and forwarded to list. Copy sent to Debian X Strike Force <debian-x@lists.debian.org>. Full text and rfc822 format available.

Message #15 received at 204363@bugs.debian.org (full text, mbox):

From: Sam Watkins <swatkins@fastmail.fm>
To: debian-user@lists.debian.org
Cc: 204363@bugs.debian.org
Subject: Re: cleanlinks breaks xterm and apt
Date: Tue, 25 Jan 2005 23:06:11 +1100
On Mon, Jan 24, 2005 at 11:24:47PM +0100, Florian Ernst wrote
(on debain-user):
> cleanlinks is dangerous, it wasn't never meant for general system
> maintenance and doesn't work as advertised in its manpage.

Rather than fixing cleanlinks to work better, which is apparently not
happening, the manpage at least should be corrected to warn of this bug
in big flashing red letters.  (cleanlinks deletes all symlinks to
anything that isn't a regular file, e.g. symlinks to directories)



Information forwarded to debian-bugs-dist@lists.debian.org, Debian X Strike Force <debian-x@lists.debian.org>:
Bug#204363; Package xutils. Full text and rfc822 format available.

Acknowledgement sent to Siward de Groot <siward@wanadoo.nl>:
Extra info received and forwarded to list. Copy sent to Debian X Strike Force <debian-x@lists.debian.org>. Full text and rfc822 format available.

Message #20 received at 204363@bugs.debian.org (full text, mbox):

From: Siward de Groot <siward@wanadoo.nl>
To: debian-user@lists.debian.org, 204363@bugs.debian.org
Subject: [patch] Re: Bug#204363: cleanlinks breaks xterm and apt
Date: Sun, 30 Jan 2005 13:39:21 +0100
[Message part 1 (text/plain, inline)]
On Tuesday 25 January 2005 13:06, Sam Watkins wrote:
| On Mon, Jan 24, 2005 at 11:24:47PM +0100, Florian Ernst wrote
|
| (on debain-user):
| > cleanlinks is dangerous, it wasn't never meant for general system
| > maintenance and doesn't work as advertised in its manpage.
|
| Rather than fixing cleanlinks to work better, which is apparently not
| happening, the manpage at least should be corrected to warn of this bug
| in big flashing red letters.  (cleanlinks deletes all symlinks to
| anything that isn't a regular file, e.g. symlinks to directories)

Attached is a patch for the manpage.

Also attached are 2 Perl scripts that do
   remove dangling symlinks and empty directories.
They seem to work, but are not systematically tested.

Cleanlinks is in xc/util because it is a utility that is used by X, i think.
When i 'grep -n -d recurse /my/source/X/xfree86-4.3.0.dfsg.1`,
  i do not see it being called anywhere,
  but then how can it break xterm ?
Maybe this is because i 'apt-get source'd sarge and not testing ?

have fun !

  Siward de Groot
  <http://home.wanadoo.nl/siward>
[cleanlinks.patch (text/x-diff, attachment)]
[rmdanglinks (application/x-perl, attachment)]
[rmemptydirs (application/x-perl, attachment)]

Severity set to `important'. Request was from Justin Pryzby <justinpryzby@users.sourceforge.net> to control@bugs.debian.org. Full text and rfc822 format available.

Bug reassigned from package `xutils' to `xutils-dev'. Request was from "Kevin B. McCarty" <kmccarty@Princeton.EDU> to control@bugs.debian.org. Full text and rfc822 format available.

Noted your statement that Bug has been forwarded to https://bugs.freedesktop.org/show_bug.cgi?id=10019. Request was from Brice Goglin <Brice.Goglin@ens-lyon.org> to control@bugs.debian.org. Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Thu Apr 24 07:07:55 2014; Machine Name: beach.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.