示例#1
0
//dirCopy slightly modified version of copyMovedir.  Modified so doesn't delete original files.
void dirCopy(char *fromdir, char *todir, BOOL overwrite) {
// 	copy directory tree below fromdir (all subdirectories and files at all levels)
	int ret, r1, len_from, len_to;
	char from[PATH_LENGTH], fromfind[PATH_LENGTH], to[PATH_LENGTH], lastdir[FILE_LENGTH], first_dir[PATH_LENGTH];
	unsigned int i, k;
	struct f_info fi;
	
	strcpy(from, fromdir);
	len_from = strlen(from);
	
	if(from[len_from-1] != '/') {
		strcat(from, "/");
		len_from++;
	}
	strcat(from, "*");
	
	strcpy(to, todir);
	len_to = strlen(to);
	ret = mkdir((LPSTR)to);	// just to be safe
	if(to[len_to-1] != '/') {
		strcat(to, "/");
		len_to++;
	}
	strcpy(fromfind,from);
	
	ret =_findfirst((LPSTR)fromfind, &fi, D_DIR);
	from[len_from] = 0;
	lastdir[0] = 0;
	strcpy(first_dir,fi.f_name);
	
	i=0;
	while (ret >= 0) {
		i++;
		k=0;
		if(fi.f_name[0]!='.') {
		
			from[len_from] = 0;
			to[len_to]= 0;
			
			strcat(from, fi.f_name);
			strcat(to, fi.f_name);
			
			r1 = mkdir((LPSTR)to);
	
			dirCopy (from, to, overwrite);
		}

		ret =_findfirst((LPSTR)fromfind, &fi, D_DIR);  //necessary to reset after rmdir? 
		while(k < i){
			ret = _findnext(&fi);
			k++;
		}
	} 
	
	from[len_from] = 0;
	to[len_to]= 0;
	copyAllFiles(from, to, overwrite);
}
示例#2
0
void JobDeployment::copyAllFiles(const std::string &srcDir, 
                                 const std::string &destDir, 
                                 const std::string &ignore)
{
   dtUtil::FileUtils &fileUtils = dtUtil::FileUtils::GetInstance();

   // traverse files in source directory
   dtUtil::DirectoryContents files = fileUtils.DirGetFiles( srcDir );
   for( dtUtil::DirectoryContents::const_iterator itr = files.begin(); itr!=files.end(); ++itr )
   {
      std::string child  = *itr;
      std::string newSrc = RelativeToAbsolutePath( child, srcDir );
      dtUtil::FileInfo fileInfo = fileUtils.GetFileInfo( newSrc );

      // ignore certain files or directories
      if ( child == "." || child == ".." || child == ignore )
      {
         continue;
      }

      // handle directories
      else if ( fileInfo.fileType == dtUtil::DIRECTORY )
      {
         // create new destination directory if necessary
         std::string newDestDir = RelativeToAbsolutePath( child, destDir );
         if ( !fileUtils.DirExists( newDestDir ) )
         {
            MakeDirectoryEX( newDestDir );
         }

         // copy all files in this sub-directory
         copyAllFiles( newSrc, newDestDir, ignore );
      }

      // handle files
      else if ( fileInfo.fileType == dtUtil::REGULAR_FILE )
      {
         try
         {
            fileUtils.FileCopy( newSrc, destDir, true );
         }
         catch ( dtUtil::Exception &e ) { e.Print(); }
      }
   }
}
示例#3
0
void run(Options& opts) {
  copyAllFiles(opts);

  ImageIO imageIO(opts);
  if (!imageIO.Good) {
    std::cerr << "Unable to process input folder structure. Terminating." << std::endl;
    exit(1);
  }

  for (auto& volumeIO: imageIO.Volumes) {
    std::cout << "Finding events on Volume: " << volumeIO->Name << std::endl;

    imageIO.SqliteHelper.beginTransaction();
    for (auto& snapshotIO: volumeIO->Snapshots) {
      std::cout << "Parsing input files for snapshot: " << snapshotIO->Name << std::endl;
      processStep(*snapshotIO, opts.extra);
      std::cout << std::endl;
    }
    imageIO.SqliteHelper.endTransaction();
    imageIO.SqliteHelper.beginTransaction();

    std::cout << std::endl << "Generating unified events output..." << std::endl;
    volumeIO->Events << Event::getColumnHeaders();
    std::vector<SnapshotIOPtr>::reverse_iterator rIt;
    for (rIt = volumeIO->Snapshots.rbegin(); rIt != volumeIO->Snapshots.rend(); ++rIt) {
      std::cout << "Processing events from snapshot: " << (*rIt)->Name << std::endl;
      processFinalize(**rIt);
    }

    imageIO.SqliteHelper.endTransaction();
  }
  imageIO.SqliteHelper.close();
  std::cout << std::endl;
  std::cout << imageIO.getSummary() << std::endl;
  std::cout << "Process complete." << std::endl;

}
示例#4
0
void JobDeployment::Execute( PackageProfile *profile )
{
   // make sure the section we are interested in, exists
   const XMLNode *chunk = profile->GetChunk( "Deployment" );
   if ( chunk == NULL )
   {
      std::cout << "[Error] 'Deployment' section is missing in project profile!" << std::endl;
      return;
   }

   // needed vars
   dtUtil::FileUtils &fileUtils = dtUtil::FileUtils::GetInstance();

   // cache working directory
   const std::string &cwd = fileUtils.CurrentDirectory();

   // output
   std::cout << "Deploying specified files." << std::endl;

   // check if output directory exists, if not then create it
   std::string outputDir = profile->GetOutputDirectory();
   if ( !fileUtils.DirExists( outputDir ) )
   {
      std::cout << "[Warning] Output directory does not exist, creating it now." << std::endl;
      MakeDirectoryEX( outputDir );
   }

   // get all deployment input directory elements
   std::vector<const XMLNode*> inputElements;
   profile->GetDeploymentInputDirectoryElements( inputElements );

   //loop through each input element and copy files from it to output directory
   for ( unsigned int i=0; i<inputElements.size(); i++)
   {
      //retrieve input directory string, resolving all environment variables
      const XMLNode *inputElement = inputElements[i];
      std::string inputDir = ResolveEnvironmentVariables(profile->GetElementAttribute(inputElement, "location"));

      //change to directory we are copying files from
      if ( inputDir.length() == 0 || !fileUtils.DirExists( inputDir ) )
      {
         std::cout << "[Error] Input directory '" << inputDir << "' does not exist." << std::endl;
         continue;
      }
      fileUtils.ChangeDirectory( inputDir );

      // get all the files we need to deploy
      std::vector<std::string>   fileNames;
      std::vector<Options>       fileOptions;
      profile->GetDeploymentContents(inputElement, fileNames, fileOptions);

      // traverse list of files
      for ( unsigned int i=0; i<fileNames.size(); i++ )
      {
         // gather file information
         std::string subpath  = GetFilePath( fileNames[i] );
         std::string file     = GetFileName( fileNames[i] );
         std::string fileName = GetFileNameNoExt( fileNames[i] );
         std::string fileExt  = GetFileExtension( fileNames[i] );
         std::string srcDir   = inputDir;
         std::string destDir  = outputDir;

         // file is located in a relative subdirectory
         if(!subpath.empty())
         {
            srcDir  = RelativeToAbsolutePath( subpath, inputDir );
            destDir = RelativeToAbsolutePath( subpath, outputDir );

            // make sure this relative input directory actually exists
            if ( !fileUtils.DirExists( srcDir ) )
            {
               std::cout << "[Warning] Directory '" << srcDir << "' does not exist." << std::endl;
               continue;
            }

            // create new destination directory if necessary
            MakeDirectoryEX( destDir );
         }

         // copy everything!
         if ( file == "*.*" )
         {
            std::string whatToIgnore = fileOptions[i].Get( std::string("ignore") );
            copyAllFiles( srcDir, destDir, whatToIgnore );
         }

         // copy all files of a certain extension
         else if ( fileName == "*" )
         {
            dtUtil::DirectoryContents files = fileUtils.DirGetFiles( srcDir );

            for( dtUtil::DirectoryContents::const_iterator itr = files.begin(); itr!=files.end(); ++itr )
            {            
               if ( GetFileExtension( itr->c_str() ) == fileExt )
               {
                  try
                  {
                     std::string absFile = RelativeToAbsolutePath( itr->c_str(), srcDir );
                     fileUtils.FileCopy( absFile, destDir, true );
                  }
                  catch ( dtUtil::Exception &e ) { e.Print(); }
               }
            }
         }

         // copy a single file
         else
         {
            try
            {
               std::string absFile = RelativeToAbsolutePath( file, srcDir );
               fileUtils.FileCopy( absFile, destDir, true );
            }
            catch ( dtUtil::Exception &e ) { e.Print(); }
         }

         // sign any JAR files
         if ( fileExt == "jar" || fileExt == "JAR" )
         {
            if ( fileOptions[i].Get( "sign" ) == "true" )
            {
               std::string absFile = RelativeToAbsolutePath( file, destDir );
               std::string cmdString;

               // used for signing JAR files
               std::string keystore = profile->GetKeystoreFile();
               std::string key = profile->GetKeystoreKey();
               std::string password = profile->GetKeystorePassword();

               if ( !IsAbsolutePath( keystore ) )
               {      
                  keystore = RelativeToAbsolutePath( keystore, cwd );
               }
               
               // sign the JAR file
               // example: jarsigner -J"-Xmx256m" -keystore C:/SomeDirectory/netc.keystore bleh.jar myKey
               std::cout << "Signing " << fileNames[i] << std::endl;
               cmdString = "jarsigner -storepass ";
               cmdString += password;
               cmdString += " -J\"-Xmx256m\" -keystore ";
               cmdString += "\"" + keystore + "\"";
               cmdString += " ";
               cmdString += "\"" + absFile + "\"";
               cmdString += " " + key;
               system( cmdString.c_str() );
            }
         }
      }
   }

   // restore working directory
   fileUtils.ChangeDirectory( cwd );

   // confirmation
   std::cout << "Deployment files copied." << std::endl;
}