@@ -88,11 +88,37 @@ public static string GetSourceDirectory(string rootPropertyName, string relative
88
88
89
89
public static DirectoryInfo DetermineIndexDir ( String directoryProviderName , IDictionary properties )
90
90
{
91
- string indexBase = ( string ) properties [ "indexBase" ] ?? "." ;
92
- string indexName = ( string ) properties [ "indexName" ] ?? directoryProviderName ;
91
+ string indexBase = ( string ) properties [ "indexBase" ] ;
92
+
93
+ if ( indexBase == null )
94
+ {
95
+ indexBase = "." ;
96
+ }
97
+ else if ( indexBase . StartsWith ( "~" ) )
98
+ {
99
+ // We need this to allow using the search from the web, where the "." directory is somewhere in the system root.
100
+ indexBase = indexBase . Replace ( "~" , AppDomain . CurrentDomain . BaseDirectory ) ;
101
+ }
102
+ else if ( indexBase . StartsWith ( ".." ) )
103
+ {
104
+ // determine the indexBase path when using parent directory (eg. "../indexes")
105
+
106
+ DirectoryInfo targetParentDir = new DirectoryInfo ( AppDomain . CurrentDomain . BaseDirectory ) ;
107
+
108
+ string path = indexBase ;
109
+
110
+ while ( path . StartsWith ( ".." ) )
111
+ {
112
+ if ( targetParentDir . Parent == null )
113
+ throw new HibernateException ( "IndexBase path not valid" ) ;
114
+
115
+ targetParentDir = targetParentDir . Parent ;
116
+ path = path . Remove ( 0 , 3 ) ;
117
+ }
118
+
119
+ indexBase = Path . Combine ( targetParentDir . FullName , path ) ;
120
+ }
93
121
94
- // We need this to allow using the search from the web, where the "." directory is somewhere in the system root.
95
- indexBase = indexBase . Replace ( "~" , AppDomain . CurrentDomain . BaseDirectory ) ;
96
122
DirectoryInfo indexDir = new DirectoryInfo ( indexBase ) ;
97
123
if ( ! indexDir . Exists )
98
124
{
@@ -105,8 +131,9 @@ public static DirectoryInfo DetermineIndexDir(String directoryProviderName, IDic
105
131
throw new HibernateException ( "Cannot write into index directory: " + indexBase ) ;
106
132
}
107
133
108
- indexDir = new DirectoryInfo ( Path . Combine ( indexDir . FullName , indexName ) ) ;
109
- return indexDir ;
134
+ string indexName = ( string ) properties [ "indexName" ] ?? directoryProviderName ;
135
+
136
+ return new DirectoryInfo ( Path . Combine ( indexDir . FullName , indexName ) ) ;
110
137
}
111
138
112
139
private static bool HasWriteAccess ( DirectoryInfo indexDir )
0 commit comments