0001-cp-don-t-reserve-a-device-number.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. From d0294ff3b90430750a631556277c75f1a555dd44 Mon Sep 17 00:00:00 2001
  2. From: Paul Eggert <eggert@cs.ucla.edu>
  3. Date: Thu, 3 Apr 2014 09:48:22 -0700
  4. Subject: [PATCH] cp: don't reserve a device number
  5. * src/copy.c (copy_internal): Replace dev_t arg DEVICE with struct
  6. stat pointer arg PARENT. All callers changed. This removes an
  7. unwarranted assumption that dev_t values of 0 cannot occur in file
  8. systems. See: http://bugs.gnu.org/17179
  9. ---
  10. src/copy.c | 15 +++++++--------
  11. 1 file changed, 7 insertions(+), 8 deletions(-)
  12. diff --git a/src/copy.c b/src/copy.c
  13. index 781cc1e..d471a77 100644
  14. --- a/src/copy.c
  15. +++ b/src/copy.c
  16. @@ -117,7 +117,7 @@ struct dir_list
  17. #define DEST_INFO_INITIAL_CAPACITY 61
  18. static bool copy_internal (char const *src_name, char const *dst_name,
  19. - bool new_dst, dev_t device,
  20. + bool new_dst, struct stat const *parent,
  21. struct dir_list *ancestors,
  22. const struct cp_options *x,
  23. bool command_line_arg,
  24. @@ -621,7 +621,7 @@ copy_dir (char const *src_name_in, char const *dst_name_in, bool new_dst,
  25. char *dst_name = file_name_concat (dst_name_in, namep, NULL);
  26. bool first_dir_created = *first_dir_created_per_command_line_arg;
  27. - ok &= copy_internal (src_name, dst_name, new_dst, src_sb->st_dev,
  28. + ok &= copy_internal (src_name, dst_name, new_dst, src_sb,
  29. ancestors, &non_command_line_options, false,
  30. &first_dir_created,
  31. &local_copy_into_self, NULL);
  32. @@ -1725,9 +1725,8 @@ should_dereference (const struct cp_options *x, bool command_line_arg)
  33. /* Copy the file SRC_NAME to the file DST_NAME. The files may be of
  34. any type. NEW_DST should be true if the file DST_NAME cannot
  35. exist because its parent directory was just created; NEW_DST should
  36. - be false if DST_NAME might already exist. DEVICE is the device
  37. - number of the parent directory, or 0 if the parent of this file is
  38. - not known. ANCESTORS points to a linked, null terminated list of
  39. + be false if DST_NAME might already exist. A nonnull PARENT describes the
  40. + parent directory. ANCESTORS points to a linked, null terminated list of
  41. devices and inodes of parent directories of SRC_NAME. COMMAND_LINE_ARG
  42. is true iff SRC_NAME was specified on the command line.
  43. FIRST_DIR_CREATED_PER_COMMAND_LINE_ARG is both input and output.
  44. @@ -1737,7 +1736,7 @@ should_dereference (const struct cp_options *x, bool command_line_arg)
  45. static bool
  46. copy_internal (char const *src_name, char const *dst_name,
  47. bool new_dst,
  48. - dev_t device,
  49. + struct stat const *parent,
  50. struct dir_list *ancestors,
  51. const struct cp_options *x,
  52. bool command_line_arg,
  53. @@ -2434,7 +2433,7 @@ copy_internal (char const *src_name, char const *dst_name,
  54. }
  55. /* Decide whether to copy the contents of the directory. */
  56. - if (x->one_file_system && device != 0 && device != src_sb.st_dev)
  57. + if (x->one_file_system && parent && parent->st_dev != src_sb.st_dev)
  58. {
  59. /* Here, we are crossing a file system boundary and cp's -x option
  60. is in effect: so don't copy the contents of this directory. */
  61. @@ -2827,7 +2826,7 @@ copy (char const *src_name, char const *dst_name,
  62. top_level_dst_name = dst_name;
  63. bool first_dir_created_per_command_line_arg = false;
  64. - return copy_internal (src_name, dst_name, nonexistent_dst, 0, NULL,
  65. + return copy_internal (src_name, dst_name, nonexistent_dst, NULL, NULL,
  66. options, true,
  67. &first_dir_created_per_command_line_arg,
  68. copy_into_self, rename_succeeded);
  69. --
  70. 1.9.1