Skip to content

Commit

Permalink
Fixing path issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende authored and synhershko committed Nov 17, 2011
1 parent d644f79 commit 1f532dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Raven.Database/Indexing/IndexStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected Lucene.Net.Store.Directory OpenOrCreateLuceneDirectory(IndexDefinition
else
{
var indexDirectory = indexName ?? IndexDefinitionStorage.FixupIndexName(indexDefinition.Name, path);
var indexFullPath = Path.Combine(path, MonoHttpUtility.UrlEncode(indexDirectory));
var indexFullPath = Path.Combine(path, indexDirectory);
directory = FSDirectory.Open(new DirectoryInfo(indexFullPath));

if (!IndexReader.IndexExists(directory))
Expand All @@ -101,7 +101,7 @@ protected Lucene.Net.Store.Directory OpenOrCreateLuceneDirectory(IndexDefinition

internal Lucene.Net.Store.Directory MakeRAMDirectoryPhysical(RAMDirectory ramDir, string indexName)
{
var newDir = FSDirectory.Open(new DirectoryInfo(Path.Combine(path, MonoHttpUtility.UrlEncode(IndexDefinitionStorage.FixupIndexName(indexName, path)))));
var newDir = FSDirectory.Open(new DirectoryInfo(Path.Combine(path, IndexDefinitionStorage.FixupIndexName(indexName, path))));
Lucene.Net.Store.Directory.Copy(ramDir, newDir, true);
return newDir;
}
Expand Down
13 changes: 7 additions & 6 deletions Raven.Database/Storage/IndexDefinitionStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public string AddIndex(IndexDefinition indexDefinition)
if (configuration.RunInMemory == false)
{
var encodeIndexNameIfNeeded = FixupIndexName(indexDefinition.Name, path);
var indexName = Path.Combine(path, MonoHttpUtility.UrlEncode(encodeIndexNameIfNeeded) + ".index");
var indexName = Path.Combine(path, encodeIndexNameIfNeeded + ".index");
// Hash the name if it's too long (as a path)
File.WriteAllText(indexName, JsonConvert.SerializeObject(indexDefinition, Formatting.Indented, Default.Converters));
}
Expand Down Expand Up @@ -168,13 +168,13 @@ public void RemoveIndex(string name)
private string GetIndexSourcePath(string name)
{
var encodeIndexNameIfNeeded = FixupIndexName(name, path);
return Path.Combine(path, MonoHttpUtility.UrlEncode(encodeIndexNameIfNeeded) + ".index.cs");
return Path.Combine(path, encodeIndexNameIfNeeded + ".index.cs");
}

private string GetIndexPath(string name)
{
var encodeIndexNameIfNeeded = FixupIndexName(name, path);
return Path.Combine(path, MonoHttpUtility.UrlEncode(encodeIndexNameIfNeeded) + ".index");
return Path.Combine(path, encodeIndexNameIfNeeded + ".index");
}


Expand Down Expand Up @@ -224,16 +224,17 @@ public static string FixupIndexName(string index, string path)
{
prefix = index.Substring(0, 5);
}
if (path.Length + index.Length > 230 ||
var fixupIndexName = MonoHttpUtility.UrlEncode(index);
if (path.Length + fixupIndexName.Length > 230 ||
Encoding.Unicode.GetByteCount(index) >= 255)
{
using (var md5 = MD5.Create())
{
var bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(index));
return prefix + Convert.ToBase64String(bytes);
return MonoHttpUtility.UrlEncode(prefix + Convert.ToBase64String(bytes));
}
}
return index;
return fixupIndexName;
}

public static void ResolveAnalyzers(IndexDefinition indexDefinition)
Expand Down

0 comments on commit 1f532dd

Please sign in to comment.