Skip to content

Commit db56557

Browse files
committed
Make a copy of the TDB database instead of using symlinks
1 parent 7a1e9de commit db56557

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/ubic/basecode/ontology/jena/TdbOntologyService.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.hp.hpl.jena.query.Dataset;
44
import com.hp.hpl.jena.tdb.TDBFactory;
5+
import com.hp.hpl.jena.tdb.base.file.Location;
56
import org.apache.commons.io.file.PathUtils;
67
import ubic.basecode.ontology.model.OntologyModel;
78

@@ -48,17 +49,23 @@ public TdbOntologyService( String ontologyName, Path tdbDir, @Nullable String mo
4849
protected OntologyModel loadModel( boolean processImports, LanguageLevel languageLevel, InferenceMode inferenceMode ) throws IOException {
4950
if ( dataset == null ) {
5051
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();
5866
}
5967
log.info( "Reading read-only TDB model from {}.", tempDir );
6068
dataset = TDBFactory.createDataset( tempDir.toString() );
61-
6269
} else {
6370
dataset = TDBFactory.createDataset( tdbDir.toString() );
6471
}

0 commit comments

Comments
 (0)