Skip to content

Instantly share code, notes, and snippets.

@mhutch

mhutch/- Secret

Created Sep 23, 2013
Embed
What would you like to do?
diff --git a/main/external/nrefactory b/main/external/nrefactory
--- a/main/external/nrefactory
+++ b/main/external/nrefactory
@@ -1 +1 @@
-Subproject commit 927cc8fd55b38af111eff07c018f2d4bbac74bc0
+Subproject commit 927cc8fd55b38af111eff07c018f2d4bbac74bc0-dirty
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TypeSystemService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TypeSystemService.cs
index e134429..381c668 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TypeSystemService.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.TypeSystem/TypeSystemService.cs
@@ -506,27 +506,17 @@ namespace MonoDevelop.Ide.TypeSystem
static string InternalGetCacheDirectory (FilePath filename)
{
- CanonicalizePath (ref filename);
string result;
- var nameNoExtension = Path.GetFileName (filename);
- var derivedDataPath = UserProfile.Current.CacheDir.Combine ("DerivedData");
+
+ CanonicalizePath (ref filename);
+ var assemblyCacheRoot = GetAssemblyCacheRoot (filename);
+
try {
- // First try to access what we think could be the correct file directly
- if (CheckCacheDirectoryIsCorrect (filename, derivedDataPath.Combine (nameNoExtension), out result))
- return result;
-
- if (Directory.Exists (derivedDataPath)) {
- // next check any directory which contains the filename
- foreach (var subDir in Directory.EnumerateDirectories (derivedDataPath).Where (s=> s.Contains (nameNoExtension))) {
- if (CheckCacheDirectoryIsCorrect (filename, subDir, out result)) {
- return result;
- }
- }
-/* // Finally check every remaining directory
- foreach (var subDir in subDirs.Where (s=> !s.Contains (nameNoExtension)))
- if (CheckCacheDirectoryIsCorrect (filename, subDir, out result))
- return result;*/
- }
+ if (!Directory.Exists (assemblyCacheRoot))
+ return null;
+ foreach (var dir in Directory.EnumerateDirectories (assemblyCacheRoot))
+ if (CheckCacheDirectoryIsCorrect (filename, dir, out result))
+ return result;
} catch (Exception e) {
LoggingService.LogError ("Error while getting derived data directories.", e);
}
@@ -634,26 +624,29 @@ namespace MonoDevelop.Ide.TypeSystem
}
}
- static string GetName (string baseName, int i)
+ static string GetAssemblyCacheRoot (string filename)
{
- if (i == 0)
- return baseName;
- return baseName + "-" + i;
+ string derivedDataPath = UserProfile.Current.CacheDir.Combine ("DerivedData");
+ string name = Path.GetFileName (filename);
+ return Path.Combine (derivedDataPath, name + "-" + name.GetHashCode ().ToString ("x"));
+ }
+
+ static IEnumerable<string> GetPossibleCacheDirNames (string baseName)
+ {
+ int i = 0;
+ while (i < 4096) {
+ yield return Path.Combine (baseName, i.ToString ());
+ i++;
+ }
+ throw new Exception ("Too many cache directories");
}
static string CreateCacheDirectory (FilePath fileName)
{
CanonicalizePath (ref fileName);
try {
- string derivedDataPath = UserProfile.Current.CacheDir.Combine ("DerivedData");
- string name = Path.GetFileName (fileName);
- string baseName = Path.Combine (derivedDataPath, name);
- int i = 0;
- while (Directory.Exists (GetName (baseName, i)))
- i++;
-
- string cacheDir = GetName (baseName, i);
-
+ string cacheRoot = GetAssemblyCacheRoot (fileName);
+ string cacheDir = GetPossibleCacheDirNames (cacheRoot).First (d => !Directory.Exists (d));
Directory.CreateDirectory (cacheDir);
File.WriteAllText (
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment