Source:
<code>private void provisionWorkflowVersionUploadFiles(ApiClient zendoClient, Deposit returnDeposit, int depositionID, Workflow workflow, WorkflowVersion workflowVersion) { FilesApi filesApi = new FilesApi(zendoClient); List<DepositionFile> originalFilesInNewVersion = returnDeposit.getFiles(); Iterator filesIter = originalFilesInNewVersion.iterator(); while (filesIter.hasNext()) { String fileIdStr = ((DepositionFile)filesIter.next()).getId(); filesApi.deleteFile(depositionID, fileIdStr); } Set<SourceFile> sourceFiles = workflowVersion.getSourceFiles(); java.nio.file.Path path = Paths.get(workflowVersion.getWorkingDirectory()); if (sourceFiles == null || sourceFiles.size() == 0) { LOG.warn("No source files found to zip when creating DOI"); throw new CustomWebApplicationException("No source files found to" + " upload when creating DOI. Zenodo requires at lease one file" + " to be uploaded in order to create a DOI.", HttpStatus.SC_BAD_REQUEST); } else { String fileName = workflow.getWorkflowPath().replaceAll("/", "-") + ".zip"; OutputStream outputStream; try { <START> outputStream = new FileOutputStream(fileName); <END> } catch (FileNotFoundException fne) { throw new CustomWebApplicationException("Could not create file " + fileName + " outputstream for DOI zip file for upload to Zenodo." + " Error is " + fne.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR); } writeStreamAsZip(sourceFiles, outputStream, path); java.nio.file.Path zipPath = Paths.get(fileName); File zipFile = zipPath.toFile(); try { filesApi.createFile(depositionID, zipFile, fileName); } catch (ApiException e) { LOG.error("Could not create files for new version on Zenodo. Error is " + e.getMessage()); throw new CustomWebApplicationException("Could not create files for new version on Zenodo." + " Error is " + e.getMessage(), HttpStatus.SC_BAD_REQUEST); } } }</code><technical_language>this file get deleted FilesAPI line 1076? If not, need delete it. create this is in a temporary directory. Right putting in essentially a user-specified location, dangerous</technical_language>

Target:
private void provisionWorkflowVersionUploadFiles(ApiClient zendoClient, Deposit returnDeposit, int depositionID, Workflow workflow, WorkflowVersion workflowVersion) { FilesApi filesApi = new FilesApi(zendoClient); List<DepositionFile> originalFilesInNewVersion = returnDeposit.getFiles(); Iterator filesIter = originalFilesInNewVersion.iterator(); while (filesIter.hasNext()) { String fileIdStr = ((DepositionFile)filesIter.next()).getId(); filesApi.deleteFile(depositionID, fileIdStr); } Set<SourceFile> sourceFiles = workflowVersion.getSourceFiles(); java.nio.file.Path path = Paths.get(workflowVersion.getWorkingDirectory()); if (sourceFiles == null || sourceFiles.size() == 0) { LOG.warn("No source files found to zip when creating DOI"); throw new CustomWebApplicationException("No source files found to" + " upload when creating DOI. Zenodo requires at lease one file" + " to be uploaded in order to create a DOI.", HttpStatus.SC_BAD_REQUEST); } else { String fileName = workflow.getWorkflowPath().replaceAll("/", "-") + ".zip"; OutputStream outputStream; try { outputStream = new FileOutputStream(fileName); } catch (FileNotFoundException fne) { LOG.error("Could not create file " + fileName + " outputstream for DOI zip file for upload to Zenodo." + " Error is " + fne.getMessage(), fne); throw new CustomWebApplicationException("Could not create file " + fileName + " outputstream for DOI zip file for upload to Zenodo." + " Error is " + fne.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR); } writeStreamAsZip(sourceFiles, outputStream, path); java.nio.file.Path zipPath = Paths.get(fileName); File zipFile = zipPath.toFile(); try { filesApi.createFile(depositionID, zipFile, fileName); } catch (ApiException e) { LOG.error("Could not create files for new version on Zenodo. Error is " + e.getMessage(), e); throw new CustomWebApplicationException("Could not create files for new version on Zenodo." + " Error is " + e.getMessage(), HttpStatus.SC_BAD_REQUEST); } } }