]> git.pld-linux.org Git - packages/coreutils.git/blob - coreutils-install-C.patch
- rel 1
[packages/coreutils.git] / coreutils-install-C.patch
1 diff -Nur coreutils-4.5.3.orig/doc/coreutils.texi coreutils-4.5.3/doc/coreutils.texi
2 --- coreutils-4.5.3.orig/doc/coreutils.texi     Sun Oct 27 22:19:34 2002
3 +++ coreutils-4.5.3/doc/coreutils.texi  Sun Oct 27 22:48:17 2002
4 @@ -6188,6 +6188,11 @@
5  @xref{Backup options}.
6  Make a backup of each file that would otherwise be overwritten or removed.
7  
8 +@item -C
9 +@opindex -C
10 +Install file, unless target already exists and is the same file, in which
11 +case the modification time is not changed.
12 +
13  @item -c
14  @opindex -c
15  Ignored; for compatibility with old Unix versions of @command{install}.
16 --- coreutils-6.10/src/install.c.orig   2008-01-05 23:59:11.000000000 +0100
17 +++ coreutils-6.10/src/install.c        2008-03-02 02:21:08.251625392 +0100
18 @@ -20,6 +20,7 @@
19  #include <stdio.h>
20  #include <getopt.h>
21  #include <sys/types.h>
22 +#include <sys/mman.h>
23  #include <signal.h>
24  #include <pwd.h>
25  #include <grp.h>
26 @@ -123,6 +124,9 @@
27     or S_ISGID bits.  */
28  static mode_t dir_mode_bits = CHMOD_MODE_BITS;
29  
30 +/* Compare files before installing (-C) */
31 +static int docompare=0;
32 +
33  /* If true, strip executable files after copying them. */
34  static bool strip_files;
35  
36 @@ -160,6 +164,82 @@
37    {NULL, 0, NULL, 0}
38  };
39  
40 +int compare (const char *file, const char *to)
41 +{
42 +  void *p, *q;
43 +  int ret=0;
44 +  size_t size;
45 +  int done=0;
46 +  struct stat file_s, to_s;
47 +  int file_fd, to_fd;
48 +  
49 +  stat(file, &file_s);
50 +  stat(to, &to_s);
51 +  
52 +  if (file_s.st_size != to_s.st_size)
53 +    return 1;
54 +
55 +  file_fd = open(file, O_RDONLY);
56 +  if (file_fd < 0)
57 +    return 1;
58 +  
59 +  to_fd = open(to, O_RDONLY);
60 +  if (to_fd < 0)
61 +    {
62 +      close(file_fd);
63 +      return 1;
64 +    }
65 +      
66 +  size = (size_t) file_s.st_size;
67 +  if (size <= 4194309) /* Don't try to mmap() files > 4 MB */
68 +    {
69 +      p = mmap(NULL, size, PROT_READ, MAP_SHARED, file_fd, (off_t) 0);
70 +      if (p != MAP_FAILED)
71 +       {
72 +          q = mmap(NULL, size, PROT_READ, MAP_SHARED, to_fd, (off_t) 0);
73 +          if (q == MAP_FAILED)
74 +            {
75 +              munmap(p, size);
76 +            }
77 +         else
78 +            {
79 +              ret = (memcmp(p, q, size)==0) ? 0 : 1;
80 +              munmap(p, size);
81 +              munmap(q, size);
82 +              done = 1;
83 +            }
84 +       }
85 +    }
86 +  if (!done)
87 +    {
88 +      char buf1[65536], buf2[65536];
89 +      int n1, n2;
90 +
91 +      lseek(file_fd, 0, SEEK_SET);
92 +      lseek(to_fd, 0, SEEK_SET);
93 +      while (ret == 0)
94 +        {
95 +          n1 = read(file_fd, buf1, sizeof(buf1));
96 +          if (n1 == 0)
97 +            break;
98 +          else if (n1 > 0)
99 +            {
100 +              n2 = read(to_fd, buf2, n1);
101 +              if (n2 == n1)
102 +                ret = memcmp(buf1, buf2, n1);
103 +              else
104 +                ret = 1; /* ouf of sync */
105 +            }
106 +          else
107 +            ret = 1; /* read failure */
108 +        }
109 +    }
110 +
111 +  close(file_fd);
112 +  close(to_fd);
113 +  return ret;
114 +}
115 +
116  static void
117  cp_option_init (struct cp_options *x)
118  {
119 @@ -345,7 +425,7 @@
120       we'll actually use backup_suffix_string.  */
121    backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
122  
123 -  while ((optc = getopt_long (argc, argv, "bcsDdg:m:o:pt:TvS:Z:", long_options,
124 +  while ((optc = getopt_long (argc, argv, "bCcsDdg:m:o:pt:TvS:Z:", long_options,
125                               NULL)) != -1)
126      {
127        switch (optc)
128 @@ -357,6 +437,9 @@
129           break;
130         case 'c':
131           break;
132 +       case 'C':
133 +         docompare=1;
134 +         break;
135         case 's':
136           strip_files = true;
137  #ifdef SIGCHLD
138 @@ -627,6 +710,12 @@
139       However, since !x->recursive, the call to "copy" will fail if FROM
140       is a directory.  */
141  
142 +  if (docompare)
143 +    {
144 +      if(compare(from, to) == 0) /* Files are identical */
145 +       return true;
146 +    }
147 +  
148    return copy (from, to, false, x, &copy_into_self, NULL);
149  }
150  
151 @@ -805,6 +894,9 @@
152        --backup[=CONTROL]  make a backup of each existing destination file\n\
153    -b                  like --backup but does not accept an argument\n\
154    -c                  (ignored)\n\
155 +  -C                  install file, unless the target already exists and is the\n\
156 +                      same, in which case mtime will remain unchanged\n\
157 +                      (for compatibility with *BSD)\n\
158    -d, --directory     treat all arguments as directory names; create all\n\
159                          components of the specified directories\n\
160  "), stdout);
161 --- coreutils-6.4/po/pl.po.orig 2006-10-24 22:32:17.793354500 +0200
162 +++ coreutils-6.4/po/pl.po      2006-10-24 22:34:53.511086250 +0200
163 @@ -1854,6 +1854,9 @@
164  "argument\n"
165  "      --copy-contents          copy contents of special files when "
166  "recursive\n"
167 +"  -C                          install file, unless the target already exists and is the\n"
168 +"                                  same, in which case mtime will remain unchanged\n"
169 +"                                  (for compatibility with *BSD)\n"
170  "  -d                           same as --no-dereference --preserve=links\n"
171  msgstr ""
172  "  -a, --archive                to samo co -dpR\n"
173 @@ -1863,6 +1866,10 @@
174  "  -b                           jak --backup, ale bez podawania argumentu\n"
175  "      --copy-contents          kopiowanie zawartości pliku specjalnego w\n"
176  "                               przypadku rekursji\n"
177 + "  -c                  (ignorowane)\n"
178 +"  -C                          instalowanie pliku, chyba że plik docelowy już istnieje\n"
179 +"                                  i jest taki sam - wtedy mtime pozostanie nie zmieniony\n"
180 +"                                  (dla kompatybilności z *BSD)\n"
181  "  -d                           to samo co --no-dereference --preserve=link\n"
182  
183  #: src/cp.c:186
This page took 0.048971 seconds and 3 git commands to generate.