/* Create a dumpdir containing only one entry: that for the tagfile. */ static void maketagdumpdir (struct directory *directory) { size_t len = strlen (directory->tagfile) + 1; char *new_dump = xmalloc (len + 2); new_dump[0] = 'Y'; memcpy (new_dump + 1, directory->tagfile, len); new_dump[len + 1] = 0; directory->idump = directory->dump; directory->dump = dumpdir_create0 (new_dump, NULL); free (new_dump); }
void makedumpdir (struct directory *directory, const char *dir) { size_t i, dirsize, /* Number of elements in DIR */ len; /* Length of DIR, including terminating nul */ const char *p; char const **array; char *new_dump, *new_dump_ptr; struct dumpdir *dump; if (directory->children == ALL_CHILDREN) dump = NULL; else if (DIR_IS_RENAMED (directory)) dump = directory->orig->idump ? directory->orig->idump : directory->orig->dump; else dump = directory->dump; /* Count the size of DIR and the number of elements it contains */ dirsize = 0; len = 0; for (p = dir; *p; p += strlen (p) + 1, dirsize++) len += strlen (p) + 2; len++; /* Create a sorted directory listing */ array = xcalloc (dirsize, sizeof array[0]); for (i = 0, p = dir; *p; p += strlen (p) + 1, i++) array[i] = p; qsort (array, dirsize, sizeof (array[0]), compare_dirnames); /* Prepare space for new dumpdir */ new_dump = xmalloc (len); new_dump_ptr = new_dump; /* Fill in the dumpdir template */ for (i = 0; i < dirsize; i++) { const char *loc = dumpdir_locate (dump, array[i]); if (loc) { if (directory->tagfile) *new_dump_ptr = strcmp (directory->tagfile, array[i]) == 0 ? ' ' : 'I'; else *new_dump_ptr = ' '; new_dump_ptr++; } else if (directory->tagfile) *new_dump_ptr++ = strcmp (directory->tagfile, array[i]) == 0 ? ' ' : 'I'; else *new_dump_ptr++ = 'Y'; /* New entry */ /* Copy the file name */ for (p = array[i]; (*new_dump_ptr++ = *p++); ) ; } *new_dump_ptr = 0; directory->idump = directory->dump; directory->dump = dumpdir_create0 (new_dump, NULL); free (array); }
struct dumpdir * dumpdir_create (const char *contents) { return dumpdir_create0 (contents, "YND"); }