2016-07-28 25 views
0

當我嘗試擴展apache-maven以使其支持外部下載程序而不檢查校驗和時,我發現此問題。爲什麼我無法在JVM子進程中打開一個新文件?

的預期的外部下載是axel和我的溶液改寫maven-wagongetTransfertransfer方法以及用於檢查aether-core加入checksums開關。

除了由mvn命令創建的新子過程axel告訴我No state file, cannot resume!以外,所有工作都正常。

我讀過的axel源之後,我想它,它meaned無法訪問state文件,標誌F_OK,它總是與擴展.st,應標誌O_CREAT | O_TRUNC | O_WRONLY在開始創建。

我的代碼如下:

protected void transfer(Resource resource, String url, File output, int requestType) throws IOException { 
    byte[] buffer = new byte[0]; 
    TransferEvent transferEvent = new TransferEvent(this, resource, 3, requestType); 
    transferEvent.setTimestamp(System.currentTimeMillis()); 
    Runtime runtime = Runtime.getRuntime(); 
    ArrayList cmdLine = new ArrayList(DOWNLOADER); 
    cmdLine.add(output.getAbsoluteFile().getAbsolutePath()); 
    cmdLine.add(url); 
    File parent = output.getParentFile(); 
    if(!parent.exists()) { 
     parent.mkdirs(); 
    } 

    Process process = runtime.exec((String[])cmdLine.toArray(new String[cmdLine.size()]), (String[])null, parent); 
    BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); 
    String stdout = br.readLine(); 
    float progress = 0.0F; 

    for(float previous = 0.0F; stdout != null; stdout = br.readLine()) { 
     Matcher matcher = PATTERN.matcher(stdout); 
     if(matcher.matches()) { 
      String stringProgress = matcher.group(1); 
      progress = Float.valueOf("0." + stringProgress).floatValue(); 
      this.fireTransferProgress(transferEvent, buffer, Float.valueOf((float)resource.getContentLength() * (progress - previous)).intValue()); 
      previous = progress; 
     } 
    } 

    br.close(); 
    if(progress != 100.0F) { 
     StringBuilder sb = new StringBuilder(); 
     br = new BufferedReader(new InputStreamReader(process.getErrorStream())); 

     for(String stderr = br.readLine(); stderr != null; stderr = br.readLine()) { 
      sb.append(stderr); 
     } 

     if(sb.length() > 0) { 
      this.fireTransferError(resource, new Exception(sb.toString()), 5); 
     } 
    } 

} 

我想這可能是特權的問題,和目標目錄的狀態看起來像(PS:我在我的機器名爲simple用戶): enter image description here

國家mvn命令: enter image description here

命令axel的狀態是: enter image description here

PS:對不起,無法將文本粘貼到該編輯器spam原因,我不知道爲什麼計算器認爲這個問題可能會是spam

我的問題是我可以在JVM的子流程中創建一個新文件嗎?如果可以,我應該如何設置特權?那麼我還不知道這種方法有什麼缺陷或缺陷?

任何建議將不勝感激,謝謝!

回答

0

所以問題變得很簡單。真正的原因是-o選項傳遞給axel。如果用戶指定此選項,axel將嘗試加載位於當前目錄中的名稱爲擴展名爲.st的原始名稱的狀態文件。

但是,我試圖從遠程存儲庫下載全新的文件,並且沒有這種狀態文件存在。

當我刪除這個選項,所有的事情都很好。

相關問題