From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#58446: 28.2; file-attribute-device-number returns a cons cell instead of an integer Date: Wed, 12 Oct 2022 16:57:04 +0200 Message-ID: <87edvd5bun.fsf@gmx.de> References: <87lepmusw5.fsf@posteo.net> <87pmexcn1h.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4996"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Thierry Volpiatto , 58446@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 12 17:02:43 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oidFr-000170-Lh for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 17:02:43 +0200 Original-Received: from localhost ([::1]:37774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oidFp-0002BX-W7 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Oct 2022 11:02:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oidBK-0007cI-T5 for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 10:58:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59123) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oidBK-0002Hc-HP for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 10:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oidBK-0008GK-CZ for bug-gnu-emacs@gnu.org; Wed, 12 Oct 2022 10:58:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 Oct 2022 14:58:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58446 X-GNU-PR-Package: emacs Original-Received: via spool by 58446-submit@debbugs.gnu.org id=B58446.166558664031668 (code B ref 58446); Wed, 12 Oct 2022 14:58:02 +0000 Original-Received: (at 58446) by debbugs.gnu.org; 12 Oct 2022 14:57:20 +0000 Original-Received: from localhost ([127.0.0.1]:58197 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oidAe-0008Ei-4k for submit@debbugs.gnu.org; Wed, 12 Oct 2022 10:57:20 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]:45199) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oidAb-0008ES-9r for 58446@debbugs.gnu.org; Wed, 12 Oct 2022 10:57:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1665586630; bh=wOKX35GRrrGK+YfAR3wqZUsFUvOX2ISXb45i1lv9ssg=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=j+07RYdUCFfNk4a0/lHcfM9U6mluwPmNZL73WzjpECUmH5tqNRlKW01Jl7P+6B1+m 4blolDbljErXMDRaLvuxBgc9/WvsaDwOYhsREwAjI8/wv3RjmPc5TUi7QTse/5IQBG k3quYVv4DcgEea3Ve5i60bw+dHclqHVz02yADJcg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from gandalf.gmx.de ([213.220.151.192]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MBDj4-1os1N527TS-00Cg90; Wed, 12 Oct 2022 16:57:10 +0200 In-Reply-To: <87pmexcn1h.fsf@gnus.org> (Lars Ingebrigtsen's message of "Wed, 12 Oct 2022 13:13:30 +0200") X-Provags-ID: V03:K1:UIAJMMRaEWUU0gjQnUvs82vQxeuCkcRIz0plz6glHqtt43CpjC2 bm1jHP5mZiEb5G9SJxGe3SOIFHwRLYcUmyL6Wu4Um20rZtj4jKlW1nuaosJPX8VHSOTeHe+ qd22+DT2x/ytVzDKMoPz+0xuTroA+rWP9+9KN3zT2psTPTZlsrtCGMPMz0uzDIVIhz6LArF fGjOmmZmuzoaY00RjHNiA== X-UI-Out-Filterresults: notjunk:1;V03:K0:5rHAUgUEWBY=:SBQCwNjofgDc5NtaGBsUG9 qj60lajJIaVSDGiYPD+kibI3lazvtquhfChtg0py/LgfkaMlveLijPWCF/Jjg5z9+a0kBgQLp 4OBqdDDcAdLqK+zlgZhZnqB4rIj8ZXT6VAolIbEmRhR7PE+99XE6GMTJhg706tjUsBHw6/3vu POt+7NRSeZfh2MN/VMuyGUnToBFWdA+tqkG/jIHhjjkaMqbtPJ0KLTOs+ndgtwLww1jq8kbln 6k6+5dhrXptTirEi+IKUV2J6RNXmeGhTLGF3y8cmaO66aBwUScnEfoSgKfCKjg+0AtxQDGHx2 /Eao0MAH6OxFkV868cgNXW10NnW+5cq720vlTD6Vhz6Ci5GUz4NeWJgbReGJ7GVvAWYzD3cpd jsXQutKIlkQ03W8az5pBDSRTwCZdFMXlxKpy3S+gXICg2l9DkyQt0X7ivi5YnsTm0HX3u1gdw LoAm+rJkxDpmNtGEGaERVHedo9I1dsNi8EAcoCxecWDsSsk61iB9OJGr3w361xSPhg7GHByAq cynFzG/iNwPLPhAs21Ps0RNfuG5bqvhEJ7VWkkvZIOhqSJNiMG3+6jxmRKscLxB7BEVCbMPzK iRob/e5BrWwxX2cMBDBWbVf7jbl/g1CDU/DR7anIHClSJdQL7lRi9dElAuwDiYNr9RkHoEngF iUWNwWH9VFw0h7DbZ01P/Ar1cXeU0jtLguYO8oTukxqI/88cyKTsMqN2xMA4ZYnGuYtpPDtNI no9Ulq8jJOfcw4e+hnXZubrOH/uGfZpFxXG9lM6IcQFWUeR5RMc3mxm6gH1IOh16IKgz8fXi X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:245220 Archived-At: Lars Ingebrigtsen writes: Hi Lars, >> The device-number in file-attributes (nth 11) is a cons cell when called >> on remote files (see tramp-get-device). >> It would be great to notify this in Emacs documentation and how to >> interpret this value e.g. (-1 . 1). >> I noticed this in fixing a bug in dired-async.el, the code was using `=` >> to compare the two values which is legitimate according to docstring. > > Hm... would it be possible for Tramp to stash that information > somewhere else? It is (as you say) documented to be a number. Yes, Tramp is out of the documented API in this case. And no, it cannot be kept somewhere else. Inodes are unique only on the given file system. That's why there are device numbers, which identify a file system. A remote file is not related to any (local) file system. That's why ange-ftp returns -1 as device-number, always. This is good enough for practical purposes, because it is different to any device number of a file system visible on the local host. For the inode number, ange-ftp uses a "virtual" one, which means for every accessed file it increases its internal counter. By this, all files accessed by ange-ftp are regarded as different if they differ in the remote file name, even if they are equal. Tramp did inherit this approach from ange-ftp, with the difference that it uses virtual inode numbers only in case it couldn't determine the real inode number. It has its own counter for virtual inode numbers, divided from ange-ftp. This had several problems. The device number of all connected remote devices, be it via any Tramp method or via ange-ftp, was always the same. Remote files were regarded as equal if just the inode number was the same, be it a real inode number or a virtual number. Therefore, in January 2003 (almost 20 years ago :-) the device number in Tramp has changed. It is now a cons cell (-1 . REMOTE), with REMOTE being a virtual device number generated by Tramp for very connection. By this, the tupel (inode, device) still identifies a file uniquely, being it local or remote. As said, this change happend almost 20 years ago. Device numbers are usually ignored by Emacs and external packages, I don't remember a problem report for this over the years. Emacs core creates the buffer-local variable buffer-file-number, which is indeed (INODE DEVNUM). See basic-save-buffer: (setq buffer-file-number (nthcdr 10 (file-attributes buffer-file-name))) And this variable is used for checking whether two files are equal, see find-buffer-visiting: (equal buffer-file-number number) That's why it works also with Tramp's interpretation of device numbers. And again, w/o blame over the years. I tend to agree with Thierry: we shall document the status quo, i.e. device numbers can be more than just an integer, and should be compared via equal. The details of that structure don't matter I believe. And perhaps we could even add a helper function to extract the information for a file's uniqueness: (defsubst file-attribute-file-number (attributes) "The inode and device numbers in ATTRIBUTES returned by `file-attributes'. It can be used to determine whether two files are identical." (nthcdr 10 attributes)) WDYT? Best regards, Michael.