Diff for /libaitsync/src/dir.c between versions 1.4 and 1.5

version 1.4, 2012/11/13 14:19:39 version 1.5, 2014/02/04 16:58:17
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012Copyright 2004 - 2014
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 78  create_tags() Line 78  create_tags()
 {  {
         int *tags;          int *tags;
   
        tags = calloc(TABLESIZ, sizeof(int));        tags = e_calloc(TABLESIZ, sizeof(int));
         if (!tags) {          if (!tags) {
                 LOGERR;                  LOGERR;
         } else          } else
Line 98  create_diridx(const char *csDir, int lm, int *tags, st Line 98  create_diridx(const char *csDir, int lm, int *tags, st
         struct stat sb;          struct stat sb;
         register int i;          register int i;
   
        l = malloc(sizeof(struct tagDirName));        l = e_malloc(sizeof(struct tagDirName));
         if (!l) {          if (!l) {
                 LOGERR;                  LOGERR;
                 *list = NULL;                  *list = NULL;
Line 111  create_diridx(const char *csDir, int lm, int *tags, st Line 111  create_diridx(const char *csDir, int lm, int *tags, st
         old = getcwd(NULL, 0);          old = getcwd(NULL, 0);
         if (chdir(csDir) == -1) {          if (chdir(csDir) == -1) {
                 LOGERR;                  LOGERR;
                free(old);                e_free(old);
                free(l);                e_free(l);
                 *list = NULL;                  *list = NULL;
                 return -1;                  return -1;
         }          }
Line 120  create_diridx(const char *csDir, int lm, int *tags, st Line 120  create_diridx(const char *csDir, int lm, int *tags, st
         if (!dir) {          if (!dir) {
                 LOGERR;                  LOGERR;
                 chdir(old);                  chdir(old);
                free(old);                e_free(old);
                free(l);                e_free(l);
                 *list = NULL;                  *list = NULL;
                 return -1;                  return -1;
         }          }
Line 129  create_diridx(const char *csDir, int lm, int *tags, st Line 129  create_diridx(const char *csDir, int lm, int *tags, st
                 if (d.d_type == DT_DIR && (!strcmp(d.d_name, ".") || !strcmp(d.d_name, "..")))                  if (d.d_type == DT_DIR && (!strcmp(d.d_name, ".") || !strcmp(d.d_name, "..")))
                         continue;                          continue;
   
                l = realloc(l, sizeof(struct tagDirName) * (n + 2));                l = e_realloc(l, sizeof(struct tagDirName) * (n + 2));
                 if (!l) {                  if (!l) {
                         LOGERR;                          LOGERR;
                         chdir(old);                          chdir(old);
                        free(old);                        e_free(old);
                        free(l);                        e_free(l);
                         *list = NULL;                          *list = NULL;
                         closedir(dir);                          closedir(dir);
                         return -1;                          return -1;
Line 206  create_diridx(const char *csDir, int lm, int *tags, st Line 206  create_diridx(const char *csDir, int lm, int *tags, st
                 tags[l[i].tag] = i;                  tags[l[i].tag] = i;
   
         chdir(old);          chdir(old);
        free(old);        e_free(old);
   
         *list = l;          *list = l;
         return n;          return n;
Line 218  create_diridx(const char *csDir, int lm, int *tags, st Line 218  create_diridx(const char *csDir, int lm, int *tags, st
  * sync_dirChkSum() - Calculate checksum of directory   * sync_dirChkSum() - Calculate checksum of directory
  *   *
  * @csDir = Directory   * @csDir = Directory
 * @md = Message digest allocated memory, must be free() after use! * @md = Message digest allocated memory, must be e_free() after use!
  * return: -1 error or !=-1 ok   * return: -1 error or !=-1 ok
  */   */
 int  int
Line 229  sync_dirChkSum(const char *csDir, u_char **md) Line 229  sync_dirChkSum(const char *csDir, u_char **md)
         MD5_CTX ctx;          MD5_CTX ctx;
         register int ret = 0;          register int ret = 0;
   
        *md = malloc(MD5_DIGEST_LENGTH);        *md = e_malloc(MD5_DIGEST_LENGTH);
         if (!*md) {          if (!*md) {
                 LOGERR;                  LOGERR;
                 return -1;                  return -1;
Line 239  sync_dirChkSum(const char *csDir, u_char **md) Line 239  sync_dirChkSum(const char *csDir, u_char **md)
         dir = opendir(csDir);          dir = opendir(csDir);
         if (!dir) {          if (!dir) {
                 LOGERR;                  LOGERR;
                free(*md);                e_free(*md);
                 return -1;                  return -1;
         }          }
   
Line 275  sync_dircmp(const char *csDir1, const char *csDir2) Line 275  sync_dircmp(const char *csDir1, const char *csDir2)
         if (sync_dirChkSum(csDir1, &md[0]) == -1)          if (sync_dirChkSum(csDir1, &md[0]) == -1)
                 return ret;                  return ret;
         if (sync_dirChkSum(csDir2, &md[1]) == -1) {          if (sync_dirChkSum(csDir2, &md[1]) == -1) {
                free(md[0]);                e_free(md[0]);
                 return ret;                  return ret;
         }          }
   
Line 284  sync_dircmp(const char *csDir1, const char *csDir2) Line 284  sync_dircmp(const char *csDir1, const char *csDir2)
         else          else
                 ret = 1;                  ret = 1;
   
        free(md[1]);        e_free(md[1]);
        free(md[0]);        e_free(md[0]);
         return ret;          return ret;
 }  }
   
Line 295  sync_dircmp(const char *csDir1, const char *csDir2) Line 295  sync_dircmp(const char *csDir1, const char *csDir2)
  * @csDir1 = Directory 1   * @csDir1 = Directory 1
  * @csDir2 = Directory 2 or File list, if "-" get input from console   * @csDir2 = Directory 2 or File list, if "-" get input from console
  * @lm = Long mode options, !=NULL long output   * @lm = Long mode options, !=NULL long output
 * @list = Output diff list, after use must be free()! * @list = Output diff list, after use must be e_free()!
  * return: -1 error, 0 is equal or >0 count of returned list items   * return: -1 error, 0 is equal or >0 count of returned list items
  */   */
 int  int
Line 324  sync_dircmpList(const char *csDir1, const char *csDir2 Line 324  sync_dircmpList(const char *csDir1, const char *csDir2
   
         if (lstat(csDir2, &sb) == -1) {          if (lstat(csDir2, &sb) == -1) {
                 LOGERR;                  LOGERR;
                free(tags);                e_free(tags);
                free(l);                e_free(l);
                 return -1;                  return -1;
         }          }
         if (S_ISDIR(sb.st_mode)) {          if (S_ISDIR(sb.st_mode)) {
Line 333  sync_dircmpList(const char *csDir1, const char *csDir2 Line 333  sync_dircmpList(const char *csDir1, const char *csDir2
                 if (chdir(csDir2) == -1) {                  if (chdir(csDir2) == -1) {
                         LOGERR;                          LOGERR;
                         chdir(old);                          chdir(old);
                        free(old);                        e_free(old);
                        free(tags);                        e_free(tags);
                        free(l);                        e_free(l);
                         return -1;                          return -1;
                 }                  }
                 dir = opendir(".");                  dir = opendir(".");
                 if (!dir) {                  if (!dir) {
                         LOGERR;                          LOGERR;
                         chdir(old);                          chdir(old);
                        free(old);                        e_free(old);
                        free(tags);                        e_free(tags);
                        free(l);                        e_free(l);
                         return -1;                          return -1;
                 }                  }
                 while (!readdir_r(dir, &d, &pd) && pd) {                  while (!readdir_r(dir, &d, &pd) && pd) {
Line 358  sync_dircmpList(const char *csDir1, const char *csDir2 Line 358  sync_dircmpList(const char *csDir1, const char *csDir2
                         find = find_tag(tags, l, t, hash);                          find = find_tag(tags, l, t, hash);
                         /* element not find in dir1, added */                          /* element not find in dir1, added */
                         if (!find) {                          if (!find) {
                                l = realloc(l, sizeof(struct tagDirName) * (n + 2));                                l = e_realloc(l, sizeof(struct tagDirName) * (n + 2));
                                 if (!l) {                                  if (!l) {
                                         LOGERR;                                          LOGERR;
                                         chdir(old);                                          chdir(old);
                                        free(old);                                        e_free(old);
                                         closedir(dir);                                          closedir(dir);
                                        free(tags);                                        e_free(tags);
                                         return -1;                                          return -1;
                                 } else                                  } else
                                         memset(&l[n + 1], 0, sizeof(struct tagDirName));                                          memset(&l[n + 1], 0, sizeof(struct tagDirName));
Line 430  sync_dircmpList(const char *csDir1, const char *csDir2 Line 430  sync_dircmpList(const char *csDir1, const char *csDir2
                 }                  }
                 closedir(dir);                  closedir(dir);
                 chdir(old);                  chdir(old);
                free(old);                e_free(old);
         } else {          } else {
                 if (strcmp(csDir2, "-")) {                  if (strcmp(csDir2, "-")) {
                         f = fopen(csDir2, "r");                          f = fopen(csDir2, "r");
                         if (!f) {                          if (!f) {
                                 LOGERR;                                  LOGERR;
                                free(tags);                                e_free(tags);
                                free(l);                                e_free(l);
                                 return -1;                                  return -1;
                         }                          }
                 }                  }
Line 460  sync_dircmpList(const char *csDir1, const char *csDir2 Line 460  sync_dircmpList(const char *csDir1, const char *csDir2
                         find = find_tag(tags, l, t, hash);                          find = find_tag(tags, l, t, hash);
                         /* element not find in dir1, added */                          /* element not find in dir1, added */
                         if (!find) {                          if (!find) {
                                l = realloc(l, sizeof(struct tagDirName) * (n + 2));                                l = e_realloc(l, sizeof(struct tagDirName) * (n + 2));
                                 if (!l) {                                  if (!l) {
                                         LOGERR;                                          LOGERR;
                                         if (strcmp(csDir2, "-"))                                          if (strcmp(csDir2, "-"))
                                                 fclose(f);                                                  fclose(f);
                                        free(tags);                                        e_free(tags);
                                         return -1;                                          return -1;
                                 } else                                  } else
                                         memset(&l[n + 1], 0, sizeof(struct tagDirName));                                          memset(&l[n + 1], 0, sizeof(struct tagDirName));
Line 493  sync_dircmpList(const char *csDir1, const char *csDir2 Line 493  sync_dircmpList(const char *csDir1, const char *csDir2
                 }                  }
         n -= cx;          n -= cx;
   
        free(tags);        e_free(tags);
         *list = l;          *list = l;
         return n;          return n;
 }  }

Removed from v.1.4  
changed lines
  Added in v.1.5


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>