Skip to content
Permalink
Browse files

[NuGet] Remove deleted xenko sources during startup to avoid restore …

…failures (fixes #338)
  • Loading branch information
xen2 committed Feb 22, 2019
1 parent 2c3f881 commit 293d60a2bdc4b6d2773a1da914fd802483828288
@@ -66,7 +66,9 @@ public NugetStore(string oldRootDirectory)
settings = NuGet.Configuration.Settings.LoadDefaultSettings(null);

// Add dev source
RemoveDeletedSources(settings, "Xenko");
CheckPackageSource("Xenko", DefaultPackageSource);
settings.SaveToDisk();

InstallPath = SettingsUtility.GetGlobalPackagesFolder(settings);

@@ -83,10 +85,29 @@ public NugetStore(string oldRootDirectory)
sourceRepositoryProvider = new NugetSourceRepositoryProvider(packageSourceProvider, this);
}

private static void RemoveDeletedSources(ISettings settings, string prefixName)
{
var packageSources = settings.GetSection("packageSources");
if (packageSources != null)
{
foreach (var packageSource in packageSources.Items.OfType<SourceItem>().ToList())
{
var path = packageSource.GetValueAsPath();

if (packageSource.Key.StartsWith(prefixName)
&& Uri.TryCreate(path, UriKind.Absolute, out var uri) && uri.IsFile // make sure it's a valid file URI
&& !Directory.Exists(path)) // detect if directory has been deleted
{
// Remove entry from packageSources
settings.Remove("packageSources", packageSource);
}
}
}
}

private void CheckPackageSource(string name, string url)
{
settings.AddOrUpdate("packageSources", new SourceItem(name, url));
settings.SaveToDisk();
}

private readonly NugetSourceRepositoryProvider sourceRepositoryProvider;
@@ -43,7 +43,10 @@ internal static void __Initialize__()
{
xenkoFolder = folder;
var settings = NuGet.Configuration.Settings.LoadDefaultSettings(null);
// Remove non-existing sources: https://github.com/xenko3d/xenko/issues/338
RemoveDeletedSources(settings, "Xenko");
CheckPackageSource(settings, $"Xenko Dev {xenkoFolder}", Path.Combine(xenkoFolder, @"bin\packages"));
settings.SaveToDisk();
break;
}
folder = Path.GetDirectoryName(folder);
@@ -112,10 +115,29 @@ internal static void __Initialize__()
};
}

private static void RemoveDeletedSources(ISettings settings, string prefixName)
{
var packageSources = settings.GetSection("packageSources");
if (packageSources != null)
{
foreach (var packageSource in packageSources.Items.OfType<SourceItem>().ToList())
{
var path = packageSource.GetValueAsPath();

if (packageSource.Key.StartsWith(prefixName)
&& Uri.TryCreate(path, UriKind.Absolute, out var uri) && uri.IsFile // make sure it's a valid file URI
&& !Directory.Exists(path)) // detect if directory has been deleted
{
// Remove entry from packageSources
settings.Remove("packageSources", packageSource);
}
}
}
}

private static void CheckPackageSource(ISettings settings, string name, string url)
{
settings.AddOrUpdate("packageSources", new SourceItem(name, url));
settings.SaveToDisk();
}

public class Logger : ILogger

0 comments on commit 293d60a

Please sign in to comment.
You can’t perform that action at this time.