|
2 | 2 |
|
3 | 3 | import com.hp.hpl.jena.query.Dataset; |
4 | 4 | import com.hp.hpl.jena.tdb.TDBFactory; |
| 5 | +import com.hp.hpl.jena.tdb.base.file.Location; |
5 | 6 | import org.apache.commons.io.file.PathUtils; |
6 | 7 | import ubic.basecode.ontology.model.OntologyModel; |
7 | 8 |
|
@@ -48,17 +49,23 @@ public TdbOntologyService( String ontologyName, Path tdbDir, @Nullable String mo |
48 | 49 | protected OntologyModel loadModel( boolean processImports, LanguageLevel languageLevel, InferenceMode inferenceMode ) throws IOException { |
49 | 50 | if ( dataset == null ) { |
50 | 51 | if ( readOnly ) { |
51 | | - Set<Path> filesToLink; |
52 | | - try ( Stream<Path> z = Files.list( tdbDir ) ) { |
53 | | - filesToLink = z.collect( Collectors.toSet() ); |
54 | | - } |
55 | | - tempDir = Files.createTempDirectory( getOntologyName() + ".tdb" ); |
56 | | - for ( Path p : filesToLink ) { |
57 | | - Files.createSymbolicLink( tempDir.resolve( p.getFileName() ), p ); |
| 52 | + // lock the location and make a copy |
| 53 | + Location loc = Location.create( tdbDir.toString() ); |
| 54 | + loc.getLock().obtain(); |
| 55 | + try { |
| 56 | + Set<Path> filesToLink; |
| 57 | + try ( Stream<Path> z = Files.list( tdbDir ) ) { |
| 58 | + filesToLink = z.collect( Collectors.toSet() ); |
| 59 | + } |
| 60 | + tempDir = Files.createTempDirectory( getOntologyName() + ".tdb" ); |
| 61 | + for ( Path p : filesToLink ) { |
| 62 | + Files.copy( p, tempDir.resolve( p.getFileName() ) ); |
| 63 | + } |
| 64 | + } finally { |
| 65 | + loc.getLock().release(); |
58 | 66 | } |
59 | 67 | log.info( "Reading read-only TDB model from {}.", tempDir ); |
60 | 68 | dataset = TDBFactory.createDataset( tempDir.toString() ); |
61 | | - |
62 | 69 | } else { |
63 | 70 | dataset = TDBFactory.createDataset( tdbDir.toString() ); |
64 | 71 | } |
|
0 commit comments