Example #1
0
bool Utils::mkdir_tree(char *path) {
  int permission = 0777, i, rc;
  struct stat s;

  fixPath(path);

  if(stat(path, &s) != 0) {
    /* Start at 1 to skip the root */
    for(i=1; path[i] != '\0'; i++)
      if(path[i] == CONST_PATH_SEP) {
#ifdef WIN32
	/* Do not create devices directory */
	if((i > 1) && (path[i-1] == ':')) continue;
#endif

	path[i] = '\0';
	rc = mkdir_s(path, permission);
	path[i] = CONST_PATH_SEP;
      }

    rc = mkdir_s(path, permission);

    return(rc == 0 ? true : false);
  } else
    return(true); /* Already existing */
}
Example #2
0
void unpack_extension( char *package )
{
  int error;
  int fd;
  char tmp[2048];
  int ftype;
  fwrite( "Uncompressing files...", 1, 22, stdout );
  memcpy( TMPDIR, "/tmp/grass.extension.XXXXXX", 28 );
  mkstemp( TMPDIR );
  fd = open( TMPDIR, 64, 511 );
  if ( fd == -1 )
  {
    print_error( -7, "could not create temp directory name: %s", strerror( *(int*)(__errno_location( )) ) );
    exit( -7 );
  }
  if ( VERBOSE )
    fprintf( stdout, "\nUncompressing to: %s.\n", TMPDIR );
  close( fd );
  remove( TMPDIR );
  mkdir_s( TMPDIR, "0700" );
  atexit( &exit_tmp );
  sprintf( tmp, "cp %s %s", package, TMPDIR );
  error = system( tmp );
  if ( error < 0 )
  {
    print_error( -7, "could not copy extension files to temp dir.\n" );
    exit( -7 );
  }
  ftype = check_filetype( package );
  if ( ftype == 0 )
  {
    print_warning( "file name not '.tar.gz', '.tgz', '.tar.bz2', '.tbz' or '.zip'. Assuming '.tgz'.\n" );
    ftype = 1;
  }
  if ( ftype == 1 )
  {
    if ( VERBOSE )
    {
      sprintf( tmp, "tar -xzvf %s/%s -C %s", TMPDIR, basename( package ), TMPDIR );
    }
    else
    {
      sprintf( tmp, "tar -xzf %s/%s -C %s", TMPDIR, basename( package ), TMPDIR );
    }
  }
  if ( ftype == 2 )
  {
    if ( VERBOSE )
    {
      sprintf( tmp, "tar -xjvf %s/%s -C %s", TMPDIR, basename( package ), TMPDIR );
    }
    else
    {
      sprintf( tmp, "tar -xjvf %s/%s -C %s", TMPDIR, basename( package ), TMPDIR );
    }
  }
  if ( ftype == 3 )
  {
    if ( VERBOSE )
    {
      sprintf( tmp, "unzip %s/%s -d %s", TMPDIR, basename( package ), TMPDIR );
    }
    else
    {
      sprintf( tmp, "unzip -qq %s/%s -d %s", TMPDIR, basename( package ), TMPDIR );
    }
  }
  if ( ftype == 4 )
  {
    if ( VERBOSE )
    {
      sprintf( tmp, "tar -xvf %s/%s -C %s", TMPDIR, basename( package ), TMPDIR );
    }
    else
    {
      sprintf( tmp, "tar -xf %s/%s -C %s", TMPDIR, basename( package ), TMPDIR );
    }
  }
  error = system( tmp );
  if ( error < 0 )
  {
    if ( ftype == 1 )
      print_error( -7, "could not extract files using 'tar' and 'gzip'. \n \t\t\t\t\tExtract manually using 'tar -xzvf %s'.\n", package );
    if ( ftype == 2 )
      print_error( -7, "could not extract files using 'tar' and 'bunzip2'.\n \t\t\t\tExtract manually using 'tar -xjvf %s'.\n", package );
    if ( ftype == 3 )
      print_error( -7, "could not extract files using 'unzip'.\n \t\t\t\tExtract manually using 'unzip %s'.\n", package );
    exit( -7 );
  }
  else
  {
    print_done( );
    return;
  }
}