From owner-freebsd-ports Mon Sep 4 0:40:55 2000 Delivered-To: freebsd-ports@freebsd.org Received: from blizzard.sabbo.net (blizzard.sabbo.net [193.193.218.18]) by hub.freebsd.org (Postfix) with ESMTP id 3FE5637B423; Mon, 4 Sep 2000 00:40:47 -0700 (PDT) Received: from vic.sabbo.net (root@vic.sabbo.net [193.193.218.106]) by blizzard.sabbo.net (8.9.1/8.9.3) with ESMTP id KAA15403; Mon, 4 Sep 2000 10:40:43 +0300 (EEST) Received: from FreeBSD.org (big_brother.vega.com [192.168.1.1]) by vic.sabbo.net (8.11.0/8.9.3) with ESMTP id e847ehC21081; Mon, 4 Sep 2000 10:40:43 +0300 (EEST) (envelope-from sobomax@FreeBSD.org) Message-ID: <39B351FA.A6CFD24F@FreeBSD.org> Date: Mon, 04 Sep 2000 10:40:42 +0300 From: Maxim Sobolev Organization: Vega International Capital X-Mailer: Mozilla 4.75 [en] (WinNT; U) X-Accept-Language: uk,ru,en MIME-Version: 1.0 To: ports@FreeBSD.org Cc: asami@FreeBSD.org Subject: Handling of symlinks to directory in pkg_delete [patch for review] Content-Type: multipart/mixed; boundary="------------F5EBA43B6A4A5E65749923B7" Sender: owner-freebsd-ports@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org This is a multi-part message in MIME format. --------------F5EBA43B6A4A5E65749923B7 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 7bit Hi! I wonder if anybody noticed that handling of symlinks in pkg_delete is somewhat broken. Particularly, the problems exist with symlinks to a directories. The pkg_delete code considers those symlinks as a directories (if the referred directory exists), however they are not, and thus tries to delete it using rmdir(2), which obviously doesn't work. The workaround exists to delete directory symlink points to first and only then remove corresponding symlinks, however it looks like an ugly hack (see lesstif's PLIST for example). The attached patch is expected to solve this problem. Also in this message I'm attaching small fake package, which exposes the bug (it consist of one symlink and one directory this symlink points to). -Maxim --------------F5EBA43B6A4A5E65749923B7 Content-Type: application/x-compressed; name="fake-0.0.tgz" Content-Transfer-Encoding: base64 Content-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Bk3H61fvINk1h5ZMojk+bfwpFJuTmNZ+bWlFvT eGZuTbkxjWfm1pTb0nhmbk25KY1n5taUW9I1C9mrQsnEivBGa9mrr2oZz3Q8O87Ew20Zmxh9 Pe02swOCaRlHUrqkWqz4Hpnz9H60ZnMfk8yle8TOwgM/PV6becoJav+xrUGYR9CxUOd6p15h ajFqjfi17St+bapmYmlxgFpjfm27xa/97YJfOzZ5tQR1ebWuhy57vNoIXfD6jGq5/ZBoeeNG tZdDTu0kQldDzj05WaCrMafWI6jH618v5l8b1fZ49/pXC326E7tj5qFcicxPPZNDNfHcGBVI pyG6HhaN6lvoZiC2zHavVyzr9Mz1aplZdSXmc82elhnKPS0z8/sxuhlxagOf/6hQ7eCGVxui wS2ndu6juxtOP8xjdMe79aIFMsdi+65eYxY6K9nmkczwrrTXt716ZcjSER+ZPc4lkW/I5A3B YorGrdX4Y5bunwlqD4r2PxWNfhcvvIfcJe/ckik+qB3ohf79/Pe/px/4nu+L4qEpalKZ837/ 1wAUTVWrR6Buf4iU1j8lPv/k3vj339JKK6200kor7e3Zf0CPOHgAKAAA --------------F5EBA43B6A4A5E65749923B7 Content-Type: text/plain; charset=koi8-r; name="pkg_install-symlinks.to.dir.handling-diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pkg_install-symlinks.to.dir.handling-diff" --- pkg_install/lib/file.c 2000/09/02 19:31:59 1.1 +++ pkg_install/lib/file.c 2000/09/02 19:39:30 @@ -40,7 +40,7 @@ return FALSE; } -/* Quick check to see if something is a directory */ +/* Quick check to see if something is a directory or symlink to a directory */ Boolean isdir(char *fname) { @@ -54,7 +54,7 @@ return FALSE; } -/* Check to see if file is a dir, and is empty */ +/* Check to see if file is a dir or symlink to a dir, and is empty */ Boolean isemptydir(char *fname) { @@ -77,6 +77,10 @@ return FALSE; } +/* + * Returns TRUE if file is a regular file or symlink pointing to a regular + * file + */ Boolean isfile(char *fname) { @@ -86,8 +90,11 @@ return FALSE; } -/* Check to see if file is a file and is empty. If nonexistent or not - a file, say "it's empty", otherwise return TRUE if zero sized. */ +/* + * Check to see if file is a file or symlink pointing to a file and is empty. + * If nonexistent or not a file, say "it's empty", otherwise return TRUE if + * zero sized. + */ Boolean isemptyfile(char *fname) { @@ -97,6 +104,16 @@ return FALSE; } return TRUE; +} + +/* Returns TRUE if file is a symbolic link. */ +Boolean +issymlink(char *fname) +{ + struct stat sb; + if (lstat(fname, &sb) != FAIL && S_ISLNK(sb.st_mode)) + return TRUE; + return FALSE; } /* Returns TRUE if file is a URL specification */ --- pkg_install/lib/lib.h 2000/09/04 07:12:52 1.1 +++ pkg_install/lib/lib.h 2000/09/04 07:15:41 @@ -129,6 +129,7 @@ Boolean isemptyfile(char *fname); Boolean isfile(char *); Boolean isempty(char *); +Boolean issymlink(char *); Boolean isURL(char *); char *fileGetURL(char *, char *); char *fileFindByPath(char *, char *); --- pkg_install/lib/plist.c 2000/09/02 19:31:59 1.1 +++ pkg_install/lib/plist.c 2000/09/02 19:32:17 @@ -390,7 +390,7 @@ case PLIST_FILE: last_file = p->name; sprintf(tmp, "%s/%s", Where, p->name); - if (isdir(tmp) && fexists(tmp)) { + if (isdir(tmp) && fexists(tmp) && !issymlink(tmp)) { warnx("cannot delete specified file `%s' - it is a directory!\n" "this packing list is incorrect - ignoring delete request", tmp); } @@ -477,7 +477,7 @@ if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir)) return 1; } - else if (isdir(dir)) { + else if (isdir(dir) && !issymlink(dir)) { if (RMDIR(dir) && !ign_err) return 1; } --------------F5EBA43B6A4A5E65749923B7-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message