Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at maildir-sync.c:373

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

maildir_scan_dir

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib-storage/index/maildir/maildir-sync.c)expand/collapse
Show more  
 358  static int maildir_scan_dir(struct maildir_sync_context *ctx, bool new_dir)
 359  {
 360          struct mail_storage *storage = &ctx->mbox->storage->storage;
 361          const char *path;
 362          DIR *dirp;
 363          string_t *src, *dest;
 364          struct dirent *dp;
 365          struct stat st;
 366          enum maildir_uidlist_rec_flag flags;
 367          unsigned int i = 0, move_count = 0;
 368          time_t now;
 369          int ret = 1;
 370          bool move_new, check_touch, dir_changed = FALSE;
 371   
 372          path = new_dir ? ctx->new_dir : ctx->cur_dir;
 373          for (i = 0;; i++) {
 374                  dirp = opendir(path);
 375                  if (dirp != NULL)
 376                          break;
 377   
 378                  if (errno != ENOENT || i == MAILDIR_DELETE_RETRY_COUNT) {
 379                          if (errno == EACCES) {
 380                                  mail_storage_set_critical(storage, "%s",
 381                                          eacces_error_get("opendir", path));
 382                          } else {
 383                                  mail_storage_set_critical(storage,
 384                                          "opendir(%s) failed: %m", path);
 385                          }
 386                          return -1;
 387                  }
 388   
 389                  if (!maildir_set_deleted(ctx->mbox))
 390                          return -1;
 391                  /* try again */
 392          }
 393   
 394  #ifdef HAVE_DIRFD 
 395          if (fstat(dirfd(dirp), &st) < 0) {
 396                  mail_storage_set_critical(storage,
 397                          "fstat(%s) failed: %m", path);
 398                  (void)closedir(dirp);
 399                  return -1;
 400          }
 401  #else
 402          if (maildir_stat(ctx->mbox, path, &st) < 0) {
 403                  (void)closedir(dirp);
 404                  return -1;
 405          }
 406  #endif
 407   
 408          now = time(NULL);
 409          if (new_dir) {
 410                  ctx->mbox->maildir_hdr.new_check_time = now;
 411                  ctx->mbox->maildir_hdr.new_mtime = st.st_mtime;
 412                  ctx->mbox->maildir_hdr.new_mtime_nsecs = ST_MTIME_NSEC(st);
 413          } else {
 414                  ctx->mbox->maildir_hdr.cur_check_time = now;
 415                  ctx->mbox->maildir_hdr.cur_mtime = st.st_mtime;
 416                  ctx->mbox->maildir_hdr.cur_mtime_nsecs = ST_MTIME_NSEC(st);
 417          }
 418   
 419          src = t_str_new(1024);
 420          dest = t_str_new(1024);
 421   
 422          move_new = new_dir && !mailbox_is_readonly(&ctx->mbox->ibox.box) &&
 423                  !ctx->mbox->ibox.keep_recent && ctx->locked;
 424   
 425          errno = 0;
 426          for (; (dp = readdir(dirp)) != NULL; errno = 0) {
 427                  if (dp->d_name[0] == '.')
 428                          continue;
 429   
 430                  check_touch = FALSE;
 431                  flags = 0;
 432                  if (move_new) {
 433                          str_truncate(src, 0);
 434                          str_truncate(dest, 0);
 435                          str_printfa(src, "%s/%s", ctx->new_dir, dp->d_name);
 436                          str_printfa(dest, "%s/%s", ctx->cur_dir, dp->d_name);
 437                          if (strchr(dp->d_name, MAILDIR_INFO_SEP) == NULL) {
 438                                  str_append(dest, MAILDIR_FLAGS_FULL_SEP);
 439                          }
 440                          if (rename(str_c(src), str_c(dest)) == 0) {
 441                                  /* we moved it - it's \Recent for us */
 442                                  dir_changed = TRUE;
 443                                  move_count++;
 444                                  flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED |
 445                                          MAILDIR_UIDLIST_REC_FLAG_RECENT;
 446                          } else if (ENOTFOUND(errno)) {
 447                                  /* someone else moved it already */
 448                                  dir_changed = TRUE;
 449                                  move_count++;
 450                                  flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED |
 451                                          MAILDIR_UIDLIST_REC_FLAG_RECENT;
 452                          } else if (ENOSPACE(errno) || errno == EACCES) {
 453                                  /* not enough disk space / read-only maildir,
 454                                     leave here */
 455                                  flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR;
 456                                  move_new = FALSE;
 457                          } else {
 458                                  flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR;
 459                                  mail_storage_set_critical(storage,
 460                                          "rename(%s, %s) failed: %m",
 461                                          str_c(src), str_c(dest));
 462                          }
 463                          if ((move_count % MAILDIR_SLOW_MOVE_COUNT) == 0)
 464                                  maildir_sync_notify(ctx);
 465                  } else if (new_dir) {
 466                          flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR |
 467                                  MAILDIR_UIDLIST_REC_FLAG_RECENT;
 468                  }
 469   
 470                  i++;
 471                  if ((i % MAILDIR_SLOW_CHECK_COUNT) == 0)
 472                          maildir_sync_notify(ctx);
 473   
 474                  ret = maildir_uidlist_sync_next(ctx->uidlist_sync_ctx,
 475                                                  dp->d_name, flags);
 476                  if (ret <= 0) {
 477                          if (ret < 0)
 478                                  break;
 479   
 480                          /* possibly duplicate - try fixing it */
 481                          T_BEGIN {
 482                                  ret = maildir_fix_duplicate(ctx, path,
 483                                                              dp->d_name);
 484                          } T_END;
 485                          if (ret < 0)
 486                                  break;
 487                  }
 488          }
 489   
 490          if (errno != 0) {
 491                  mail_storage_set_critical(storage,
 492                                            "readdir(%s) failed: %m", path);
 493                  ret = -1;
 494          }
 495   
 496          if (closedir(dirp) < 0) {
 497                  mail_storage_set_critical(storage,
 498                                            "closedir(%s) failed: %m", path);
 499                  ret = -1;
 500          }
 501   
 502          if (dir_changed) {
 503                  /* save the exact new times. the new mtimes should be >=
 504                     "now", but just in case something weird happens and mtime 
 505                     doesn't update, use "now". */
 506                  if (stat(ctx->new_dir, &st) == 0) {
 507                          ctx->mbox->maildir_hdr.new_check_time =
 508                                  I_MAX(st.st_mtime, now);
 509                          ctx->mbox->maildir_hdr.new_mtime = st.st_mtime;
 510                          ctx->mbox->maildir_hdr.new_mtime_nsecs =
 511                                  ST_MTIME_NSEC(st);
 512                  }
 513                  if (stat(ctx->cur_dir, &st) == 0) {
 514                          ctx->mbox->maildir_hdr.new_check_time =
 515                                  I_MAX(st.st_mtime, now);
 516                          ctx->mbox->maildir_hdr.cur_mtime = st.st_mtime;
 517                          ctx->mbox->maildir_hdr.cur_mtime_nsecs =
 518                                  ST_MTIME_NSEC(st);
 519                  }
 520          }
 521   
 522          return ret < 0 ? -1 :
 523                  (move_count <= MAILDIR_RENAME_RESCAN_COUNT ? 0 : 1);
 524  }
Show more  




Change Warning 7304.25190 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: