diff options
| author | Michael Albinus | 2022-10-13 21:13:45 +0200 |
|---|---|---|
| committer | Michael Albinus | 2022-10-13 21:13:45 +0200 |
| commit | cbd04ad3d572850775f18bde868c71abcde733ed (patch) | |
| tree | cca60866632ff253cbc5062ab7483379e81a1376 | |
| parent | 10f55975d34dd7299f72fdf8d93fd8cbe2e41e25 (diff) | |
| download | emacs-cbd04ad3d572850775f18bde868c71abcde733ed.tar.gz emacs-cbd04ad3d572850775f18bde868c71abcde733ed.zip | |
Clarify structure of file-attribute's device number
* doc/lispref/buffers.texi (Buffer File Name): Fix description of
buffer-file-number.
* doc/lispref/files.texi (File Attributes): Clarify type of device
number. Describe file-attribute-file-number. (Bug#58446)
* etc/NEWS: Mention file-attribute-file-number.
* lisp/files.el (buffer-file-number, file-attribute-device-number)
(file-attribute-collect): Fix docstring.
(file-attribute-file-number): New defsubst.
(find-buffer-visiting, find-file-noselect)
(set-visited-file-name, basic-save-buffer):
* lisp/startup.el (normal-top-level-add-subdirs-to-load-path):
* lisp/eshell/em-unix.el (eshell-shuffle-files): Use it.
* src/dired.c (Ffile_attributes): Fix docstring.
| -rw-r--r-- | doc/lispref/buffers.texi | 4 | ||||
| -rw-r--r-- | doc/lispref/files.texi | 13 | ||||
| -rw-r--r-- | etc/NEWS | 9 | ||||
| -rw-r--r-- | lisp/eshell/em-unix.el | 6 | ||||
| -rw-r--r-- | lisp/files.el | 24 | ||||
| -rw-r--r-- | lisp/startup.el | 2 | ||||
| -rw-r--r-- | src/dired.c | 5 |
7 files changed, 38 insertions, 25 deletions
diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi index 6a1d125701c..b46b6c52d86 100644 --- a/doc/lispref/buffers.texi +++ b/doc/lispref/buffers.texi | |||
| @@ -427,12 +427,12 @@ It is a permanent local, unaffected by | |||
| 427 | @end defvar | 427 | @end defvar |
| 428 | 428 | ||
| 429 | @defvar buffer-file-number | 429 | @defvar buffer-file-number |
| 430 | This buffer-local variable holds the file number and directory device | 430 | This buffer-local variable holds the inode number and directory device |
| 431 | number of the file visited in the current buffer, or @code{nil} if no | 431 | number of the file visited in the current buffer, or @code{nil} if no |
| 432 | file or a nonexistent file is visited. It is a permanent local, | 432 | file or a nonexistent file is visited. It is a permanent local, |
| 433 | unaffected by @code{kill-all-local-variables}. | 433 | unaffected by @code{kill-all-local-variables}. |
| 434 | 434 | ||
| 435 | The value is normally a list of the form @code{(@var{filenum} | 435 | The value is normally a list of the form @code{(@var{inodenum} |
| 436 | @var{devnum})}. This pair of numbers uniquely identifies the file among | 436 | @var{devnum})}. This pair of numbers uniquely identifies the file among |
| 437 | all files accessible on the system. See the function | 437 | all files accessible on the system. See the function |
| 438 | @code{file-attributes}, in @ref{File Attributes}, for more information | 438 | @code{file-attributes}, in @ref{File Attributes}, for more information |
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index 0e8efa3297c..b9d4e87dc73 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi | |||
| @@ -1405,13 +1405,16 @@ a nonnegative integer. | |||
| 1405 | 1405 | ||
| 1406 | @item | 1406 | @item |
| 1407 | The filesystem number of the device that the file is on | 1407 | The filesystem number of the device that the file is on |
| 1408 | @code{file-attribute-device-number}), an integer. | 1408 | (@code{file-attribute-device-number}), an integer or a cons cell of |
| 1409 | This element and the file's inode number | 1409 | integers. The latter is sometimes used by remote files, in order to |
| 1410 | together give enough information to distinguish any two files on the | 1410 | distinguish the remote filesystems from the local ones. |
| 1411 | system---no two files can have the same values for both of these | ||
| 1412 | numbers. | ||
| 1413 | @end enumerate | 1411 | @end enumerate |
| 1414 | 1412 | ||
| 1413 | The file's inode and device numbers together give enough information | ||
| 1414 | to distinguish any two files on the system---no two files can have the | ||
| 1415 | same values for both of these numbers. This tupel is returned by | ||
| 1416 | @code{file-attribute-file-number}. | ||
| 1417 | |||
| 1415 | For example, here are the file attributes for @file{files.texi}: | 1418 | For example, here are the file attributes for @file{files.texi}: |
| 1416 | 1419 | ||
| 1417 | @example | 1420 | @example |
| @@ -1872,7 +1872,7 @@ If non-nil, multiple revisions can be queried. This is done using | |||
| 1872 | 'completing-read-multiple'. | 1872 | 'completing-read-multiple'. |
| 1873 | 1873 | ||
| 1874 | --- | 1874 | --- |
| 1875 | *** New function 'vc-read-multiple-revisions' | 1875 | *** New function 'vc-read-multiple-revisions'. |
| 1876 | This function invokes 'vc-read-revision' with a non-nil value for | 1876 | This function invokes 'vc-read-revision' with a non-nil value for |
| 1877 | MULTIPLE. | 1877 | MULTIPLE. |
| 1878 | 1878 | ||
| @@ -1880,7 +1880,7 @@ MULTIPLE. | |||
| 1880 | *** New command 'vc-prepare-patch'. | 1880 | *** New command 'vc-prepare-patch'. |
| 1881 | Patches for any version control system can be prepared using VC. The | 1881 | Patches for any version control system can be prepared using VC. The |
| 1882 | command will query what commits to send and will compose messages for | 1882 | command will query what commits to send and will compose messages for |
| 1883 | your mail user agent. The behaviour of 'vc-prepare-patch' can be | 1883 | your mail user agent. The behavior of 'vc-prepare-patch' can be |
| 1884 | modified by the user options 'vc-prepare-patches-separately' and | 1884 | modified by the user options 'vc-prepare-patches-separately' and |
| 1885 | 'vc-default-patch-addressee'. | 1885 | 'vc-default-patch-addressee'. |
| 1886 | 1886 | ||
| @@ -3148,6 +3148,11 @@ The following generalized variables have been made obsolete: | |||
| 3148 | * Lisp Changes in Emacs 29.1 | 3148 | * Lisp Changes in Emacs 29.1 |
| 3149 | 3149 | ||
| 3150 | +++ | 3150 | +++ |
| 3151 | ** New accessor function 'file-attribute-file-number'. | ||
| 3152 | It returns the list of the inode and device numbers retrieved by | ||
| 3153 | 'file-attributes'. This value can be used to identify a file uniquely. | ||
| 3154 | |||
| 3155 | +++ | ||
| 3151 | ** New macro 'while-let'. | 3156 | ** New macro 'while-let'. |
| 3152 | This is like 'when-let', but repeats until a binding form is nil. | 3157 | This is like 'when-let', but repeats until a binding form is nil. |
| 3153 | 3158 | ||
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el index 40b83010f94..378b0ceeeae 100644 --- a/lisp/eshell/em-unix.el +++ b/lisp/eshell/em-unix.el | |||
| @@ -372,12 +372,10 @@ Remove the DIRECTORY(ies), if they are empty.") | |||
| 372 | (setq attr (eshell-file-attributes (car files))) | 372 | (setq attr (eshell-file-attributes (car files))) |
| 373 | (file-attribute-inode-number attr-target) | 373 | (file-attribute-inode-number attr-target) |
| 374 | (file-attribute-inode-number attr) | 374 | (file-attribute-inode-number attr) |
| 375 | (equal (file-attribute-inode-number attr-target) | ||
| 376 | (file-attribute-inode-number attr)) | ||
| 377 | (file-attribute-device-number attr-target) | 375 | (file-attribute-device-number attr-target) |
| 378 | (file-attribute-device-number attr) | 376 | (file-attribute-device-number attr) |
| 379 | (equal (file-attribute-device-number attr-target) | 377 | (equal (file-attribute-file-number attr-target) |
| 380 | (file-attribute-device-number attr))) | 378 | (file-attribute-file-number attr))) |
| 381 | (eshell-error (format-message "%s: `%s' and `%s' are the same file\n" | 379 | (eshell-error (format-message "%s: `%s' and `%s' are the same file\n" |
| 382 | command (car files) target))) | 380 | command (car files) target))) |
| 383 | (t | 381 | (t |
diff --git a/lisp/files.el b/lisp/files.el index 94d110f0b7d..1a301485517 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -208,8 +208,8 @@ if the file has changed on disk and you have not edited the buffer." | |||
| 208 | :group 'find-file) | 208 | :group 'find-file) |
| 209 | 209 | ||
| 210 | (defvar-local buffer-file-number nil | 210 | (defvar-local buffer-file-number nil |
| 211 | "The device number and file number of the file visited in the current buffer. | 211 | "The inode and device numbers of the file visited in the current buffer. |
| 212 | The value is a list of the form (FILENUM DEVNUM). | 212 | The value is a list of the form (INODENUM DEVNUM). |
| 213 | This pair of numbers uniquely identifies the file. | 213 | This pair of numbers uniquely identifies the file. |
| 214 | If the buffer is visiting a new file, the value is nil.") | 214 | If the buffer is visiting a new file, the value is nil.") |
| 215 | (put 'buffer-file-number 'permanent-local t) | 215 | (put 'buffer-file-number 'permanent-local t) |
| @@ -2163,7 +2163,7 @@ If there is no such live buffer, return nil." | |||
| 2163 | (setq list (cdr list))) | 2163 | (setq list (cdr list))) |
| 2164 | found) | 2164 | found) |
| 2165 | (let* ((attributes (file-attributes truename)) | 2165 | (let* ((attributes (file-attributes truename)) |
| 2166 | (number (nthcdr 10 attributes)) | 2166 | (number (file-attribute-file-number attributes)) |
| 2167 | (list (buffer-list)) found) | 2167 | (list (buffer-list)) found) |
| 2168 | (and buffer-file-numbers-unique | 2168 | (and buffer-file-numbers-unique |
| 2169 | (car-safe number) ;Make sure the inode is not just nil. | 2169 | (car-safe number) ;Make sure the inode is not just nil. |
| @@ -2366,7 +2366,7 @@ the various files." | |||
| 2366 | (let* ((buf (get-file-buffer filename)) | 2366 | (let* ((buf (get-file-buffer filename)) |
| 2367 | (truename (abbreviate-file-name (file-truename filename))) | 2367 | (truename (abbreviate-file-name (file-truename filename))) |
| 2368 | (attributes (file-attributes truename)) | 2368 | (attributes (file-attributes truename)) |
| 2369 | (number (nthcdr 10 attributes)) | 2369 | (number (file-attribute-file-number attributes)) |
| 2370 | ;; Find any buffer for a file that has same truename. | 2370 | ;; Find any buffer for a file that has same truename. |
| 2371 | (other (and (not buf) | 2371 | (other (and (not buf) |
| 2372 | (find-buffer-visiting | 2372 | (find-buffer-visiting |
| @@ -4744,7 +4744,7 @@ the old visited file has been renamed to the new name FILENAME." | |||
| 4744 | (setq buffer-file-name truename)))) | 4744 | (setq buffer-file-name truename)))) |
| 4745 | (setq buffer-file-number | 4745 | (setq buffer-file-number |
| 4746 | (if filename | 4746 | (if filename |
| 4747 | (nthcdr 10 (file-attributes buffer-file-name)) | 4747 | (file-attribute-file-number (file-attributes buffer-file-name)) |
| 4748 | nil)) | 4748 | nil)) |
| 4749 | ;; write-file-functions is normally used for things like ftp-find-file | 4749 | ;; write-file-functions is normally used for things like ftp-find-file |
| 4750 | ;; that visit things that are not local files as if they were files. | 4750 | ;; that visit things that are not local files as if they were files. |
| @@ -5733,7 +5733,7 @@ Before and after saving the buffer, this function runs | |||
| 5733 | (setq save-buffer-coding-system last-coding-system-used) | 5733 | (setq save-buffer-coding-system last-coding-system-used) |
| 5734 | (setq buffer-file-coding-system last-coding-system-used)) | 5734 | (setq buffer-file-coding-system last-coding-system-used)) |
| 5735 | (setq buffer-file-number | 5735 | (setq buffer-file-number |
| 5736 | (nthcdr 10 (file-attributes buffer-file-name))) | 5736 | (file-attribute-file-number (file-attributes buffer-file-name))) |
| 5737 | (if setmodes | 5737 | (if setmodes |
| 5738 | (condition-case () | 5738 | (condition-case () |
| 5739 | (progn | 5739 | (progn |
| @@ -8658,19 +8658,25 @@ It is a nonnegative integer." | |||
| 8658 | 8658 | ||
| 8659 | (defsubst file-attribute-device-number (attributes) | 8659 | (defsubst file-attribute-device-number (attributes) |
| 8660 | "The file system device number in ATTRIBUTES returned by `file-attributes'. | 8660 | "The file system device number in ATTRIBUTES returned by `file-attributes'. |
| 8661 | It is an integer." | 8661 | It is an integer or a cons cell of integers." |
| 8662 | (nth 11 attributes)) | 8662 | (nth 11 attributes)) |
| 8663 | 8663 | ||
| 8664 | (defsubst file-attribute-file-number (attributes) | ||
| 8665 | "The inode and device numbers in ATTRIBUTES returned by `file-attributes'. | ||
| 8666 | The value is a list of the form (INODENUM DEVNUM). | ||
| 8667 | This pair of numbers uniquely identifies the file." | ||
| 8668 | (nthcdr 10 attributes)) | ||
| 8669 | |||
| 8664 | (defun file-attribute-collect (attributes &rest attr-names) | 8670 | (defun file-attribute-collect (attributes &rest attr-names) |
| 8665 | "Return a sublist of ATTRIBUTES returned by `file-attributes'. | 8671 | "Return a sublist of ATTRIBUTES returned by `file-attributes'. |
| 8666 | ATTR-NAMES are symbols with the selected attribute names. | 8672 | ATTR-NAMES are symbols with the selected attribute names. |
| 8667 | 8673 | ||
| 8668 | Valid attribute names are: type, link-number, user-id, group-id, | 8674 | Valid attribute names are: type, link-number, user-id, group-id, |
| 8669 | access-time, modification-time, status-change-time, size, modes, | 8675 | access-time, modification-time, status-change-time, size, modes, |
| 8670 | inode-number and device-number." | 8676 | inode-number, device-number and file-number." |
| 8671 | (let ((all '(type link-number user-id group-id access-time | 8677 | (let ((all '(type link-number user-id group-id access-time |
| 8672 | modification-time status-change-time | 8678 | modification-time status-change-time |
| 8673 | size modes inode-number device-number)) | 8679 | size modes inode-number device-number file-number)) |
| 8674 | result) | 8680 | result) |
| 8675 | (while attr-names | 8681 | (while attr-names |
| 8676 | (let ((attr (pop attr-names))) | 8682 | (let ((attr (pop attr-names))) |
diff --git a/lisp/startup.el b/lisp/startup.el index 04de7e42fea..c7faf4abc6f 100644 --- a/lisp/startup.el +++ b/lisp/startup.el | |||
| @@ -458,7 +458,7 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'." | |||
| 458 | ;; The Windows version doesn't report meaningful inode numbers, so | 458 | ;; The Windows version doesn't report meaningful inode numbers, so |
| 459 | ;; use the canonicalized absolute file name of the directory instead. | 459 | ;; use the canonicalized absolute file name of the directory instead. |
| 460 | (setq attrs (or canonicalized | 460 | (setq attrs (or canonicalized |
| 461 | (nthcdr 10 (file-attributes this-dir)))) | 461 | (file-attribute-file-number (file-attributes this-dir)))) |
| 462 | (unless (member attrs normal-top-level-add-subdirs-inode-list) | 462 | (unless (member attrs normal-top-level-add-subdirs-inode-list) |
| 463 | (push attrs normal-top-level-add-subdirs-inode-list) | 463 | (push attrs normal-top-level-add-subdirs-inode-list) |
| 464 | (dolist (file contents) | 464 | (dolist (file contents) |
diff --git a/src/dired.c b/src/dired.c index c2c099f0a5f..32c083ad7b0 100644 --- a/src/dired.c +++ b/src/dired.c | |||
| @@ -923,11 +923,12 @@ Elements of the attribute list are: | |||
| 923 | 8. File modes, as a string of ten letters or dashes as in ls -l. | 923 | 8. File modes, as a string of ten letters or dashes as in ls -l. |
| 924 | 9. An unspecified value, present only for backward compatibility. | 924 | 9. An unspecified value, present only for backward compatibility. |
| 925 | 10. inode number, as a nonnegative integer. | 925 | 10. inode number, as a nonnegative integer. |
| 926 | 11. Filesystem device number, as an integer. | 926 | 11. Filesystem device number, as an integer or a cons cell of integers. |
| 927 | 927 | ||
| 928 | Large integers are bignums, so `eq' might not work on them. | 928 | Large integers are bignums, so `eq' might not work on them. |
| 929 | On most filesystems, the combination of the inode and the device | 929 | On most filesystems, the combination of the inode and the device |
| 930 | number uniquely identifies the file. | 930 | number uniquely identifies the file. This is provided by the access |
| 931 | function `file-attribute-file-number'. | ||
| 931 | 932 | ||
| 932 | On MS-Windows, performance depends on `w32-get-true-file-attributes', | 933 | On MS-Windows, performance depends on `w32-get-true-file-attributes', |
| 933 | which see. | 934 | which see. |