MCPcopy Create free account
hub / github.com/F-Stack/f-stack / makeUniqueMirroredDestDirs

Function makeUniqueMirroredDestDirs

freebsd/contrib/zstd/programs/util.c:883–920  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

881}
882
883static void
884makeUniqueMirroredDestDirs(char** srcDirNames, unsigned nbFile, const char* outDirName)
885{
886 unsigned int i = 0, uniqueDirNr = 0;
887 char** uniqueDirNames = NULL;
888
889 if (nbFile == 0)
890 return;
891
892 uniqueDirNames = (char** ) malloc(nbFile * sizeof (char *));
893 CONTROL(uniqueDirNames != NULL);
894
895 /* if dirs is "a/b/c" and "a/b/c/d", we only need call:
896 * we just need "a/b/c/d" */
897 qsort((void *)srcDirNames, nbFile, sizeof(char*), compareDir);
898
899 uniqueDirNr = 1;
900 uniqueDirNames[uniqueDirNr - 1] = srcDirNames[0];
901 for (i = 1; i < nbFile; i++) {
902 char* prevDirName = srcDirNames[i - 1];
903 char* currDirName = srcDirNames[i];
904
905 /* note: we alwasy compare trimmed path, i.e.:
906 * src dir of "./foo" and "/foo" will be both saved into:
907 * "outDirName/foo/" */
908 if (!firstIsParentOrSameDirOfSecond(trimPath(prevDirName),
909 trimPath(currDirName)))
910 uniqueDirNr++;
911
912 /* we need maintain original src dir name instead of trimmed
913 * dir, so we can retrive the original src dir's mode_t */
914 uniqueDirNames[uniqueDirNr - 1] = currDirName;
915 }
916
917 makeMirroredDestDirsWithSameSrcDirMode(uniqueDirNames, uniqueDirNr, outDirName);
918
919 free(uniqueDirNames);
920}
921
922static void
923makeMirroredDestDirs(char** srcFileNames, unsigned nbFile, const char* outDirName)

Callers 1

makeMirroredDestDirsFunction · 0.85

Calls 6

mallocFunction · 0.85
qsortFunction · 0.85
trimPathFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected