Skip to content
This repository was archived by the owner on Dec 18, 2017. It is now read-only.

Commit 7464ecb

Browse files
committed
Make '--ignore-failed-sources' work with local packages folders
1 parent 800e21f commit 7464ecb

File tree

3 files changed

+70
-7
lines changed

3 files changed

+70
-7
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Threading.Tasks;
8+
9+
namespace Microsoft.Framework.PackageManager.Restore.NuGet
10+
{
11+
public class NonExistentPackageFolder : IPackageFeed
12+
{
13+
private bool _ignored;
14+
private readonly bool _ignoreFailure;
15+
private readonly Reports _reports;
16+
17+
public string Source { get; }
18+
19+
public NonExistentPackageFolder(
20+
string physicalPath,
21+
bool ignoreFailure,
22+
Reports reports)
23+
{
24+
_ignored = false;
25+
_ignoreFailure = ignoreFailure;
26+
_reports = reports;
27+
Source = physicalPath;
28+
}
29+
30+
public Task<IEnumerable<PackageInfo>> FindPackagesByIdAsync(string id)
31+
{
32+
if (!_ignored)
33+
{
34+
var exception = new FileNotFoundException(
35+
message: string.Format("The local package source {0} doesn't exist", Source.Bold()),
36+
fileName: Source);
37+
38+
if (_ignoreFailure)
39+
{
40+
_reports.Information.WriteLine(string.Format("Warning: FindPackagesById: {1}\r\n {0}",
41+
exception.Message, id.Yellow().Bold()));
42+
_ignored = true;
43+
}
44+
else
45+
{
46+
_reports.Error.WriteLine(string.Format("Error: FindPackagesById: {1}\r\n {0}",
47+
exception.Message, id.Red().Bold()));
48+
throw exception;
49+
}
50+
}
51+
return Task.FromResult<IEnumerable<PackageInfo>>(new List<PackageInfo>());
52+
}
53+
54+
public Task<Stream> OpenNuspecStreamAsync(PackageInfo package)
55+
{
56+
throw new NotImplementedException();
57+
}
58+
59+
public Task<Stream> OpenNupkgStreamAsync(PackageInfo package)
60+
{
61+
throw new NotImplementedException();
62+
}
63+
}
64+
}
65+

src/Microsoft.Framework.PackageManager/Restore/RestoreCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,7 @@ private void AddRemoteProvidersFromSources(List<IWalkProvider> remoteProviders,
461461
foreach (var source in effectiveSources)
462462
{
463463
var feed = PackageSourceUtils.CreatePackageFeed(source, NoCache, IgnoreFailedSources, Reports);
464-
if (feed != null)
465-
{
466-
remoteProviders.Add(new RemoteWalkProvider(feed));
467-
}
464+
remoteProviders.Add(new RemoteWalkProvider(feed));
468465
}
469466
}
470467

src/Microsoft.Framework.PackageManager/Utils/PackageSourceUtils.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ public static IPackageFeed CreatePackageFeed(PackageSource source, bool noCache,
3333
{
3434
if (!Directory.Exists(source.Source))
3535
{
36-
reports.Information.WriteLine("Package source {0} doesn't exist",
37-
source.Source.Yellow().Bold());
38-
return null;
36+
return new NonExistentPackageFolder(
37+
source.Source,
38+
ignoreFailedSources,
39+
reports);
3940
}
4041
return PackageFolderFactory.CreatePackageFolderFromPath(source.Source, reports.Quiet);
4142
}

0 commit comments

Comments
 (0)