You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/10/16 23:10:23 UTC
svn commit: r1532911 -
/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java
Author: andy
Date: Wed Oct 16 21:10:22 2013
New Revision: 1532911
URL: http://svn.apache.org/r1532911
Log:
Cope with in-memory locations: don't create filesystem objects.
Modified:
jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java
Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java?rev=1532911&r1=1532910&r2=1532911&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/base/file/Location.java Wed Oct 16 21:10:22 2013
@@ -78,35 +78,34 @@ public class Location {
return ;
}
- File file = new File(rootname) ;
+ ensure(rootname) ;
+ pathname = fixupName(rootname) ;
+ // Metafilename for a directory.
+ String metafileName = getPath(Names.directoryMetafile, Names.extMeta) ;
- if ( !file.exists() ) {
- file.mkdir() ;
- // throw new FileException("Not found: "+file.getAbsolutePath()) ;
- } else if ( !file.isDirectory() )
- throw new FileException("Not a directory: " + file.getAbsolutePath()) ;
-
- // MS Windows:
- // getCanonicalPath is only good enough for existing files.
- // It leaves the case as it finds it (upper, lower) and lower cases
- // not-existing segments. But later creation of a segment with uppercase
- // changes the exact string returned.
+ metafile = new MetaFile("Location: " + rootname, metafileName) ;
+ }
+ // MS Windows:
+ // getCanonicalPath is only good enough for existing files.
+ // It leaves the case as it finds it (upper, lower) and lower cases
+ // not-existing segments. But later creation of a segment with uppercase
+ // changes the exact string returned.
+ private String fixupName(String fsName) {
+ if ( isMem() )
+ return fsName ;
+ File file = new File(fsName) ;
try {
- pathname = file.getCanonicalPath() ;
+ fsName = file.getCanonicalPath() ;
} catch (IOException ex) {
throw new FileException("Failed to get canoncial path: " + file.getAbsolutePath(), ex) ;
}
- if ( !pathname.endsWith(File.separator) && !pathname.endsWith(pathSeparator) )
- pathname = pathname + pathSeparator ;
-
- // Metafilename for a directory.
- String metafileName = getPath(Names.directoryMetafile, Names.extMeta) ;
-
- metafile = new MetaFile("Location: " + rootname, metafileName) ;
+ if ( !fsName.endsWith(File.separator) && !fsName.endsWith(pathSeparator) )
+ fsName = fsName + pathSeparator ;
+ return fsName ;
}
-
+
public String getDirectoryPath() {
return pathname ;
}
@@ -125,15 +124,20 @@ public class Location {
public Location getSubLocation(String dirname) {
String newName = pathname + dirname ;
- File file = new File(newName) ;
+ ensure(newName) ;
+ return new Location(newName) ;
+ }
+
+ private void ensure(String dirname) {
+ if ( isMem() )
+ return ;
+ File file = new File(dirname) ;
if ( file.exists() && !file.isDirectory() )
throw new FileException("Existing file: " + file.getAbsolutePath()) ;
if ( !file.exists() )
file.mkdir() ;
-
- return new Location(newName) ;
}
-
+
public String getSubDirectory(String dirname) {
return getSubLocation(dirname).getDirectoryPath() ;
}