Program: 105196
Project: 105196
Buggy source:
/** 
 * Post local download activity (install and cleanup). Executed in context of downloader thread
 * @throws IOException
 */
private String postLocalDownload(String jobId){
  DownloadJob dnld=jobs.get(jobId);
  TemplateDownloader td=dnld.getTemplateDownloader();
  String resourcePath=dnld.getInstallPathPrefix();
  String finalResourcePath=dnld.getTmpltPath();
  ResourceType resourceType=dnld.getResourceType();
  File originalTemplate=new File(td.getDownloadLocalPath());
  String checkSum=computeCheckSum(originalTemplate);
  if (checkSum == null) {
    s_logger.warn("String_Node_Str");
  }
  dnld.setCheckSum(checkSum);
  int imgSizeGigs=(int)Math.ceil(_storage.getSize(td.getDownloadLocalPath()) * 1.0d / (1024 * 1024 * 1024));
  imgSizeGigs++;
  long timeout=(long)imgSizeGigs * installTimeoutPerGig;
  Script scr=null;
  String script=resourceType == ResourceType.TEMPLATE ? createTmpltScr : createVolScr;
  scr=new Script(script,timeout,s_logger);
  scr.add("String_Node_Str",Integer.toString(imgSizeGigs));
  scr.add("String_Node_Str",Long.toString(td.getMaxTemplateSizeInBytes()));
  if (dnld.getDescription() != null && dnld.getDescription().length() > 1) {
    scr.add("String_Node_Str",dnld.getDescription());
  }
  if (dnld.isHvm()) {
    scr.add("String_Node_Str");
  }
  String extension=dnld.getFormat().getFileExtension();
  String templateName="String_Node_Str";
  if (extension.equals("String_Node_Str")) {
    templateName=jobs.get(jobId).getTmpltName().trim().replace("String_Node_Str","String_Node_Str");
  }
 else {
    templateName=java.util.UUID.nameUUIDFromBytes((jobs.get(jobId).getTmpltName() + System.currentTimeMillis()).getBytes()).toString();
  }
  String templateFilename=templateName + "String_Node_Str" + extension;
  dnld.setTmpltPath(finalResourcePath + "String_Node_Str" + templateFilename);
  scr.add("String_Node_Str",templateFilename);
  scr.add("String_Node_Str",resourcePath);
  scr.add("String_Node_Str",td.getDownloadLocalPath());
  if (dnld.getChecksum() != null && dnld.getChecksum().length() > 1) {
    scr.add("String_Node_Str",dnld.getChecksum());
  }
  scr.add("String_Node_Str");
  String result;
  result=scr.execute();
  if (result != null) {
    return result;
  }
  File downloadedTemplate=new File(resourcePath + "String_Node_Str" + templateFilename);
  _storage.setWorldReadableAndWriteable(downloadedTemplate);
  String propertiesFile=resourcePath;
  if (resourceType == ResourceType.TEMPLATE) {
    propertiesFile+="String_Node_Str";
  }
 else {
    propertiesFile+="String_Node_Str";
  }
  File templateProperties=new File(propertiesFile);
  _storage.setWorldReadableAndWriteable(templateProperties);
  TemplateLocation loc=new TemplateLocation(_storage,resourcePath);
  try {
    loc.create(dnld.getId(),true,dnld.getTmpltName());
  }
 catch (  IOException e) {
    s_logger.warn("String_Node_Str" + resourcePath,e);
    loc.purge();
    return "String_Node_Str" + e.getMessage();
  }
  Iterator<Processor> en=_processors.values().iterator();
  while (en.hasNext()) {
    Processor processor=en.next();
    FormatInfo info=null;
    try {
      info=processor.process(resourcePath,null,templateName);
    }
 catch (    InternalErrorException e) {
      s_logger.error("String_Node_Str",e);
      return e.toString();
    }
    if (info != null) {
      loc.addFormat(info);
      dnld.setTemplatesize(info.virtualSize);
      dnld.setTemplatePhysicalSize(info.size);
      break;
    }
  }
  if (!loc.save()) {
    s_logger.warn("String_Node_Str");
    loc.purge();
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Post local download activity (install and cleanup). Executed in context of downloader thread
 * @throws IOException
 */
private String postLocalDownload(String jobId){
  DownloadJob dnld=jobs.get(jobId);
  TemplateDownloader td=dnld.getTemplateDownloader();
  String resourcePath=dnld.getInstallPathPrefix();
  String finalResourcePath=dnld.getTmpltPath();
  ResourceType resourceType=dnld.getResourceType();
  File originalTemplate=new File(td.getDownloadLocalPath());
  String checkSum=computeCheckSum(originalTemplate);
  if (checkSum == null) {
    s_logger.warn("String_Node_Str");
  }
  dnld.setCheckSum(checkSum);
  int imgSizeGigs=(int)Math.ceil(_storage.getSize(td.getDownloadLocalPath()) * 1.0d / (1024 * 1024 * 1024));
  imgSizeGigs++;
  long timeout=(long)imgSizeGigs * installTimeoutPerGig;
  Script scr=null;
  String script=resourceType == ResourceType.TEMPLATE ? createTmpltScr : createVolScr;
  scr=new Script(script,timeout,s_logger);
  scr.add("String_Node_Str",Integer.toString(imgSizeGigs));
  scr.add("String_Node_Str",Long.toString(td.getMaxTemplateSizeInBytes()));
  if (dnld.getDescription() != null && dnld.getDescription().length() > 1) {
    scr.add("String_Node_Str",dnld.getDescription());
  }
  if (dnld.isHvm()) {
    scr.add("String_Node_Str");
  }
  String extension=dnld.getFormat().getFileExtension();
  String templateName="String_Node_Str";
  if (extension.equals("String_Node_Str")) {
    templateName=jobs.get(jobId).getTmpltName().trim().replace("String_Node_Str","String_Node_Str");
  }
 else {
    templateName=java.util.UUID.nameUUIDFromBytes((jobs.get(jobId).getTmpltName() + System.currentTimeMillis()).getBytes(StringUtils.getPreferredCharset())).toString();
  }
  String templateFilename=templateName + "String_Node_Str" + extension;
  dnld.setTmpltPath(finalResourcePath + "String_Node_Str" + templateFilename);
  scr.add("String_Node_Str",templateFilename);
  scr.add("String_Node_Str",resourcePath);
  scr.add("String_Node_Str",td.getDownloadLocalPath());
  if (dnld.getChecksum() != null && dnld.getChecksum().length() > 1) {
    scr.add("String_Node_Str",dnld.getChecksum());
  }
  scr.add("String_Node_Str");
  String result;
  result=scr.execute();
  if (result != null) {
    return result;
  }
  File downloadedTemplate=new File(resourcePath + "String_Node_Str" + templateFilename);
  _storage.setWorldReadableAndWriteable(downloadedTemplate);
  String propertiesFile=resourcePath;
  if (resourceType == ResourceType.TEMPLATE) {
    propertiesFile+="String_Node_Str";
  }
 else {
    propertiesFile+="String_Node_Str";
  }
  File templateProperties=new File(propertiesFile);
  _storage.setWorldReadableAndWriteable(templateProperties);
  TemplateLocation loc=new TemplateLocation(_storage,resourcePath);
  try {
    loc.create(dnld.getId(),true,dnld.getTmpltName());
  }
 catch (  IOException e) {
    s_logger.warn("String_Node_Str" + resourcePath,e);
    loc.purge();
    return "String_Node_Str" + e.getMessage();
  }
  Iterator<Processor> en=_processors.values().iterator();
  while (en.hasNext()) {
    Processor processor=en.next();
    FormatInfo info=null;
    try {
      info=processor.process(resourcePath,null,templateName);
    }
 catch (    InternalErrorException e) {
      s_logger.error("String_Node_Str",e);
      return e.toString();
    }
    if (info != null) {
      loc.addFormat(info);
      dnld.setTemplatesize(info.virtualSize);
      dnld.setTemplatePhysicalSize(info.size);
      break;
    }
  }
  if (!loc.save()) {
    s_logger.warn("String_Node_Str");
    loc.purge();
  }
  return null;
}