mirror of
git://git.sv.gnu.org/coreutils
synced 2026-06-22 16:40:34 -04:00
maint: prefer issymlink to readlink with a small buffer
* bootstrap.conf (gnulib_modules): Add issymlink and issymlinkat. * src/copy.c: Include issymlink.h. (copy_reg): Use issymlink instead of readlinkat. * src/rmdir.c: Include issymlink.h. (main): Use issymlink instead of readlink. * src/tail.c: Include issymlink.h. (recheck, any_symlinks): Use issymlink instead of readlink. * src/test.c: Include issymlink.h. (unary_operator): Use issymlink instead of readlink.
This commit is contained in:
@@ -152,6 +152,8 @@ gnulib_modules="
|
||||
isapipe
|
||||
isatty
|
||||
isblank
|
||||
issymlink
|
||||
issymlinkat
|
||||
largefile
|
||||
lchmod
|
||||
ldtoastr
|
||||
|
||||
+3
-3
@@ -49,6 +49,7 @@
|
||||
#include "hashcode-file.h"
|
||||
#include "ignore-value.h"
|
||||
#include "ioblksize.h"
|
||||
#include "issymlink.h"
|
||||
#include "quote.h"
|
||||
#include "renameatu.h"
|
||||
#include "root-uid.h"
|
||||
@@ -1444,7 +1445,7 @@ copy_reg (char const *src_name, char const *dst_name,
|
||||
|
||||
/* When trying to copy through a dangling destination symlink,
|
||||
the above open fails with EEXIST. If that happens, and
|
||||
readlinkat shows that it is a symlink, then we
|
||||
issymlinkat shows that it is a symlink, then we
|
||||
have a problem: trying to resolve this dangling symlink to
|
||||
a directory/destination-entry pair is fundamentally racy,
|
||||
so punt. If x->open_dangling_dest_symlink is set (cp sets
|
||||
@@ -1454,8 +1455,7 @@ copy_reg (char const *src_name, char const *dst_name,
|
||||
only when copying, i.e., not in move_mode. */
|
||||
if (dest_desc < 0 && dest_errno == EEXIST && ! x->move_mode)
|
||||
{
|
||||
char dummy[1];
|
||||
if (0 <= readlinkat (dst_dirfd, dst_relname, dummy, sizeof dummy))
|
||||
if (issymlinkat (dst_dirfd, dst_relname) == 1)
|
||||
{
|
||||
if (x->open_dangling_dest_symlink)
|
||||
{
|
||||
|
||||
+2
-2
@@ -28,6 +28,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "system.h"
|
||||
#include "issymlink.h"
|
||||
#include "prog-fprintf.h"
|
||||
|
||||
/* The official name of this program (e.g., no 'g' prefix). */
|
||||
@@ -269,8 +270,7 @@ main (int argc, char **argv)
|
||||
/* Ensure the last component was a symlink. */
|
||||
char *dir_arg = xstrdup (dir);
|
||||
strip_trailing_slashes (dir);
|
||||
char linkbuf[1];
|
||||
if (0 <= readlink (dir, linkbuf, 1))
|
||||
if (issymlink (dir) == 1)
|
||||
{
|
||||
error (0, 0,
|
||||
_("failed to remove %s:"
|
||||
|
||||
+3
-4
@@ -39,6 +39,7 @@
|
||||
#include "fcntl--.h"
|
||||
#include "iopoll.h"
|
||||
#include "isapipe.h"
|
||||
#include "issymlink.h"
|
||||
#include "posixver.h"
|
||||
#include "quote.h"
|
||||
#include "stat-size.h"
|
||||
@@ -976,8 +977,7 @@ recheck (struct File_spec *f, bool blocking)
|
||||
|
||||
affirm (valid_file_spec (f));
|
||||
|
||||
char linkbuf[1];
|
||||
if (! disable_inotify && 0 <= readlink (f->name, linkbuf, 1))
|
||||
if (! disable_inotify && issymlink (f->name) == 1)
|
||||
{
|
||||
/* Diagnose the edge case where a regular file is changed
|
||||
to a symlink. We avoid inotify with symlinks since
|
||||
@@ -1350,9 +1350,8 @@ any_non_remote_file (const struct File_spec *f, int n_files)
|
||||
static bool
|
||||
any_symlinks (const struct File_spec *f, int n_files)
|
||||
{
|
||||
char linkbuf[1];
|
||||
for (int i = 0; i < n_files; i++)
|
||||
if (0 <= readlink (f[i].name, linkbuf, 1))
|
||||
if (issymlink (f[i].name) == 1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
+2
-2
@@ -41,6 +41,7 @@
|
||||
#include "system.h"
|
||||
#include "assure.h"
|
||||
#include "c-ctype.h"
|
||||
#include "issymlink.h"
|
||||
#include "quote.h"
|
||||
#include "stat-time.h"
|
||||
#include "strnumcmp.h"
|
||||
@@ -467,8 +468,7 @@ unary_operator (void)
|
||||
|
||||
case 'h': /* File is a symbolic link? */
|
||||
unary_advance ();
|
||||
char linkbuf[1];
|
||||
return 0 <= readlink (argv[pos - 1], linkbuf, 1);
|
||||
return issymlink (argv[pos - 1]) == 1;
|
||||
|
||||
case 'u': /* File is setuid? */
|
||||
unary_advance ();
|
||||
|
||||
Reference in New Issue
Block a user