Пример #1
0
static int
do_link (const char *source, const char *dest)
{
  struct stat source_stats;
  struct stat dest_stats;
  char *dest_backup = NULL;
  int lstat_status;
  int backup_succeeded = 0;

  /* Use stat here instead of lstat.
     On SVR4, link does not follow symlinks, so this check disallows
     making hard links to symlinks that point to directories.  Big deal.
     On other systems, link follows symlinks, so this check is right.  */
  if (!symbolic_link)
    {
      if (STAT_LIKE_LINK (source, &source_stats) != 0)
	{
	  error (0, errno, _("accessing %s"), quote (source));
	  return 1;
	}

      if (S_ISLNK (source_stats.st_mode))
	{
	  error (0, 0, _("%s: warning: making a hard link to a symbolic link\
 is not portable"),
		 quote (source));
	}

      if (!hard_dir_link && S_ISDIR (source_stats.st_mode))
	{
	  error (0, 0, _("%s: hard link not allowed for directory"),
		 quote (source));
	  return 1;
	}
    }
Пример #2
0
static bool
do_link (const char *source, const char *dest)
{
  struct stat source_stats;
  struct stat dest_stats;
  char *dest_backup = NULL;
  bool dest_lstat_ok = false;
  bool source_is_dir = false;
  bool ok;

  /* Use stat here instead of lstat.
     On SVR4, link does not follow symlinks, so this check disallows
     making hard links to symlinks that point to directories.  Big deal.
     On other systems, link follows symlinks, so this check is right.  */
  if (!symbolic_link)
    {
      if (STAT_LIKE_LINK (source, &source_stats) != 0)
	{
	  error (0, errno, _("accessing %s"), quote (source));
	  return false;
	}

      if (ENABLE_HARD_LINK_TO_SYMLINK_WARNING
	  && S_ISLNK (source_stats.st_mode))
	{
	  error (0, 0, _("%s: warning: making a hard link to a symbolic link\
 is not portable"),
		 quote (source));
	}

      if (S_ISDIR (source_stats.st_mode))
	{
	  source_is_dir = true;
	  if (! hard_dir_link)
	    {
	      error (0, 0, _("%s: hard link not allowed for directory"),
		     quote (source));
	      return false;
	    }
	}
    }