diff options
| author | Paul Eggert | 2017-08-19 00:48:28 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-08-19 00:49:39 -0700 |
| commit | e58b3ef78b7db5190bd940495da6de0b6737f955 (patch) | |
| tree | 2e6c43e0b52a63f2a43cec4dcfe7124c39197927 | |
| parent | 6763399ef3f268269fefd75d7c7a4ac012f66833 (diff) | |
| download | emacs-e58b3ef78b7db5190bd940495da6de0b6737f955.tar.gz emacs-e58b3ef78b7db5190bd940495da6de0b6737f955.zip | |
Clarify behavior of symlinks and directories
* doc/lispref/files.texi (Saving Buffers): Document how functions
like rename-file work with symlinks and directories. This patch
attempts to document the current behavior better, in preparation
for possibly changing it. See Bug#27986.
| -rw-r--r-- | doc/lispref/files.texi | 123 |
1 files changed, 80 insertions, 43 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index 9359d3eaa09..5a52765131c 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi | |||
| @@ -401,6 +401,8 @@ If @var{confirm} is non-@code{nil}, that means to ask for confirmation | |||
| 401 | before overwriting an existing file. Interactively, confirmation is | 401 | before overwriting an existing file. Interactively, confirmation is |
| 402 | required, unless the user supplies a prefix argument. | 402 | required, unless the user supplies a prefix argument. |
| 403 | 403 | ||
| 404 | @c FIXME: This disagrees with the doc string, which talks about | ||
| 405 | @c directory names, not directories. See Bug#27986. | ||
| 404 | If @var{filename} is an existing directory, or a symbolic link to one, | 406 | If @var{filename} is an existing directory, or a symbolic link to one, |
| 405 | @code{write-file} uses the name of the visited file, in directory | 407 | @code{write-file} uses the name of the visited file, in directory |
| 406 | @var{filename}. If the buffer is not visiting a file, it uses the | 408 | @var{filename}. If the buffer is not visiting a file, it uses the |
| @@ -628,7 +630,10 @@ If @var{mustbenew} is non-@code{nil}, then @code{write-region} asks | |||
| 628 | for confirmation if @var{filename} names an existing file. If | 630 | for confirmation if @var{filename} names an existing file. If |
| 629 | @var{mustbenew} is the symbol @code{excl}, then @code{write-region} | 631 | @var{mustbenew} is the symbol @code{excl}, then @code{write-region} |
| 630 | does not ask for confirmation, but instead it signals an error | 632 | does not ask for confirmation, but instead it signals an error |
| 631 | @code{file-already-exists} if the file already exists. | 633 | @code{file-already-exists} if the file already exists. Although |
| 634 | @code{write-region} normally follows a symbolic link and creates the | ||
| 635 | pointed-to file if the symbolic link is dangling, it does not follow | ||
| 636 | symbolic links if @var{mustbenew} is @code{excl}. | ||
| 632 | 637 | ||
| 633 | The test for an existing file, when @var{mustbenew} is @code{excl}, uses | 638 | The test for an existing file, when @var{mustbenew} is @code{excl}, uses |
| 634 | a special system feature. At least for files on a local disk, there is | 639 | a special system feature. At least for files on a local disk, there is |
| @@ -817,9 +822,7 @@ are silently and automatically ignored. | |||
| 817 | 822 | ||
| 818 | These functions test for permission to access a file for reading, | 823 | These functions test for permission to access a file for reading, |
| 819 | writing, or execution. Unless explicitly stated otherwise, they | 824 | writing, or execution. Unless explicitly stated otherwise, they |
| 820 | recursively follow symbolic links for their file name arguments, at | 825 | follow symbolic links. @xref{Kinds of Files}. |
| 821 | all levels (at the level of the file itself and at all levels of | ||
| 822 | parent directories). | ||
| 823 | 826 | ||
| 824 | On some operating systems, more complex sets of access permissions | 827 | On some operating systems, more complex sets of access permissions |
| 825 | can be specified, via mechanisms such as Access Control Lists (ACLs). | 828 | can be specified, via mechanisms such as Access Control Lists (ACLs). |
| @@ -838,8 +841,8 @@ If the file does not exist, or if access control policies prevent you | |||
| 838 | from finding its attributes, this function returns @code{nil}. | 841 | from finding its attributes, this function returns @code{nil}. |
| 839 | 842 | ||
| 840 | Directories are files, so @code{file-exists-p} returns @code{t} when | 843 | Directories are files, so @code{file-exists-p} returns @code{t} when |
| 841 | given a directory name. However, symbolic links are treated | 844 | given a directory name. However, because @code{file-exists-p} follows |
| 842 | specially; @code{file-exists-p} returns @code{t} for a symbolic link | 845 | symbolic links, it returns @code{t} for a symbolic link |
| 843 | name only if the target file exists. | 846 | name only if the target file exists. |
| 844 | @end defun | 847 | @end defun |
| 845 | 848 | ||
| @@ -906,10 +909,7 @@ returns @code{t} for nonexistent files. | |||
| 906 | If the optional argument @var{group} is non-@code{nil}, this function | 909 | If the optional argument @var{group} is non-@code{nil}, this function |
| 907 | also checks that the file's group would be unchanged. | 910 | also checks that the file's group would be unchanged. |
| 908 | 911 | ||
| 909 | If @var{filename} is a symbolic link, then, unlike the other functions | 912 | This function does not follow symbolic links. |
| 910 | discussed here, @code{file-ownership-preserved-p} does @emph{not} | ||
| 911 | replace @var{filename} with its target. However, it does recursively | ||
| 912 | follow symbolic links at all levels of parent directories. | ||
| 913 | @end defun | 913 | @end defun |
| 914 | 914 | ||
| 915 | @defun file-modes filename | 915 | @defun file-modes filename |
| @@ -919,8 +919,8 @@ follow symbolic links at all levels of parent directories. | |||
| 919 | @cindex file modes | 919 | @cindex file modes |
| 920 | This function returns the @dfn{mode bits} of @var{filename}---an | 920 | This function returns the @dfn{mode bits} of @var{filename}---an |
| 921 | integer summarizing its read, write, and execution permissions. | 921 | integer summarizing its read, write, and execution permissions. |
| 922 | Symbolic links in @var{filename} are recursively followed at all | 922 | This function follows symbolic links. If the file does not exist, the |
| 923 | levels. If the file does not exist, the return value is @code{nil}. | 923 | return value is @code{nil}. |
| 924 | 924 | ||
| 925 | @xref{File permissions,,, coreutils, The @sc{gnu} @code{Coreutils} | 925 | @xref{File permissions,,, coreutils, The @sc{gnu} @code{Coreutils} |
| 926 | Manual}, for a description of mode bits. For example, if the | 926 | Manual}, for a description of mode bits. For example, if the |
| @@ -971,19 +971,26 @@ Unix. These conventions are also followed by @code{file-attributes} | |||
| 971 | @subsection Distinguishing Kinds of Files | 971 | @subsection Distinguishing Kinds of Files |
| 972 | @cindex file classification | 972 | @cindex file classification |
| 973 | @cindex classification of file types | 973 | @cindex classification of file types |
| 974 | @cindex symbolic links | ||
| 974 | 975 | ||
| 975 | This section describes how to distinguish various kinds of files, such | 976 | This section describes how to distinguish various kinds of files, such |
| 976 | as directories, symbolic links, and ordinary files. | 977 | as directories, symbolic links, and ordinary files. |
| 977 | 978 | ||
| 979 | Symbolic links are ordinarily followed wherever they appear. For | ||
| 980 | example, to interpret the file name @file{a/b/c}, any of @file{a}, | ||
| 981 | @file{a/b}, and @file{a/b/c} can be symbolic links that are followed, | ||
| 982 | possibly recursively if the link targets are themselves symbolic | ||
| 983 | links. However, a few functions do not follow symbolic links at the | ||
| 984 | end of a file name (@file{a/b/c} in this example). Such a function | ||
| 985 | is said to @dfn{not follow symbolic links}. | ||
| 986 | |||
| 978 | @defun file-symlink-p filename | 987 | @defun file-symlink-p filename |
| 979 | @cindex file symbolic links | 988 | @cindex symbolic links |
| 980 | If the file @var{filename} is a symbolic link, the | 989 | If the file @var{filename} is a symbolic link, this function does not |
| 981 | @code{file-symlink-p} function returns its (non-recursive) link target | 990 | follow it and instead returns its link target |
| 982 | as a string. (The link target string is not necessarily the full | 991 | as a string. (The link target string is not necessarily the full |
| 983 | absolute file name of the target; determining the full file name that | 992 | absolute file name of the target; determining the full file name that |
| 984 | the link points to is nontrivial, see below.) If the leading | 993 | the link points to is nontrivial, see below.) |
| 985 | directories of @var{filename} include symbolic links, this function | ||
| 986 | recursively follows them. | ||
| 987 | 994 | ||
| 988 | If the file @var{filename} is not a symbolic link, or does not exist, | 995 | If the file @var{filename} is not a symbolic link, or does not exist, |
| 989 | @code{file-symlink-p} returns @code{nil}. | 996 | @code{file-symlink-p} returns @code{nil}. |
| @@ -1011,9 +1018,9 @@ Here are a few examples of using this function: | |||
| 1011 | 1018 | ||
| 1012 | Note that in the third example, the function returned @file{sym-link}, | 1019 | Note that in the third example, the function returned @file{sym-link}, |
| 1013 | but did not proceed to resolve it, although that file is itself a | 1020 | but did not proceed to resolve it, although that file is itself a |
| 1014 | symbolic link. This is what we meant by ``non-recursive'' above---the | 1021 | symbolic link. That is because this function does not follow symbolic |
| 1015 | process of following the symbolic links does not recurse if the link | 1022 | links---the process of following the symbolic links does not apply to |
| 1016 | target is itself a link. | 1023 | the last component of the file name. |
| 1017 | 1024 | ||
| 1018 | The string that this function returns is what is recorded in the | 1025 | The string that this function returns is what is recorded in the |
| 1019 | symbolic link; it may or may not include any leading directories. | 1026 | symbolic link; it may or may not include any leading directories. |
| @@ -1044,12 +1051,10 @@ link. If you actually need the file name of the link target, use | |||
| 1044 | @ref{Truenames}. | 1051 | @ref{Truenames}. |
| 1045 | @end defun | 1052 | @end defun |
| 1046 | 1053 | ||
| 1047 | The next two functions recursively follow symbolic links at | ||
| 1048 | all levels for @var{filename}. | ||
| 1049 | |||
| 1050 | @defun file-directory-p filename | 1054 | @defun file-directory-p filename |
| 1051 | This function returns @code{t} if @var{filename} is the name of an | 1055 | This function returns @code{t} if @var{filename} is the name of an |
| 1052 | existing directory, @code{nil} otherwise. | 1056 | existing directory, @code{nil} otherwise. |
| 1057 | This function follows symbolic links. | ||
| 1053 | 1058 | ||
| 1054 | @example | 1059 | @example |
| 1055 | @group | 1060 | @group |
| @@ -1080,6 +1085,7 @@ existing directory, @code{nil} otherwise. | |||
| 1080 | This function returns @code{t} if the file @var{filename} exists and is | 1085 | This function returns @code{t} if the file @var{filename} exists and is |
| 1081 | a regular file (not a directory, named pipe, terminal, or | 1086 | a regular file (not a directory, named pipe, terminal, or |
| 1082 | other I/O device). | 1087 | other I/O device). |
| 1088 | This function follows symbolic links. | ||
| 1083 | @end defun | 1089 | @end defun |
| 1084 | 1090 | ||
| 1085 | @node Truenames | 1091 | @node Truenames |
| @@ -1231,15 +1237,11 @@ on the 19th, @file{aug-20} was written on the 20th, and the file | |||
| 1231 | @end example | 1237 | @end example |
| 1232 | @end defun | 1238 | @end defun |
| 1233 | 1239 | ||
| 1234 | If the @var{filename} argument to the next two functions is a | ||
| 1235 | symbolic link, then these function do @emph{not} replace it with its | ||
| 1236 | target. However, they both recursively follow symbolic links at all | ||
| 1237 | levels of parent directories. | ||
| 1238 | |||
| 1239 | @defun file-attributes filename &optional id-format | 1240 | @defun file-attributes filename &optional id-format |
| 1240 | @anchor{Definition of file-attributes} | 1241 | @anchor{Definition of file-attributes} |
| 1241 | This function returns a list of attributes of file @var{filename}. If | 1242 | This function returns a list of attributes of file @var{filename}. If |
| 1242 | the specified file cannot be opened, it returns @code{nil}. | 1243 | the specified file's attributes cannot be accessed, it returns @code{nil}. |
| 1244 | This function does not follow symbolic links. | ||
| 1243 | The optional parameter @var{id-format} specifies the preferred format | 1245 | The optional parameter @var{id-format} specifies the preferred format |
| 1244 | of attributes @acronym{UID} and @acronym{GID} (see below)---the | 1246 | of attributes @acronym{UID} and @acronym{GID} (see below)---the |
| 1245 | valid values are @code{'string} and @code{'integer}. The latter is | 1247 | valid values are @code{'string} and @code{'integer}. The latter is |
| @@ -1391,7 +1393,7 @@ This function returns the number of names (i.e., hard links) that | |||
| 1391 | file @var{filename} has. If the file does not exist, this function | 1393 | file @var{filename} has. If the file does not exist, this function |
| 1392 | returns @code{nil}. Note that symbolic links have no effect on this | 1394 | returns @code{nil}. Note that symbolic links have no effect on this |
| 1393 | function, because they are not considered to be names of the files | 1395 | function, because they are not considered to be names of the files |
| 1394 | they link to. | 1396 | they link to. This function does not follow symbolic links. |
| 1395 | 1397 | ||
| 1396 | @example | 1398 | @example |
| 1397 | @group | 1399 | @group |
| @@ -1553,6 +1555,16 @@ a @code{file-missing} error instead. | |||
| 1553 | made by these functions instead of writing them immediately to | 1555 | made by these functions instead of writing them immediately to |
| 1554 | secondary storage. @xref{Files and Storage}. | 1556 | secondary storage. @xref{Files and Storage}. |
| 1555 | 1557 | ||
| 1558 | @c FIXME: This paragraph is purposely silent on what happens if | ||
| 1559 | @c @var{newname} is not a directory name but happens to name a | ||
| 1560 | @c directory. See Bug#27986 for discussion on how to clear this up. | ||
| 1561 | In the functions that have an argument @var{newname}, if this | ||
| 1562 | argument is a directory name it is treated as if the nondirectory part | ||
| 1563 | of the source name were appended. Typically, a directory name is one | ||
| 1564 | that ends in @samp{/} (@pxref{Directory Names}). For example, if the | ||
| 1565 | old name is @file{a/b/c}, the @var{newname} @file{d/e/f/} is treated | ||
| 1566 | as if it were @file{d/e/f/c}. | ||
| 1567 | |||
| 1556 | In the functions that have an argument @var{newname}, if a file by the | 1568 | In the functions that have an argument @var{newname}, if a file by the |
| 1557 | name of @var{newname} already exists, the actions taken depend on the | 1569 | name of @var{newname} already exists, the actions taken depend on the |
| 1558 | value of the argument @var{ok-if-already-exists}: | 1570 | value of the argument @var{ok-if-already-exists}: |
| @@ -1570,11 +1582,6 @@ Replace the old file without confirmation if @var{ok-if-already-exists} | |||
| 1570 | is any other value. | 1582 | is any other value. |
| 1571 | @end itemize | 1583 | @end itemize |
| 1572 | 1584 | ||
| 1573 | The next four commands all recursively follow symbolic links at all | ||
| 1574 | levels of parent directories for their first argument, but, if that | ||
| 1575 | argument is itself a symbolic link, then only @code{copy-file} | ||
| 1576 | replaces it with its (recursive) target. | ||
| 1577 | |||
| 1578 | @deffn Command add-name-to-file oldname newname &optional ok-if-already-exists | 1585 | @deffn Command add-name-to-file oldname newname &optional ok-if-already-exists |
| 1579 | @cindex file with multiple names | 1586 | @cindex file with multiple names |
| 1580 | @cindex file hard link | 1587 | @cindex file hard link |
| @@ -1582,6 +1589,14 @@ This function gives the file named @var{oldname} the additional name | |||
| 1582 | @var{newname}. This means that @var{newname} becomes a new hard | 1589 | @var{newname}. This means that @var{newname} becomes a new hard |
| 1583 | link to @var{oldname}. | 1590 | link to @var{oldname}. |
| 1584 | 1591 | ||
| 1592 | If @var{newname} is a symbolic link, its directory entry is replaced, | ||
| 1593 | not the directory entry it points to. If @var{oldname} is a symbolic | ||
| 1594 | link, this function might or might not follow the link; it does not | ||
| 1595 | follow the link on GNU platforms. If @var{oldname} is a directory, | ||
| 1596 | this function typically fails, although for the superuser on a few | ||
| 1597 | old-fashioned non-GNU platforms it can succeed and create a filesystem | ||
| 1598 | that is not tree-structured. | ||
| 1599 | |||
| 1585 | In the first part of the following example, we list two files, | 1600 | In the first part of the following example, we list two files, |
| 1586 | @file{foo} and @file{foo3}. | 1601 | @file{foo} and @file{foo3}. |
| 1587 | 1602 | ||
| @@ -1649,14 +1664,34 @@ This command renames the file @var{filename} as @var{newname}. | |||
| 1649 | If @var{filename} has additional names aside from @var{filename}, it | 1664 | If @var{filename} has additional names aside from @var{filename}, it |
| 1650 | continues to have those names. In fact, adding the name @var{newname} | 1665 | continues to have those names. In fact, adding the name @var{newname} |
| 1651 | with @code{add-name-to-file} and then deleting @var{filename} has the | 1666 | with @code{add-name-to-file} and then deleting @var{filename} has the |
| 1652 | same effect as renaming, aside from momentary intermediate states. | 1667 | same effect as renaming, aside from momentary intermediate states and |
| 1668 | treatment of errors, directories and symbolic links. | ||
| 1669 | |||
| 1670 | This command does not follow symbolic links. If @var{filename} is a | ||
| 1671 | symbolic link, this command renames the symbolic link, not the file it | ||
| 1672 | points to. If @var{newname} is a symbolic link, its directory entry | ||
| 1673 | is replaced, not the directory entry it points to. | ||
| 1674 | |||
| 1675 | This command does nothing if @var{filename} and @var{newname} are the | ||
| 1676 | same directory entry, i.e., if they refer to the same parent directory | ||
| 1677 | and give the same name within that directory. Otherwise, if | ||
| 1678 | @var{filename} and @var{newname} name the same file, this command does | ||
| 1679 | nothing on POSIX-conforming systems, and removes @var{filename} on | ||
| 1680 | some non-POSIX systems. | ||
| 1681 | |||
| 1682 | If @var{newname} exists, then it must be an empty directory if | ||
| 1683 | @var{oldname} is a directory and a non-directory otherwise. | ||
| 1653 | @end deffn | 1684 | @end deffn |
| 1654 | 1685 | ||
| 1655 | @deffn Command copy-file oldname newname &optional ok-if-already-exists time preserve-uid-gid preserve-extended-attributes | 1686 | @deffn Command copy-file oldname newname &optional ok-if-already-exists time preserve-uid-gid preserve-extended-attributes |
| 1656 | This command copies the file @var{oldname} to @var{newname}. An | 1687 | This command copies the file @var{oldname} to @var{newname}. An |
| 1657 | error is signaled if @var{oldname} does not exist. If @var{newname} | 1688 | error is signaled if @var{oldname} is not a regular file. If @var{newname} |
| 1658 | names a directory, it copies @var{oldname} into that directory, | 1689 | names a directory, it copies @var{oldname} into that directory, |
| 1659 | preserving its final name component. | 1690 | preserving its final name component. |
| 1691 | @c FIXME: See Bug#27986 for how the previous sentence might change. | ||
| 1692 | |||
| 1693 | This function follows symbolic links, except that it does not follow a | ||
| 1694 | dangling symbolic link to create @var{newname}. | ||
| 1660 | 1695 | ||
| 1661 | If @var{time} is non-@code{nil}, then this function gives the new file | 1696 | If @var{time} is non-@code{nil}, then this function gives the new file |
| 1662 | the same last-modified time that the old one has. (This works on only | 1697 | the same last-modified time that the old one has. (This works on only |
| @@ -1689,7 +1724,11 @@ SELinux context are not copied over in either case. | |||
| 1689 | @kindex file-already-exists | 1724 | @kindex file-already-exists |
| 1690 | This command makes a symbolic link to @var{filename}, named | 1725 | This command makes a symbolic link to @var{filename}, named |
| 1691 | @var{newname}. This is like the shell command @samp{ln -s | 1726 | @var{newname}. This is like the shell command @samp{ln -s |
| 1692 | @var{filename} @var{newname}}. | 1727 | @var{filename} @var{newname}}. The @var{filename} argument |
| 1728 | is treated only as a string; it need not name an existing file. | ||
| 1729 | If @var{filename} is a relative file name, the resulting symbolic link | ||
| 1730 | is interpreted relative to the directory containing the symbolic link. | ||
| 1731 | @xref{Relative File Names}. | ||
| 1693 | 1732 | ||
| 1694 | This function is not available on systems that don't support symbolic | 1733 | This function is not available on systems that don't support symbolic |
| 1695 | links. | 1734 | links. |
| @@ -1702,8 +1741,7 @@ links. | |||
| 1702 | This command deletes the file @var{filename}. If the file has | 1741 | This command deletes the file @var{filename}. If the file has |
| 1703 | multiple names, it continues to exist under the other names. If | 1742 | multiple names, it continues to exist under the other names. If |
| 1704 | @var{filename} is a symbolic link, @code{delete-file} deletes only the | 1743 | @var{filename} is a symbolic link, @code{delete-file} deletes only the |
| 1705 | symbolic link and not its target (though it does follow symbolic links | 1744 | symbolic link and not its target. |
| 1706 | at all levels of parent directories). | ||
| 1707 | 1745 | ||
| 1708 | A suitable kind of @code{file-error} error is signaled if the file | 1746 | A suitable kind of @code{file-error} error is signaled if the file |
| 1709 | does not exist, or is not deletable. (On Unix and GNU/Linux, a file | 1747 | does not exist, or is not deletable. (On Unix and GNU/Linux, a file |
| @@ -1724,8 +1762,7 @@ See also @code{delete-directory} in @ref{Create/Delete Dirs}. | |||
| 1724 | @cindex file modes, setting | 1762 | @cindex file modes, setting |
| 1725 | @deffn Command set-file-modes filename mode | 1763 | @deffn Command set-file-modes filename mode |
| 1726 | This function sets the @dfn{file mode} (or @dfn{permissions}) of | 1764 | This function sets the @dfn{file mode} (or @dfn{permissions}) of |
| 1727 | @var{filename} to @var{mode}. It recursively follows symbolic links | 1765 | @var{filename} to @var{mode}. This function follows symbolic links. |
| 1728 | at all levels for @var{filename}. | ||
| 1729 | 1766 | ||
| 1730 | If called non-interactively, @var{mode} must be an integer. Only the | 1767 | If called non-interactively, @var{mode} must be an integer. Only the |
| 1731 | lowest 12 bits of the integer are used; on most systems, only the | 1768 | lowest 12 bits of the integer are used; on most systems, only the |