From owner-freebsd-hackers@FreeBSD.ORG Tue Aug 15 04:16:32 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 716FF16A4E0 for ; Tue, 15 Aug 2006 04:16:32 +0000 (UTC) (envelope-from j_guojun@lbl.gov) Received: from smtp110.sbc.mail.mud.yahoo.com (smtp110.sbc.mail.mud.yahoo.com [68.142.198.209]) by mx1.FreeBSD.org (Postfix) with SMTP id 96B9343D5F for ; Tue, 15 Aug 2006 04:16:26 +0000 (GMT) (envelope-from j_guojun@lbl.gov) Received: (qmail 12870 invoked from network); 15 Aug 2006 04:16:25 -0000 Received: from unknown (HELO ?192.168.2.8?) (jinmtb@sbcglobal.net@68.127.183.0 with plain) by smtp110.sbc.mail.mud.yahoo.com with SMTP; 15 Aug 2006 04:16:25 -0000 Message-ID: <44E14AFD.3040900@lbl.gov> Date: Mon, 14 Aug 2006 21:18:05 -0700 From: "Jin Guojun [VFFS]" User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.5) Gecko/20050108 X-Accept-Language: en, zh, zh-CN MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Tue, 15 Aug 2006 05:05:55 +0000 Subject: diff should not follow sym-link X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Aug 2006 04:16:32 -0000 I do not know what is the historical reason for program "diff" to follow a symbolic link during the recursive diff (-r), but it seems not to be a proper implementation. If both compared directories contains a sym-link, which point to a same file or directory, it obviously no need to compare it (not them). If both compared directories contains a sym-link, which point to a duplicated file or directory, and files or directories are duplicated in the same tree level, these files or directories will be compared any way during the recursive diff. So there is no need to follow the sym-link to compare them (just waste time by doing so). The only case that I can see that diff may follow the sym-link in recursive comparison is if the symlink is pointing to a duplicated directory/file in very different locations, which may probably rarely be created. If this is probably the only case "diff -r" needs to follow the sym-link, an option -L or something similar in other commands, such as ls, should be add for such purpose. Otherwise, diff -r can be loop forever on large file systems if there is some symlinks point forth and back between some directories, users may create them for easy to traversal around file systems. Then the process of "diff -r" a backup file system and a live file system will take a day to finish till maximum symlink number is reached, and many redundant diff information is created. See simple example below. So, we need to either disable recursive diff to follow the symlink, or we need a switch (option) to enable following symlink feature in recursive comparison of diff when a user real needs it. Any comment? -Jin ------------- example of looping on recursive diff ------------------------ % create a simple test structure % dir -R test # show tree structure, in real case a and b will be a large tree total 8 drwxr-xr-x 3 jin wheel 512 Aug 14 20:25 a/ drwxr-xr-x 2 jin wheel 512 Aug 14 20:32 b/ -rw-r--r-- 1 jin wheel 4 Aug 14 20:23 x -rw-r--r-- 1 jin wheel 4 Aug 14 20:25 y test/a: total 2 drwxr-xr-x 2 jin wheel 512 Aug 14 20:25 a1/ lrwxr-xr-x 1 jin wheel 4 Aug 14 20:25 x@ -> ../x test/a/a1: total 0 lrwxr-xr-x 1 jin wheel 10 Aug 14 20:24 a1@ -> ../../b/a1 test/b: total 0 lrwxr-xr-x 1 jin wheel 4 Aug 14 20:32 a1@ -> ../a lrwxr-xr-x 1 jin wheel 4 Aug 14 20:25 x@ -> ../y % mkdir test1 % cd test % tar -cf - . | ( cd ../test1 ; tar -xf - ) % cd .. ; diff -r test test1 diff: test/a/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1: Too many levels of symbolic links diff: test1/a/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1: Too many levels of symbolic links diff: test/a/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/x: Too many levels of symbolic links diff: test1/a/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/x: Too many levels of symbolic links diff: test/b/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1: Too many levels of symbolic links diff: test1/b/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1/a1: Too many levels of symbolic links