You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
997 B

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "imageParserDataStructs.h"
  2. CSTR buildMd5Path(CSTR base, CSTR md5, mode_t mode, CSTR user, CSTR group)
  3. {
  4. char tPath[1024];
  5. char p1[3];
  6. char p2[3];
  7. char p3[3];
  8. if (! fileExist(base))
  9. {
  10. return NULL;
  11. }
  12. memcpy(p1, md5, 2);
  13. p1[2] = (char) 0;
  14. sprintf(tPath, "%s/%s", base, p1);
  15. if (! fileExist(tPath))
  16. {
  17. if (mkdir(tPath, mode) == -1)
  18. {
  19. return NULL;
  20. }
  21. if (user != NULL && group != NULL)
  22. {
  23. ch_chown(tPath, user, group);
  24. }
  25. };
  26. memcpy(p2, md5 + 2, 2);
  27. p2[2] = (char) 0;
  28. sprintf(tPath, "%s/%s/%s", base, p1, p2);
  29. if (! fileExist(tPath))
  30. {
  31. if (mkdir(tPath, mode) == -1)
  32. {
  33. return NULL;
  34. }
  35. if (user != NULL && group != NULL)
  36. {
  37. ch_chown(tPath, user, group);
  38. }
  39. };
  40. memcpy(p3, md5 + 4, 2);
  41. p3[2] = (char) 0;
  42. sprintf(tPath, "%s/%s/%s/%s", base, p1, p2, p3);
  43. if (! fileExist(tPath))
  44. {
  45. if (mkdir(tPath, mode) == -1)
  46. {
  47. return NULL;
  48. }
  49. if (user != NULL && group != NULL)
  50. {
  51. ch_chown(tPath, user, group);
  52. }
  53. };
  54. return strdup(tPath);
  55. }