Subject: bug#58446: 28.2; file-attribute-device-number returns a cons cell instead of an integer

From: Lars Ingebrigtsen <[email-masked]>
Date: Thu, 13 Oct 2022 08:31:06 +0200

Michael Albinus <[email-masked]> writes:

[explanation snipped]

> 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.

Yes, I agree -- we should probably just document this.  But I was
wondering whether it would be useful to make the `file-attribute'
structure extendable?  We could have a twelfth (optional) element that
could be an plist of properties, and then we'd have a place to stash
stuff.

(That might break stuff, though.)

But if we haven't needed that until now, we're probably not going to
need it going forward, and we should just document the current status
quo. 

> 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?

Makes sense to me.