Exemplo n.º 1
0
int btFiles::CreateFiles()
{
  int check_exist = 0;
  char fn[MAXPATHLEN];
  BTFILE *pbt = m_btfhead;
  struct stat sb;
  int i = 0;

  for(; pbt; pbt = pbt->bf_next){
    m_nfiles++;

    if( m_directory ){
      if( MAXPATHLEN <= snprintf(fn, MAXPATHLEN, "%s%c%s",
          m_directory, PATH_SP, pbt->bf_filename) ){
        errno = ENAMETOOLONG;
        return -1;
      }
    }else{
      strcpy(fn, pbt->bf_filename);
    }
    
    if(stat(fn, &sb) < 0){
      if(ENOENT == errno){
        CONSOLE.Interact_n("");
        CONSOLE.Interact_n("Creating file \"%s\"", fn);
        if( !_btf_creat_by_path(fn,pbt->bf_length)){
          CONSOLE.Warning(1, "error, create file \"%s\" failed:  %s", fn,
            strerror(errno));
          return -1;
        }
      }else{
        CONSOLE.Warning(1, "error, couldn't create file \"%s\":  %s", fn,
          strerror(errno));
        return -1;
      }
    }else{
      if( !check_exist) check_exist = 1;
      if( !(S_IFREG & sb.st_mode) ){
        CONSOLE.Warning(1, "error, file \"%s\" is not a regular file.", fn);
        return -1;
      }
      if(sb.st_size != pbt->bf_length){
        CONSOLE.Warning(1,"error, file \"%s\" size doesn't match; must be %llu",
                fn, (unsigned long long)(pbt->bf_length));
        return -1;
      }
    }
  } //end for

  m_file = new BTFILE *[m_nfiles];
  if( !m_file ){
    CONSOLE.Warning(1, "error, failed to allocate memory for files list");
    return -1;
  }
  for( pbt = m_btfhead; pbt; pbt = pbt->bf_next ){
    m_file[i++] = pbt;
  }
  return check_exist;
}
Exemplo n.º 2
0
int btFiles::CreateFiles()
{
  int check_exist = 0;
  char fn[MAXPATHLEN];
  BTFILE *pbt = m_btfhead;
  struct stat sb;

  for(; pbt; pbt = pbt->bf_next){
    if( m_directory ){
      if( MAXPATHLEN <= snprintf(fn, MAXPATHLEN, "%s%c%s", m_directory, PATH_SP, pbt->bf_filename) )
	return -1;
    }else{
      strcpy(fn, pbt->bf_filename);
    }
    
    if(stat(fn ,&sb) < 0){
      if(ENOENT == errno){
	if( !_btf_creat_by_path(fn,pbt->bf_length)){
	  fprintf(stderr,"error, create file %s failed.\n",fn);
	  return -1;
	}
      }else{
	fprintf(stderr,"error, couldn't create file %s\n", fn);
	return -1;
      }
    }else{
      if( !check_exist) check_exist = 1;
      if( !(S_IFREG & sb.st_mode) ){
	fprintf(stderr,"error, file %s not a regular file.\n", fn);
	return -1;
      }
      if(sb.st_size != pbt->bf_length){
	fprintf(stderr,"error, file %s 's size not match. must be %u\n",
		fn, pbt->bf_length);
	return -1;
      }
    }
  } //end for
  return check_exist;
}