]> Dogcows Code - chaz/tar/blob - src/create.c
(to_oct): New parameter substitute, giving a substitute value to use
[chaz/tar] / src / create.c
1 /* Create a tar archive.
2 Copyright 1985, 92, 93, 94, 96, 97, 1999 Free Software Foundation, Inc.
3 Written by John Gilmore, on 1985-08-25.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any later
8 version.
9
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 59 Place - Suite 330, Boston, MA 02111-1307, USA. */
18
19 #include "system.h"
20
21 #if !MSDOS
22 # include <pwd.h>
23 # include <grp.h>
24 #endif
25
26 #if HAVE_UTIME_H
27 # include <utime.h>
28 #else
29 struct utimbuf
30 {
31 long actime;
32 long modtime;
33 };
34 #endif
35
36 #include "common.h"
37
38 #ifndef MSDOS
39 extern dev_t ar_dev;
40 extern ino_t ar_ino;
41 #endif
42
43 extern struct name *gnu_list_name;
44
45 /* This module is the only one that cares about `struct link's. */
46
47 struct link
48 {
49 struct link *next;
50 dev_t dev;
51 ino_t ino;
52 short linkcount;
53 char name[1];
54 };
55
56 struct link *linklist = NULL; /* points to first link in list */
57 \f
58
59 /*------------------------------------------------------------------------.
60 | Convert VALUE (with substitute SUBSTITUTE if VALUE is out of range) |
61 | into a size-SIZE field at WHERE, including a |
62 | trailing space. For example, 3 for SIZE means two digits and a space. |
63 | |
64 | We assume the trailing NUL is already there and don't fill it in. This |
65 | fact is used by start_header and finish_header, so don't change it! |
66 `------------------------------------------------------------------------*/
67
68 /* This should be equivalent to: sprintf (WHERE, "%*lo", SIZE, VALUE);
69 except that we don't assume VALUE fits in an unsigned long, and
70 except that sprintf fills in the trailing NUL and we don't. */
71
72 static void
73 to_oct (uintmax_t value, uintmax_t substitute, char *where, size_t size, const char *type)
74 {
75 uintmax_t v = value;
76 size_t i = size;
77
78 /* Produce the digits -- at least one. */
79
80 do
81 {
82 where[--i] = '0' + (int) (v & 7); /* one octal digit */
83 v >>= 3;
84 }
85 while (i != 0 && v != 0);
86
87 /* Leading spaces, if necessary. */
88 while (i != 0)
89 where[--i] = ' ';
90
91 if (v != 0)
92 {
93 int bits = size * 3;
94 uintmax_t maxval = (bits < sizeof (uintmax_t) * CHAR_BIT
95 ? ((uintmax_t) 1 << bits) - 1
96 : (uintmax_t) -1);
97 char buf1[UINTMAX_STRSIZE_BOUND];
98 char buf2[UINTMAX_STRSIZE_BOUND];
99 char buf3[UINTMAX_STRSIZE_BOUND];
100 char *value_string = STRINGIFY_BIGINT (value, buf1);
101 char *maxval_string = STRINGIFY_BIGINT (maxval, buf2);
102 if (substitute)
103 {
104 substitute &= maxval;
105 WARN ((0, 0, _("%s value %s too large (max=%s); substituting %s"),
106 type, value_string, maxval_string,
107 STRINGIFY_BIGINT (substitute, buf3)));
108 to_oct (substitute, (uintmax_t) 0, where, size, type);
109 }
110 else
111 ERROR ((0, 0, _("%s value %s too large (max=%s)"),
112 type, value_string, maxval_string));
113 }
114 }
115 #ifndef GID_NOBODY
116 #define GID_NOBODY 0
117 #endif
118 void
119 gid_to_oct (gid_t v, char *p, size_t s)
120 {
121 to_oct ((uintmax_t) v, (uintmax_t) GID_NOBODY, p, s, "gid_t");
122 }
123 void
124 major_to_oct (major_t v, char *p, size_t s)
125 {
126 to_oct ((uintmax_t) v, (uintmax_t) 0, p, s, "major_t");
127 }
128 void
129 minor_to_oct (minor_t v, char *p, size_t s)
130 {
131 to_oct ((uintmax_t) v, (uintmax_t) 0, p, s, "minor_t");
132 }
133 void
134 mode_to_oct (mode_t v, char *p, size_t s)
135 {
136 to_oct ((uintmax_t) v, (uintmax_t) 0, p, s, "mode_t");
137 }
138 void
139 off_to_oct (off_t v, char *p, size_t s)
140 {
141 to_oct ((uintmax_t) v, (uintmax_t) 0, p, s, "off_t");
142 }
143 void
144 size_to_oct (size_t v, char *p, size_t s)
145 {
146 to_oct ((uintmax_t) v, (uintmax_t) 0, p, s, "size_t");
147 }
148 void
149 time_to_oct (time_t v, char *p, size_t s)
150 {
151 to_oct ((uintmax_t) v, (uintmax_t) 0, p, s, "time_t");
152 }
153 #ifndef UID_NOBODY
154 #define UID_NOBODY 0
155 #endif
156 void
157 uid_to_oct (uid_t v, char *p, size_t s)
158 {
159 to_oct ((uintmax_t) v, (uintmax_t) UID_NOBODY, p, s, "uid_t");
160 }
161 void
162 uintmax_to_oct (uintmax_t v, char *p, size_t s)
163 {
164 to_oct (v, (uintmax_t) 0, p, s, "uintmax_t");
165 }
166 \f
167 /* Writing routines. */
168
169 /*-----------------------------------------------------------------------.
170 | Just zeroes out the buffer so we don't confuse ourselves with leftover |
171 | data. |
172 `-----------------------------------------------------------------------*/
173
174 static void
175 clear_buffer (char *buffer)
176 {
177 memset (buffer, 0, BLOCKSIZE);
178 }
179
180 /*-------------------------------------------------------------------------.
181 | Write the EOT block(s). We actually zero at least one block, through |
182 | the end of the record. Old tar, as previous versions of GNU tar, writes |
183 | garbage after two zeroed blocks. |
184 `-------------------------------------------------------------------------*/
185
186 void
187 write_eot (void)
188 {
189 union block *pointer = find_next_block ();
190
191 if (pointer)
192 {
193 size_t space = available_space_after (pointer);
194
195 memset (pointer->buffer, 0, space);
196 set_next_block_after (pointer);
197 }
198 }
199
200 /*-----------------------------------------------------.
201 | Write a GNUTYPE_LONGLINK or GNUTYPE_LONGNAME block. |
202 `-----------------------------------------------------*/
203
204 /* FIXME: Cross recursion between start_header and write_long! */
205
206 static union block *start_header PARAMS ((const char *, struct stat *));
207
208 static void
209 write_long (const char *p, char type)
210 {
211 size_t size = strlen (p) + 1;
212 size_t bufsize;
213 union block *header;
214 struct stat foo;
215
216 memset (&foo, 0, sizeof foo);
217 foo.st_size = size;
218
219 header = start_header ("././@LongLink", &foo);
220 header->header.typeflag = type;
221 finish_header (header);
222
223 header = find_next_block ();
224
225 bufsize = available_space_after (header);
226
227 while (bufsize < size)
228 {
229 memcpy (header->buffer, p, bufsize);
230 p += bufsize;
231 size -= bufsize;
232 set_next_block_after (header + (bufsize - 1) / BLOCKSIZE);
233 header = find_next_block ();
234 bufsize = available_space_after (header);
235 }
236 memcpy (header->buffer, p, size);
237 memset (header->buffer + size, 0, bufsize - size);
238 set_next_block_after (header + (size - 1) / BLOCKSIZE);
239 }
240 \f
241 /* Header handling. */
242
243 /*---------------------------------------------------------------------.
244 | Make a header block for the file name whose stat info is st. Return |
245 | header pointer for success, NULL if the name is too long. |
246 `---------------------------------------------------------------------*/
247
248 static union block *
249 start_header (const char *name, struct stat *st)
250 {
251 union block *header;
252
253 if (!absolute_names_option)
254 {
255 static int warned_once = 0;
256
257 #if MSDOS
258 if (name[1] == ':')
259 {
260 name += 2;
261 if (!warned_once)
262 {
263 warned_once = 1;
264 WARN ((0, 0, _("Removing drive spec from names in the archive")));
265 }
266 }
267 #endif
268
269 while (*name == '/')
270 {
271 name++; /* force relative path */
272 if (!warned_once)
273 {
274 warned_once = 1;
275 WARN ((0, 0, _("\
276 Removing leading `/' from absolute path names in the archive")));
277 }
278 }
279 }
280
281 /* Check the file name and put it in the block. */
282
283 if (strlen (name) >= (size_t) NAME_FIELD_SIZE)
284 write_long (name, GNUTYPE_LONGNAME);
285 header = find_next_block ();
286 memset (header->buffer, 0, sizeof (union block));
287
288 assign_string (&current_file_name, name);
289
290 strncpy (header->header.name, name, NAME_FIELD_SIZE);
291 header->header.name[NAME_FIELD_SIZE - 1] = '\0';
292
293 /* Override some stat fields, if requested to do so. */
294
295 if (owner_option != (uid_t) -1)
296 st->st_uid = owner_option;
297 if (group_option != (gid_t) -1)
298 st->st_gid = group_option;
299 if (mode_option)
300 st->st_mode = ((st->st_mode & S_IFMT)
301 | mode_adjust (st->st_mode, mode_option));
302
303 /* Paul Eggert tried the trivial test ($WRITER cf a b; $READER tvf a)
304 for a few tars and came up with the following interoperability
305 matrix:
306
307 WRITER
308 1 2 3 4 5 6 7 8 9 READER
309 . . . . . . . . . 1 = SunOS 4.2 tar
310 # . . # # . . # # 2 = NEC SVR4.0.2 tar
311 . . . # # . . # . 3 = Solaris 2.1 tar
312 . . . . . . . . . 4 = GNU tar 1.11.1
313 . . . . . . . . . 5 = HP-UX 8.07 tar
314 . . . . . . . . . 6 = Ultrix 4.1
315 . . . . . . . . . 7 = AIX 3.2
316 . . . . . . . . . 8 = Hitachi HI-UX 1.03
317 . . . . . . . . . 9 = Omron UNIOS-B 4.3BSD 1.60Beta
318
319 . = works
320 # = ``impossible file type''
321
322 The following mask for old archive removes the `#'s in column 4
323 above, thus making GNU tar both a universal donor and a universal
324 acceptor for Paul's test. */
325
326 if (archive_format == V7_FORMAT)
327 MODE_TO_OCT (st->st_mode & 07777, header->header.mode);
328 else
329 MODE_TO_OCT (st->st_mode, header->header.mode);
330
331 UID_TO_OCT (st->st_uid, header->header.uid);
332 GID_TO_OCT (st->st_gid, header->header.gid);
333 OFF_TO_OCT (st->st_size, header->header.size);
334 TIME_TO_OCT (st->st_mtime, header->header.mtime);
335
336 if (incremental_option)
337 if (archive_format == OLDGNU_FORMAT)
338 {
339 TIME_TO_OCT (st->st_atime, header->oldgnu_header.atime);
340 TIME_TO_OCT (st->st_ctime, header->oldgnu_header.ctime);
341 }
342
343 header->header.typeflag = archive_format == V7_FORMAT ? AREGTYPE : REGTYPE;
344
345 switch (archive_format)
346 {
347 case DEFAULT_FORMAT:
348 case V7_FORMAT:
349 break;
350
351 case OLDGNU_FORMAT:
352 /* Overwrite header->header.magic and header.version in one blow. */
353 strcpy (header->header.magic, OLDGNU_MAGIC);
354 break;
355
356 case POSIX_FORMAT:
357 case GNU_FORMAT:
358 strncpy (header->header.magic, TMAGIC, TMAGLEN);
359 strncpy (header->header.version, TVERSION, TVERSLEN);
360 break;
361 }
362
363 if (archive_format == V7_FORMAT || numeric_owner_option)
364 {
365 /* header->header.[ug]name are left as the empty string. */
366 }
367 else
368 {
369 uid_to_uname (st->st_uid, header->header.uname);
370 gid_to_gname (st->st_gid, header->header.gname);
371 }
372
373 return header;
374 }
375
376 /*-------------------------------------------------------------------------.
377 | Finish off a filled-in header block and write it out. We also print the |
378 | file name and/or full info if verbose is on. |
379 `-------------------------------------------------------------------------*/
380
381 void
382 finish_header (union block *header)
383 {
384 size_t i;
385 int sum;
386 char *p;
387
388 memcpy (header->header.chksum, CHKBLANKS, sizeof (header->header.chksum));
389
390 sum = 0;
391 p = header->buffer;
392 for (i = sizeof (*header); i-- != 0; )
393 /* We can't use unsigned char here because of old compilers, e.g. V7. */
394 sum += 0xFF & *p++;
395
396 /* Fill in the checksum field. It's formatted differently from the
397 other fields: it has [6] digits, a null, then a space -- rather than
398 digits, then a null. We use to_oct then write the null.
399 The final space is already there, from checksumming,
400 and to_oct doesn't modify it.
401
402 This is a fast way to do:
403
404 sprintf(header->header.chksum, "%6o", sum); */
405
406 uintmax_to_oct ((uintmax_t) sum, header->header.chksum, 6);
407 header->header.chksum[6] = '\0';
408
409 set_next_block_after (header);
410
411 if (verbose_option
412 && header->header.typeflag != GNUTYPE_LONGLINK
413 && header->header.typeflag != GNUTYPE_LONGNAME)
414 {
415 /* These globals are parameters to print_header, sigh. */
416
417 current_header = header;
418 /* current_stat is already set up. */
419 current_format = archive_format;
420 print_header ();
421 }
422 }
423 \f
424 /* Sparse file processing. */
425
426 /*-------------------------------------------------------------------------.
427 | Takes a blockful of data and basically cruises through it to see if it's |
428 | made *entirely* of zeros, returning a 0 the instant it finds something |
429 | that is a nonzero, i.e., useful data. |
430 `-------------------------------------------------------------------------*/
431
432 static int
433 zero_block_p (char *buffer)
434 {
435 int counter;
436
437 for (counter = 0; counter < BLOCKSIZE; counter++)
438 if (buffer[counter] != '\0')
439 return 0;
440 return 1;
441 }
442
443 /*---.
444 | ? |
445 `---*/
446
447 static void
448 init_sparsearray (void)
449 {
450 int counter;
451
452 sp_array_size = 10;
453
454 /* Make room for our scratch space -- initially is 10 elts long. */
455
456 sparsearray = (struct sp_array *)
457 xmalloc (sp_array_size * sizeof (struct sp_array));
458 for (counter = 0; counter < sp_array_size; counter++)
459 {
460 sparsearray[counter].offset = 0;
461 sparsearray[counter].numbytes = 0;
462 }
463 }
464
465 /*---.
466 | ? |
467 `---*/
468
469 static void
470 find_new_file_size (off_t *filesize, int highest_index)
471 {
472 int counter;
473
474 *filesize = 0;
475 for (counter = 0;
476 sparsearray[counter].numbytes && counter <= highest_index;
477 counter++)
478 *filesize += sparsearray[counter].numbytes;
479 }
480
481 /*-----------------------------------------------------------------------.
482 | Make one pass over the file NAME, studying where any non-zero data is, |
483 | that is, how far into the file each instance of data is, and how many |
484 | bytes are there. Save this information in the sparsearray, which will |
485 | later be translated into header information. |
486 `-----------------------------------------------------------------------*/
487
488 /* There is little point in trimming small amounts of null data at the head
489 and tail of blocks, only avoid dumping full null blocks. */
490
491 /* FIXME: this routine might accept bits of algorithmic cleanup, it is
492 too kludgey for my taste... */
493
494 static int
495 deal_with_sparse (char *name, union block *header)
496 {
497 size_t numbytes = 0;
498 off_t offset = 0;
499 int file;
500 int sparse_index = 0;
501 ssize_t count;
502 char buffer[BLOCKSIZE];
503
504 if (archive_format == OLDGNU_FORMAT)
505 header->oldgnu_header.isextended = 0;
506
507 if (file = open (name, O_RDONLY), file < 0)
508 /* This problem will be caught later on, so just return. */
509 return 0;
510
511 init_sparsearray ();
512 clear_buffer (buffer);
513
514 while (count = read (file, buffer, sizeof buffer), count != 0)
515 {
516 /* Realloc the scratch area as necessary. FIXME: should reallocate
517 only at beginning of a new instance of non-zero data. */
518
519 if (sparse_index > sp_array_size - 1)
520 {
521
522 sparsearray = (struct sp_array *)
523 xrealloc (sparsearray,
524 2 * sp_array_size * sizeof (struct sp_array));
525 sp_array_size *= 2;
526 }
527
528 /* Process one block. */
529
530 if (count == sizeof buffer)
531
532 if (zero_block_p (buffer))
533 {
534 if (numbytes)
535 {
536 sparsearray[sparse_index++].numbytes = numbytes;
537 numbytes = 0;
538 }
539 }
540 else
541 {
542 if (!numbytes)
543 sparsearray[sparse_index].offset = offset;
544 numbytes += count;
545 }
546
547 else
548
549 /* Since count < sizeof buffer, we have the last bit of the file. */
550
551 if (!zero_block_p (buffer))
552 {
553 if (!numbytes)
554 sparsearray[sparse_index].offset = offset;
555 numbytes += count;
556 }
557 else
558 /* The next two lines are suggested by Andreas Degert, who says
559 they are required for trailing full blocks to be written to the
560 archive, when all zeroed. Yet, it seems to me that the case
561 does not apply. Further, at restore time, the file is not as
562 sparse as it should. So, some serious cleanup is *also* needed
563 in this area. Just one more... :-(. FIXME. */
564 if (numbytes)
565 numbytes += count;
566
567 /* Prepare for next block. */
568
569 offset += count;
570 /* FIXME: do not clear unless necessary. */
571 clear_buffer (buffer);
572 }
573
574 if (numbytes)
575 sparsearray[sparse_index++].numbytes = numbytes;
576 else
577 {
578 sparsearray[sparse_index].offset = offset - 1;
579 sparsearray[sparse_index++].numbytes = 1;
580 }
581
582 close (file);
583 return sparse_index - 1;
584 }
585
586 /*---.
587 | ? |
588 `---*/
589
590 static int
591 finish_sparse_file (int file, off_t *sizeleft, off_t fullsize, char *name)
592 {
593 union block *start;
594 size_t bufsize;
595 int sparse_index = 0;
596 ssize_t count;
597
598 while (*sizeleft > 0)
599 {
600 start = find_next_block ();
601 memset (start->buffer, 0, BLOCKSIZE);
602 bufsize = sparsearray[sparse_index].numbytes;
603 if (!bufsize)
604 {
605 /* We blew it, maybe. */
606 char buf1[UINTMAX_STRSIZE_BOUND];
607 char buf2[UINTMAX_STRSIZE_BOUND];
608
609 ERROR ((0, 0, _("Wrote %s of %s bytes to file %s"),
610 STRINGIFY_BIGINT (fullsize - *sizeleft, buf1),
611 STRINGIFY_BIGINT (fullsize, buf2),
612 name));
613 break;
614 }
615
616 if (lseek (file, sparsearray[sparse_index++].offset, 0) < 0)
617 {
618 char buf[UINTMAX_STRSIZE_BOUND];
619 ERROR ((0, errno, _("lseek error at byte %s in file %s"),
620 STRINGIFY_BIGINT (sparsearray[sparse_index - 1].offset, buf),
621 name));
622 break;
623 }
624
625 /* If the number of bytes to be written here exceeds the size of
626 the temporary buffer, do it in steps. */
627
628 while (bufsize > BLOCKSIZE)
629 {
630 #if 0
631 if (amount_read)
632 {
633 count = read (file, start->buffer + amount_read,
634 BLOCKSIZE - amount_read);
635 bufsize -= BLOCKSIZE - amount_read;
636 amount_read = 0;
637 set_next_block_after (start);
638 start = find_next_block ();
639 memset (start->buffer, 0, BLOCKSIZE);
640 }
641 #endif
642 /* Store the data. */
643
644 count = read (file, start->buffer, BLOCKSIZE);
645 if (count < 0)
646 {
647 char buf[UINTMAX_STRSIZE_BOUND];
648 ERROR ((0, errno, _("\
649 Read error at byte %s, reading %lu bytes, in file %s"),
650 STRINGIFY_BIGINT (fullsize - *sizeleft, buf),
651 (unsigned long) bufsize, name));
652 return 1;
653 }
654 bufsize -= count;
655 *sizeleft -= count;
656 set_next_block_after (start);
657 start = find_next_block ();
658 memset (start->buffer, 0, BLOCKSIZE);
659 }
660
661 {
662 char buffer[BLOCKSIZE];
663
664 clear_buffer (buffer);
665 count = read (file, buffer, bufsize);
666 memcpy (start->buffer, buffer, BLOCKSIZE);
667 }
668
669 if (count < 0)
670 {
671 char buf[UINTMAX_STRSIZE_BOUND];
672
673 ERROR ((0, errno,
674 _("Read error at byte %s, reading %lu bytes, in file %s"),
675 STRINGIFY_BIGINT (fullsize - *sizeleft, buf),
676 (unsigned long) bufsize, name));
677 return 1;
678 }
679 #if 0
680 if (amount_read >= BLOCKSIZE)
681 {
682 amount_read = 0;
683 set_next_block_after (start + (count - 1) / BLOCKSIZE);
684 if (count != bufsize)
685 {
686 ERROR ((0, 0,
687 _("File %s shrunk, padding with zeros"),
688 name));
689 return 1;
690 }
691 start = find_next_block ();
692 }
693 else
694 amount_read += bufsize;
695 #endif
696 *sizeleft -= count;
697 set_next_block_after (start);
698
699 }
700 free (sparsearray);
701 #if 0
702 set_next_block_after (start + (count - 1) / BLOCKSIZE);
703 #endif
704 return 0;
705 }
706 \f
707 /* Main functions of this module. */
708
709 /*---.
710 | ? |
711 `---*/
712
713 void
714 create_archive (void)
715 {
716 char *p;
717
718 open_archive (ACCESS_WRITE);
719
720 if (incremental_option)
721 {
722 char *buffer = xmalloc (PATH_MAX);
723 const char *q;
724 char *bufp;
725
726 collect_and_sort_names ();
727
728 while (p = name_from_list (), p)
729 dump_file (p, (dev_t) -1, 1);
730
731 blank_name_list ();
732 while (p = name_from_list (), p)
733 {
734 strcpy (buffer, p);
735 if (p[strlen (p) - 1] != '/')
736 strcat (buffer, "/");
737 bufp = buffer + strlen (buffer);
738 for (q = gnu_list_name->dir_contents;
739 q && *q;
740 q += strlen (q) + 1)
741 {
742 if (*q == 'Y')
743 {
744 strcpy (bufp, q + 1);
745 dump_file (buffer, (dev_t) -1, 1);
746 }
747 }
748 }
749 free (buffer);
750 }
751 else
752 {
753 while (p = name_next (1), p)
754 dump_file (p, (dev_t) -1, 1);
755 }
756
757 write_eot ();
758 close_archive ();
759
760 if (listed_incremental_option)
761 write_dir_file ();
762 }
763
764 /*----------------------------------------------------------------------.
765 | Dump a single file. Recurse on directories. Result is nonzero for |
766 | success. P is file name to dump. PARENT_DEVICE is device our parent |
767 | directory was on. TOP_LEVEL tells wether we are a toplevel call. |
768 | |
769 | Sets global CURRENT_STAT to stat output for this file. |
770 `----------------------------------------------------------------------*/
771
772 /* FIXME: One should make sure that for *every* path leading to setting
773 exit_status to failure, a clear diagnostic has been issued. */
774
775 void
776 dump_file (char *p, dev_t parent_device, int top_level)
777 {
778 union block *header;
779 char type;
780 union block *exhdr;
781 char save_typeflag;
782 struct utimbuf restore_times;
783 off_t restore_size;
784
785 /* FIXME: `header' and `upperbound' might be used uninitialized in this
786 function. Reported by Bruno Haible. */
787
788 if (interactive_option && !confirm ("add", p))
789 return;
790
791 /* Use stat if following (rather than dumping) 4.2BSD's symbolic links.
792 Otherwise, use lstat (which falls back to stat if no symbolic links). */
793
794 if (dereference_option != 0
795 #if STX_HIDDEN && !_LARGE_FILES /* AIX */
796 ? statx (p, &current_stat, STATSIZE, STX_HIDDEN)
797 : statx (p, &current_stat, STATSIZE, STX_HIDDEN | STX_LINK)
798 #else
799 ? stat (p, &current_stat) : lstat (p, &current_stat)
800 #endif
801 )
802 {
803 WARN ((0, errno, _("Cannot add file %s"), p));
804 if (!ignore_failed_read_option)
805 exit_status = TAREXIT_FAILURE;
806 return;
807 }
808
809 restore_times.actime = current_stat.st_atime;
810 restore_times.modtime = current_stat.st_mtime;
811 restore_size = current_stat.st_size;
812
813 #ifdef S_ISHIDDEN
814 if (S_ISHIDDEN (current_stat.st_mode))
815 {
816 char *new = (char *) alloca (strlen (p) + 2);
817 if (new)
818 {
819 strcpy (new, p);
820 strcat (new, "@");
821 p = new;
822 }
823 }
824 #endif
825
826 /* See if we only want new files, and check if this one is too old to
827 put in the archive. */
828
829 if (!incremental_option && !S_ISDIR (current_stat.st_mode)
830 && current_stat.st_mtime < newer_mtime_option
831 && (!after_date_option || current_stat.st_ctime < newer_ctime_option))
832 {
833 if (parent_device == (dev_t) -1)
834 WARN ((0, 0, _("%s: is unchanged; not dumped"), p));
835 /* FIXME: recheck this return. */
836 return;
837 }
838
839 #if !MSDOS
840 /* See if we are trying to dump the archive. */
841
842 if (ar_dev && current_stat.st_dev == ar_dev && current_stat.st_ino == ar_ino)
843 {
844 WARN ((0, 0, _("%s is the archive; not dumped"), p));
845 return;
846 }
847 #endif
848
849 /* Check for multiple links.
850
851 We maintain a list of all such files that we've written so far. Any
852 time we see another, we check the list and avoid dumping the data
853 again if we've done it once already. */
854
855 if (current_stat.st_nlink > 1
856 && (S_ISREG (current_stat.st_mode)
857 #ifdef S_ISCTG
858 || S_ISCTG (current_stat.st_mode)
859 #endif
860 #ifdef S_ISCHR
861 || S_ISCHR (current_stat.st_mode)
862 #endif
863 #ifdef S_ISBLK
864 || S_ISBLK (current_stat.st_mode)
865 #endif
866 #ifdef S_ISFIFO
867 || S_ISFIFO (current_stat.st_mode)
868 #endif
869 ))
870 {
871 struct link *lp;
872
873 /* FIXME: First quick and dirty. Hashing, etc later. */
874
875 for (lp = linklist; lp; lp = lp->next)
876 if (lp->ino == current_stat.st_ino && lp->dev == current_stat.st_dev)
877 {
878 char *link_name = lp->name;
879
880 /* We found a link. */
881
882 while (!absolute_names_option && *link_name == '/')
883 {
884 static int warned_once = 0;
885
886 if (!warned_once)
887 {
888 warned_once = 1;
889 WARN ((0, 0, _("\
890 Removing leading `/' from absolute links")));
891 }
892 link_name++;
893 }
894 if (strlen (link_name) >= NAME_FIELD_SIZE)
895 write_long (link_name, GNUTYPE_LONGLINK);
896 assign_string (&current_link_name, link_name);
897
898 current_stat.st_size = 0;
899 header = start_header (p, &current_stat);
900 if (header == NULL)
901 {
902 exit_status = TAREXIT_FAILURE;
903 return;
904 }
905 strncpy (header->header.linkname,
906 link_name, NAME_FIELD_SIZE);
907
908 /* Force null truncated. */
909
910 header->header.linkname[NAME_FIELD_SIZE - 1] = 0;
911
912 header->header.typeflag = LNKTYPE;
913 finish_header (header);
914
915 /* FIXME: Maybe remove from list after all links found? */
916
917 if (remove_files_option)
918 if (unlink (p) == -1)
919 ERROR ((0, errno, _("Cannot remove %s"), p));
920
921 /* We dumped it. */
922 return;
923 }
924
925 /* Not found. Add it to the list of possible links. */
926
927 lp = (struct link *)
928 xmalloc ((size_t) (sizeof (struct link) + strlen (p)));
929 lp->ino = current_stat.st_ino;
930 lp->dev = current_stat.st_dev;
931 strcpy (lp->name, p);
932 lp->next = linklist;
933 linklist = lp;
934 }
935
936 /* This is not a link to a previously dumped file, so dump it. */
937
938 if (S_ISREG (current_stat.st_mode)
939 #ifdef S_ISCTG
940 || S_ISCTG (current_stat.st_mode)
941 #endif
942 )
943 {
944 int f; /* file descriptor */
945 size_t bufsize;
946 ssize_t count;
947 off_t sizeleft;
948 union block *start;
949 int header_moved;
950 char isextended = 0;
951 int upperbound;
952 #if 0
953 static int cried_once = 0;
954 #endif
955
956 header_moved = 0;
957
958 if (sparse_option)
959 {
960 /* Check the size of the file against the number of blocks
961 allocated for it, counting both data and indirect blocks.
962 If there is a smaller number of blocks that would be
963 necessary to accommodate a file of this size, this is safe
964 to say that we have a sparse file: at least one of those
965 blocks in the file is just a useless hole. For sparse
966 files not having more hole blocks than indirect blocks, the
967 sparseness will go undetected. */
968
969 /* Bruno Haible sent me these statistics for Linux. It seems
970 that some filesystems count indirect blocks in st_blocks,
971 while others do not seem to:
972
973 minix-fs tar: size=7205, st_blocks=18 and ST_NBLOCKS=18
974 extfs tar: size=7205, st_blocks=18 and ST_NBLOCKS=18
975 ext2fs tar: size=7205, st_blocks=16 and ST_NBLOCKS=16
976 msdos-fs tar: size=7205, st_blocks=16 and ST_NBLOCKS=16
977
978 Dick Streefland reports the previous numbers as misleading,
979 because ext2fs use 12 direct blocks, while minix-fs uses only
980 6 direct blocks. Dick gets:
981
982 ext2 size=20480 ls listed blocks=21
983 minix size=20480 ls listed blocks=21
984 msdos size=20480 ls listed blocks=20
985
986 It seems that indirect blocks *are* included in st_blocks.
987 The minix filesystem does not account for phantom blocks in
988 st_blocks, so `du' and `ls -s' give wrong results. So, the
989 --sparse option would not work on a minix filesystem. */
990
991 if (ST_NBLOCKS (current_stat)
992 < (current_stat.st_size / ST_NBLOCKSIZE
993 + (current_stat.st_size % ST_NBLOCKSIZE != 0)))
994 {
995 off_t filesize = current_stat.st_size;
996 int counter;
997
998 header = start_header (p, &current_stat);
999 if (header == NULL)
1000 {
1001 exit_status = TAREXIT_FAILURE;
1002 return;
1003 }
1004 header->header.typeflag = GNUTYPE_SPARSE;
1005 header_moved = 1;
1006
1007 /* Call the routine that figures out the layout of the
1008 sparse file in question. UPPERBOUND is the index of the
1009 last element of the "sparsearray," i.e., the number of
1010 elements it needed to describe the file. */
1011
1012 upperbound = deal_with_sparse (p, header);
1013
1014 /* See if we'll need an extended header later. */
1015
1016 if (upperbound > SPARSES_IN_OLDGNU_HEADER - 1)
1017 header->oldgnu_header.isextended = 1;
1018
1019 /* We store the "real" file size so we can show that in
1020 case someone wants to list the archive, i.e., tar tvf
1021 <file>. It might be kind of disconcerting if the
1022 shrunken file size was the one that showed up. */
1023
1024 OFF_TO_OCT (current_stat.st_size,
1025 header->oldgnu_header.realsize);
1026
1027 /* This will be the new "size" of the file, i.e., the size
1028 of the file minus the blocks of holes that we're
1029 skipping over. */
1030
1031 find_new_file_size (&filesize, upperbound);
1032 current_stat.st_size = filesize;
1033 OFF_TO_OCT (filesize, header->header.size);
1034
1035 for (counter = 0; counter < SPARSES_IN_OLDGNU_HEADER; counter++)
1036 {
1037 if (!sparsearray[counter].numbytes)
1038 break;
1039
1040 OFF_TO_OCT (sparsearray[counter].offset,
1041 header->oldgnu_header.sp[counter].offset);
1042 SIZE_TO_OCT (sparsearray[counter].numbytes,
1043 header->oldgnu_header.sp[counter].numbytes);
1044 }
1045
1046 }
1047 }
1048 else
1049 upperbound = SPARSES_IN_OLDGNU_HEADER - 1;
1050
1051 sizeleft = current_stat.st_size;
1052
1053 /* Don't bother opening empty, world readable files. Also do not open
1054 files when archive is meant for /dev/null. */
1055
1056 if (dev_null_output
1057 || (sizeleft == 0 && 0444 == (0444 & current_stat.st_mode)))
1058 f = -1;
1059 else
1060 {
1061 f = open (p, O_RDONLY | O_BINARY);
1062 if (f < 0)
1063 {
1064 WARN ((0, errno, _("Cannot add file %s"), p));
1065 if (!ignore_failed_read_option)
1066 exit_status = TAREXIT_FAILURE;
1067 return;
1068 }
1069 }
1070
1071 /* If the file is sparse, we've already taken care of this. */
1072
1073 if (!header_moved)
1074 {
1075 header = start_header (p, &current_stat);
1076 if (header == NULL)
1077 {
1078 if (f >= 0)
1079 close (f);
1080 exit_status = TAREXIT_FAILURE;
1081 return;
1082 }
1083 }
1084 #ifdef S_ISCTG
1085 /* Mark contiguous files, if we support them. */
1086
1087 if (archive_format != V7_FORMAT && S_ISCTG (current_stat.st_mode))
1088 header->header.typeflag = CONTTYPE;
1089 #endif
1090 isextended = header->oldgnu_header.isextended;
1091 save_typeflag = header->header.typeflag;
1092 finish_header (header);
1093 if (isextended)
1094 {
1095 #if 0
1096 int sum = 0;
1097 #endif
1098 int counter;
1099 #if 0
1100 union block *exhdr;
1101 int arraybound = SPARSES_IN_SPARSE_HEADER;
1102 #endif
1103 /* static */ int index_offset = SPARSES_IN_OLDGNU_HEADER;
1104
1105 extend:
1106 exhdr = find_next_block ();
1107
1108 if (exhdr == NULL)
1109 {
1110 exit_status = TAREXIT_FAILURE;
1111 return;
1112 }
1113 memset (exhdr->buffer, 0, BLOCKSIZE);
1114 for (counter = 0; counter < SPARSES_IN_SPARSE_HEADER; counter++)
1115 {
1116 if (counter + index_offset > upperbound)
1117 break;
1118
1119 SIZE_TO_OCT (sparsearray[counter + index_offset].numbytes,
1120 exhdr->sparse_header.sp[counter].numbytes);
1121 OFF_TO_OCT (sparsearray[counter + index_offset].offset,
1122 exhdr->sparse_header.sp[counter].offset);
1123 }
1124 set_next_block_after (exhdr);
1125 #if 0
1126 sum += counter;
1127 if (sum < upperbound)
1128 goto extend;
1129 #endif
1130 if (index_offset + counter <= upperbound)
1131 {
1132 index_offset += counter;
1133 exhdr->sparse_header.isextended = 1;
1134 goto extend;
1135 }
1136
1137 }
1138 if (save_typeflag == GNUTYPE_SPARSE)
1139 {
1140 if (finish_sparse_file (f, &sizeleft, current_stat.st_size, p))
1141 goto padit;
1142 }
1143 else
1144 while (sizeleft > 0)
1145 {
1146 if (multi_volume_option)
1147 {
1148 assign_string (&save_name, p);
1149 save_sizeleft = sizeleft;
1150 save_totsize = current_stat.st_size;
1151 }
1152 start = find_next_block ();
1153
1154 bufsize = available_space_after (start);
1155
1156 if (sizeleft < bufsize)
1157 {
1158 /* Last read -- zero out area beyond. */
1159
1160 bufsize = sizeleft;
1161 count = bufsize % BLOCKSIZE;
1162 if (count)
1163 memset (start->buffer + sizeleft, 0,
1164 (size_t) (BLOCKSIZE - count));
1165 }
1166 if (f < 0)
1167 count = bufsize;
1168 else
1169 count = read (f, start->buffer, bufsize);
1170 if (count < 0)
1171 {
1172 char buf[UINTMAX_STRSIZE_BOUND];
1173 ERROR ((0, errno, _("\
1174 Read error at byte %s, reading %lu bytes, in file %s"),
1175 STRINGIFY_BIGINT (current_stat.st_size - sizeleft,
1176 buf),
1177 (unsigned long) bufsize, p));
1178 goto padit;
1179 }
1180 sizeleft -= count;
1181
1182 /* This is nonportable (the type of set_next_block_after's arg). */
1183
1184 set_next_block_after (start + (count - 1) / BLOCKSIZE);
1185
1186 if (count == bufsize)
1187 continue;
1188 else
1189 {
1190 char buf[UINTMAX_STRSIZE_BOUND];
1191 ERROR ((0, 0,
1192 _("File %s shrunk by %s bytes, padding with zeros"),
1193 p, STRINGIFY_BIGINT (sizeleft, buf)));
1194 goto padit; /* short read */
1195 }
1196 }
1197
1198 if (multi_volume_option)
1199 assign_string (&save_name, NULL);
1200
1201 if (f >= 0)
1202 {
1203 struct stat final_stat;
1204 if (fstat (f, &final_stat) != 0)
1205 ERROR ((0, errno, "%s: fstat", p));
1206 else if (final_stat.st_mtime != restore_times.modtime
1207 || final_stat.st_size != restore_size)
1208 ERROR ((0, errno, _("%s: file changed as we read it"), p));
1209 if (close (f) != 0)
1210 ERROR ((0, errno, _("%s: close"), p));
1211 if (atime_preserve_option)
1212 utime (p, &restore_times);
1213 }
1214 if (remove_files_option)
1215 {
1216 if (unlink (p) == -1)
1217 ERROR ((0, errno, _("Cannot remove %s"), p));
1218 }
1219 return;
1220
1221 /* File shrunk or gave error, pad out tape to match the size we
1222 specified in the header. */
1223
1224 padit:
1225 while (sizeleft > 0)
1226 {
1227 save_sizeleft = sizeleft;
1228 start = find_next_block ();
1229 memset (start->buffer, 0, BLOCKSIZE);
1230 set_next_block_after (start);
1231 sizeleft -= BLOCKSIZE;
1232 }
1233 if (multi_volume_option)
1234 assign_string (&save_name, NULL);
1235 if (f >= 0)
1236 {
1237 close (f);
1238 if (atime_preserve_option)
1239 utime (p, &restore_times);
1240 }
1241 return;
1242 }
1243
1244 #ifdef S_ISLNK
1245 else if (S_ISLNK (current_stat.st_mode))
1246 {
1247 int size;
1248 char *buffer = (char *) alloca (PATH_MAX + 1);
1249
1250 size = readlink (p, buffer, PATH_MAX + 1);
1251 if (size < 0)
1252 {
1253 WARN ((0, errno, _("Cannot add file %s"), p));
1254 if (!ignore_failed_read_option)
1255 exit_status = TAREXIT_FAILURE;
1256 return;
1257 }
1258 buffer[size] = '\0';
1259 if (size >= NAME_FIELD_SIZE)
1260 write_long (buffer, GNUTYPE_LONGLINK);
1261 assign_string (&current_link_name, buffer);
1262
1263 current_stat.st_size = 0; /* force 0 size on symlink */
1264 header = start_header (p, &current_stat);
1265 if (header == NULL)
1266 {
1267 exit_status = TAREXIT_FAILURE;
1268 return;
1269 }
1270 strncpy (header->header.linkname, buffer, NAME_FIELD_SIZE);
1271 header->header.linkname[NAME_FIELD_SIZE - 1] = '\0';
1272 header->header.typeflag = SYMTYPE;
1273 finish_header (header); /* nothing more to do to it */
1274 if (remove_files_option)
1275 {
1276 if (unlink (p) == -1)
1277 ERROR ((0, errno, _("Cannot remove %s"), p));
1278 }
1279 return;
1280 }
1281 #endif /* S_ISLNK */
1282
1283 else if (S_ISDIR (current_stat.st_mode))
1284 {
1285 DIR *directory;
1286 struct dirent *entry;
1287 char *namebuf;
1288 size_t buflen;
1289 size_t len;
1290 dev_t our_device = current_stat.st_dev;
1291
1292 /* If this tar program is installed suid root, like for Amanda, the
1293 access might look like denied, while it is not really.
1294
1295 FIXME: I have the feeling this test is done too early. Couldn't it
1296 just be bundled in later actions? I guess that the proper support
1297 of --ignore-failed-read is the key of the current writing. */
1298
1299 if (access (p, R_OK) == -1 && geteuid () != 0)
1300 {
1301 WARN ((0, errno, _("Cannot add directory %s"), p));
1302 if (!ignore_failed_read_option)
1303 exit_status = TAREXIT_FAILURE;
1304 return;
1305 }
1306
1307 /* Build new prototype name. Ensure exactly one trailing slash. */
1308
1309 len = strlen (p);
1310 buflen = len + NAME_FIELD_SIZE;
1311 namebuf = xmalloc (buflen + 1);
1312 strncpy (namebuf, p, buflen);
1313 while (len >= 1 && namebuf[len - 1] == '/')
1314 len--;
1315 namebuf[len++] = '/';
1316 namebuf[len] = '\0';
1317
1318 if (1)
1319 {
1320 /* The "1" above used to be "archive_format != V7_FORMAT", GNU tar
1321 was just not writing directory blocks at all. Daniel Trinkle
1322 writes: ``All old versions of tar I have ever seen have
1323 correctly archived an empty directory. The really old ones I
1324 checked included HP-UX 7 and Mt. Xinu More/BSD. There may be
1325 some subtle reason for the exclusion that I don't know, but the
1326 current behavior is broken.'' I do not know those subtle
1327 reasons either, so until these are reported (anew?), just allow
1328 directory blocks to be written even with old archives. */
1329
1330 current_stat.st_size = 0; /* force 0 size on dir */
1331
1332 /* FIXME: If people could really read standard archives, this
1333 should be:
1334
1335 header
1336 = start_header (standard_option ? p : namebuf, &current_stat);
1337
1338 but since they'd interpret DIRTYPE blocks as regular
1339 files, we'd better put the / on the name. */
1340
1341 header = start_header (namebuf, &current_stat);
1342 if (header == NULL)
1343 {
1344 exit_status = TAREXIT_FAILURE;
1345 return; /* eg name too long */
1346 }
1347
1348 if (incremental_option)
1349 header->header.typeflag = GNUTYPE_DUMPDIR;
1350 else /* if (standard_option) */
1351 header->header.typeflag = DIRTYPE;
1352
1353 /* If we're gnudumping, we aren't done yet so don't close it. */
1354
1355 if (!incremental_option)
1356 finish_header (header); /* done with directory header */
1357 }
1358
1359 if (incremental_option && gnu_list_name->dir_contents)
1360 {
1361 off_t sizeleft;
1362 off_t totsize;
1363 size_t bufsize;
1364 union block *start;
1365 ssize_t count;
1366 const char *buffer, *p_buffer;
1367
1368 buffer = gnu_list_name->dir_contents; /* FOO */
1369 totsize = 0;
1370 for (p_buffer = buffer; p_buffer && *p_buffer;)
1371 {
1372 size_t tmp;
1373
1374 tmp = strlen (p_buffer) + 1;
1375 totsize += tmp;
1376 p_buffer += tmp;
1377 }
1378 totsize++;
1379 OFF_TO_OCT (totsize, header->header.size);
1380 finish_header (header);
1381 p_buffer = buffer;
1382 sizeleft = totsize;
1383 while (sizeleft > 0)
1384 {
1385 if (multi_volume_option)
1386 {
1387 assign_string (&save_name, p);
1388 save_sizeleft = sizeleft;
1389 save_totsize = totsize;
1390 }
1391 start = find_next_block ();
1392 bufsize = available_space_after (start);
1393 if (sizeleft < bufsize)
1394 {
1395 bufsize = sizeleft;
1396 count = bufsize % BLOCKSIZE;
1397 if (count)
1398 memset (start->buffer + sizeleft, 0,
1399 (size_t) (BLOCKSIZE - count));
1400 }
1401 memcpy (start->buffer, p_buffer, bufsize);
1402 sizeleft -= bufsize;
1403 p_buffer += bufsize;
1404 set_next_block_after (start + (bufsize - 1) / BLOCKSIZE);
1405 }
1406 if (multi_volume_option)
1407 assign_string (&save_name, NULL);
1408 if (atime_preserve_option)
1409 utime (p, &restore_times);
1410 return;
1411 }
1412
1413 /* See if we are about to recurse into a directory, and avoid doing
1414 so if the user wants that we do not descend into directories. */
1415
1416 if (no_recurse_option)
1417 return;
1418
1419 /* See if we are crossing from one file system to another, and
1420 avoid doing so if the user only wants to dump one file system. */
1421
1422 if (one_file_system_option && !top_level
1423 && parent_device != current_stat.st_dev)
1424 {
1425 if (verbose_option)
1426 WARN ((0, 0, _("%s: On a different filesystem; not dumped"), p));
1427 return;
1428 }
1429
1430 /* Now output all the files in the directory. */
1431
1432 errno = 0; /* FIXME: errno should be read-only */
1433
1434 directory = opendir (p);
1435 if (!directory)
1436 {
1437 ERROR ((0, errno, _("Cannot open directory %s"), p));
1438 return;
1439 }
1440
1441 /* Hack to remove "./" from the front of all the file names. */
1442
1443 if (len == 2 && namebuf[0] == '.' && namebuf[1] == '/')
1444 len = 0;
1445
1446 /* FIXME: Should speed this up by cd-ing into the dir. */
1447
1448 while (entry = readdir (directory), entry)
1449 {
1450 /* Skip `.' and `..'. */
1451
1452 if (is_dot_or_dotdot (entry->d_name))
1453 continue;
1454
1455 if ((int) NAMLEN (entry) + len >= buflen)
1456 {
1457 buflen = len + NAMLEN (entry);
1458 namebuf = (char *) xrealloc (namebuf, buflen + 1);
1459 #if 0
1460 namebuf[len] = '\0';
1461 ERROR ((0, 0, _("File name %s%s too long"),
1462 namebuf, entry->d_name));
1463 continue;
1464 #endif
1465 }
1466 strcpy (namebuf + len, entry->d_name);
1467 if (exclude_option && check_exclude (namebuf))
1468 continue;
1469 dump_file (namebuf, our_device, 0);
1470 }
1471
1472 closedir (directory);
1473 free (namebuf);
1474 if (atime_preserve_option)
1475 utime (p, &restore_times);
1476 return;
1477 }
1478
1479 #ifdef S_ISCHR
1480 else if (S_ISCHR (current_stat.st_mode))
1481 type = CHRTYPE;
1482 #endif
1483
1484 #ifdef S_ISBLK
1485 else if (S_ISBLK (current_stat.st_mode))
1486 type = BLKTYPE;
1487 #endif
1488
1489 /* Avoid screwy apollo lossage where S_IFIFO == S_IFSOCK. */
1490
1491 #if (_ISP__M68K == 0) && (_ISP__A88K == 0) && defined(S_ISFIFO)
1492 else if (S_ISFIFO (current_stat.st_mode))
1493 type = FIFOTYPE;
1494 #endif
1495
1496 #ifdef S_ISSOCK
1497 else if (S_ISSOCK (current_stat.st_mode))
1498 type = FIFOTYPE;
1499 #endif
1500
1501 else
1502 goto unknown;
1503
1504 if (archive_format == V7_FORMAT)
1505 goto unknown;
1506
1507 current_stat.st_size = 0; /* force 0 size */
1508 header = start_header (p, &current_stat);
1509 if (header == NULL)
1510 {
1511 exit_status = TAREXIT_FAILURE;
1512 return; /* eg name too long */
1513 }
1514
1515 header->header.typeflag = type;
1516
1517 #if defined(S_IFBLK) || defined(S_IFCHR)
1518 if (type != FIFOTYPE)
1519 {
1520 MAJOR_TO_OCT (major (current_stat.st_rdev), header->header.devmajor);
1521 MINOR_TO_OCT (minor (current_stat.st_rdev), header->header.devminor);
1522 }
1523 #endif
1524
1525 finish_header (header);
1526 if (remove_files_option)
1527 {
1528 if (unlink (p) == -1)
1529 ERROR ((0, errno, _("Cannot remove %s"), p));
1530 }
1531 return;
1532
1533 unknown:
1534 ERROR ((0, 0, _("%s: Unknown file type; file ignored"), p));
1535 }
This page took 0.106503 seconds and 5 git commands to generate.