@@ -73,16 +73,16 @@ public class ROBundleService {
73
73
private final Logger logger = LoggerFactory .getLogger (this .getClass ());
74
74
75
75
// Services
76
- private GraphVizService graphVizService ;
77
- private GitService gitService ;
78
- private RDFService rdfService ;
79
- private CWLTool cwlTool ;
80
- private GitSemaphore gitSemaphore ;
76
+ private final GraphVizService graphVizService ;
77
+ private final GitService gitService ;
78
+ private final RDFService rdfService ;
79
+ private final CWLTool cwlTool ;
80
+ private final GitSemaphore gitSemaphore ;
81
81
82
82
// Configuration variables
83
- private Agent appAgent ;
84
- private int singleFileSizeLimit ;
85
- private Path bundleStorage ;
83
+ private final Agent appAgent ;
84
+ private final int singleFileSizeLimit ;
85
+ private final Path bundleStorage ;
86
86
87
87
// Pattern for extracting version from a cwl file
88
88
private final String CWL_VERSION_REGEX = "cwlVersion:\\ s*\" ?(?:cwl:)?([^\\ s\" ]+)\" ?" ;
@@ -129,6 +129,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
129
129
Manifest manifest = bundle .getManifest ();
130
130
131
131
// Simplified attribution for RO bundle
132
+ Git gitRepo = null ;
132
133
try {
133
134
manifest .setId (new URI (workflow .getPermalink ()));
134
135
@@ -150,7 +151,8 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
150
151
Set <HashableAgent > authors = new HashSet <>();
151
152
152
153
boolean safeToAccess = gitSemaphore .acquire (gitInfo .getRepoUrl ());
153
- try (Git gitRepo = gitService .getRepository (workflow .getRetrievedFrom (), safeToAccess )) {
154
+ try {
155
+ gitRepo = gitService .getRepository (workflow .getRetrievedFrom (), safeToAccess );
154
156
Path relativePath = Paths .get (FilenameUtils .getPath (gitInfo .getPath ()));
155
157
Path gitPath = gitRepo .getRepository ().getWorkTree ().toPath ().resolve (relativePath );
156
158
addFilesToBundle (gitInfo , bundle , bundlePath , gitRepo , gitPath , authors , workflow );
@@ -194,7 +196,7 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
194
196
addAggregation (bundle , manifestAnnotations ,
195
197
"merged.cwl" , cwlTool .getPackedVersion (rawUrl ));
196
198
} catch (CWLValidationException ex ) {
197
- logger .error ("Could not pack workflow when creating Research Object" , ex . getMessage () );
199
+ logger .error ("Could not pack workflow when creating Research Object" , ex );
198
200
}
199
201
String rdfUrl = workflow .getIdentifier ();
200
202
if (rdfService .graphExists (rdfUrl )) {
@@ -216,6 +218,19 @@ public Bundle createBundle(Workflow workflow, GitDetails gitInfo) throws IOExcep
216
218
logger .error ("Error creating URI for RO Bundle" , ex );
217
219
} catch (GitAPIException ex ) {
218
220
logger .error ("Error getting repository to create RO Bundle" , ex );
221
+ } finally {
222
+ if (gitRepo != null ) {
223
+ gitRepo .close ();
224
+ File repoDir = gitRepo .getRepository ().getDirectory ();
225
+ try {
226
+ FileUtils .deleteDirectory (repoDir .getParentFile ());
227
+ } catch (IOException e ) {
228
+ logger .warn (
229
+ String .format ("Failed to delete Git repository directory: %s" , repoDir .getAbsolutePath ()),
230
+ e
231
+ );
232
+ }
233
+ }
219
234
}
220
235
221
236
// Return the completed bundle
0 commit comments