Beispiel #1
0
int Scan_TreeAndIndex(char *pathname, Index *ind, Pathstore *store,int discardDups) {
  const uint32_t MAXPATH = 1024;
  if (Fileops_isfile(pathname)) {
    return Scan_File(pathname, ind, store, discardDups);
  }
  // Not a file must be directory, process all entries in the directory

  if (strlen(pathname) > MAXPATH-16) {
    fprintf(stderr, "Too deep of directories %s\n", pathname);
    return -1;
  }
  numdirs++;

  int dirfd = Fileops_open(pathname);
  if (dirfd < 0) {
    fprintf(stderr, "Can't open pathname %s\n", pathname);
    return -1;
  }

  if (pathname[1] == 0) {
    // pathame == "/"
    pathname++; // Delete extra / character
  }


  int ret;
  while (1)  {
    struct direntv6 dirent;
    ret = Fileops_read(dirfd, (char *)&dirent, sizeof(struct direntv6));

    if (ret == 0)  {
      /* Done with directory */
      break;
    }

    if (ret != sizeof(struct direntv6)) {
      fprintf(stderr, "Error reading directory %s\n", pathname);
      ret = -1;
      break;
    }

    numdirents++;
    char *n = dirent.d_name;
    if (n[0] == '.') {
      if ((n[1] == 0) || ((n[1] == '.') && (n[2] == 0))) {
	       /* Skip over "." and ".." */
	       continue;
      }
    }

    char nextpath[MAXPATH];
    sprintf(nextpath, "%s/%s",pathname, n);
    Scan_TreeAndIndex(nextpath, ind, store, discardDups);
  }

  Fileops_close(dirfd);
  return ret;
}
Beispiel #2
0
void
BuildDiskIndex(char *diskpath, int discardDups)
{
  void *fshandle = Fileops_init(diskpath);
  if (fshandle == NULL) {
    fprintf(stderr, "Error initializing  %s\n", diskpath);
    exit(EXIT_FAILURE);
  }

  store = Pathstore_create(fshandle);
  if (store == NULL) {
    fprintf(stderr, "Can't create pathstore\n");
    exit(EXIT_FAILURE);
  }
  //fprintf(stderr, "About to create index\n");
  diskIndex = Index_Create();
  //fprintf(stderr, "Index created\n");
  if (diskIndex == NULL) {
    fprintf(stderr, "Can't create index\n");
    exit(EXIT_FAILURE);
  }
	//fprintf(stderr, "about to reach quietflag\n");
  if (!quietFlag) {
    printf("Starting index build ....");
  }

  int64_t startTime = Debug_GetTimeInMicrosecs();
	//fprintf(stderr, "scanning tree\n");

  int err = Scan_TreeAndIndex("/", diskIndex, store, discardDups);
	//fprintf(stderr, "scanned tree\n");

  if (err) {
    fprintf(stderr, "Error creating index\n");
    exit(EXIT_FAILURE);
  }
  int64_t endTime = Debug_GetTimeInMicrosecs();

  if (!quietFlag) {
    printf("\nIndex disk %s (latency %d) completed in %f seconds\n",
           diskpath, diskLatency, (endTime - startTime)/1000000.0);
  }
}