Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private IEnumerable<Feed> Feeds {
return Enumerable.Empty<Feed>();
}

#if !PORTABLE
// we don't do bootstrap on core powershell
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) {
Warning(Constants.Messages.NetworkNotAvailable);
Warning(string.Format(CultureInfo.CurrentCulture, Resources.Messages.ProviderBootstrapFailed));
Expand All @@ -91,6 +93,7 @@ private IEnumerable<Feed> Feeds {
Warning(Constants.Messages.ProviderSwidtagUnavailable);
return Enumerable.Empty<Feed>();
}
#endif
}
return _feeds;
}
Expand Down Expand Up @@ -441,6 +444,10 @@ private static bool AnyNullOrEmpty(params string[] args) {
/// <returns></returns>
internal Package GetProviderFromFile(string filePath, bool copyFileToTemp = false, bool suppressErrorsAndWarnings = false) {

#if PORTABLE
// not supported on core powershell
return null;
#else
if (string.IsNullOrWhiteSpace(filePath) && !System.IO.File.Exists(filePath)) {
Warning(Constants.Messages.FileNotFound, filePath);
return null;
Expand Down Expand Up @@ -501,6 +508,7 @@ internal Package GetProviderFromFile(string filePath, bool copyFileToTemp = fals
}

return null;
#endif
}

/// <summary>
Expand Down Expand Up @@ -629,4 +637,4 @@ private string CopyToTempLocation(string filePath) {
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/Microsoft.PackageManagement.CoreProviders/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
"netstandard1.6": {
"imports": ["dnxcore50"],
"buildOptions": {
"define": ["CORECLR"],
"define": ["CORECLR", "PORTABLE"],
"compile": {
"exclude": [ "ProgramsProvider.cs"]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ internal static string BaseFolder {
if (_baseFolder == null || !Directory.Exists(_baseFolder)) {
throw new Exception(Resources.Messages.CantFindBasePowerShellModuleFolder);
}

_baseFolder = Path.Combine(_baseFolder, "Modules", "PackageManagement");
}
return _baseFolder;
}
Expand Down Expand Up @@ -827,4 +829,4 @@ private void ProvideSwidTagInformation(PackageProvider packageProvider, PSModule
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,11 @@ internal IEnumerable<string> ScanAllProvidersFromProviderAssembliesLocation(
Version maximumVersion,
ProviderOption providerOption = ProviderOption.LatestVersion) {

#if PORTABLE
return Enumerable.Empty<string>();
#else
//We don't need to scan provider assemblies on corepowershell.

//if provider is installed in providername\version format
var providerFolder = ProviderAssembliesLocation.Distinct(new PathEqualityComparer(PathCompareOption.Full)).SelectMany(Directory.EnumerateDirectories);

Expand Down Expand Up @@ -962,23 +967,29 @@ internal IEnumerable<string> ScanAllProvidersFromProviderAssembliesLocation(
}
}
}
#endif
}

//Return all providers under the providerAssemblies folder
internal IEnumerable<string> AllProvidersFromProviderAssembliesLocation(IHostApi request) {
#if !PORTABLE
// don't need this for core powershell
try {

return ScanAllProvidersFromProviderAssembliesLocation(request, null, null, null, null, ProviderOption.AllProvider).WhereNotNull().ToArray();
} catch (Exception ex) {
request.Debug(ex.Message);
}
#endif
return Enumerable.Empty<string>();
}


//return the providers with latest version under the providerAssemblies folder
//This method only gets called during the initialization, i.e. LoadProviders().
private IEnumerable<string> ProvidersWithLatestVersionFromProviderAssembliesLocation(IHostApi request) {
#if !PORTABLE
// don't need this for core powershell
try {
var providerPaths = ScanAllProvidersFromProviderAssembliesLocation(request, null, null, null, null, ProviderOption.LatestVersion).WhereNotNull().ToArray();

Expand Down Expand Up @@ -1011,6 +1022,8 @@ private IEnumerable<string> ProvidersWithLatestVersionFromProviderAssembliesLoca
{
request.Debug(ex.Message);
}
#endif

return Enumerable.Empty<string>();
}

Expand All @@ -1029,43 +1042,21 @@ internal void LoadProviders(IHostApi request) {
.Concat(GetProvidersFromRegistry(Registry.LocalMachine, "SOFTWARE\\MICROSOFT\\PACKAGEMANAGEMENT"))
.Concat(GetProvidersFromRegistry(Registry.CurrentUser, "SOFTWARE\\MICROSOFT\\PACKAGEMANAGEMENT"));

providerAssemblies = providerAssemblies.Concat(ProvidersWithLatestVersionFromProviderAssembliesLocation(request));

#if DEEP_DEBUG
providerAssemblies = providerAssemblies.ToArray();

foreach (var each in providerAssemblies) {
request.Debug("possible assembly: {0}".format(each));
}
#endif

// find modules that have manifests
// todo: expand this out to validate the assembly is ok for this instance of PackageManagement.
providerAssemblies = providerAssemblies.Where(each => Manifest.LoadFrom(each).Any(manifest => Swidtag.IsSwidtag(manifest) && new Swidtag(manifest).IsApplicable(new Hashtable())));

// add inbox assemblies (don't require manifests, because they are versioned with the core)

#if !COMMUNITY_BUILD
// todo: these should just be strong-named references. for now, just load them from the same directory.
providerAssemblies = providerAssemblies.Concat(new[] {
Path.Combine(BaseDir, "Microsoft.PackageManagement.MetaProvider.PowerShell.dll"),
Path.Combine(BaseDir, "Microsoft.PackageManagement.ArchiverProviders.dll"),
Path.Combine(BaseDir, "Microsoft.PackageManagement.CoreProviders.dll"),
Path.Combine(BaseDir, "Microsoft.PackageManagement.CoreProviders.dll"),
Path.Combine(BaseDir, "Microsoft.PackageManagement.NuGetProvider.dll"),
Path.Combine(BaseDir, "Microsoft.PackageManagement.PackageSourceListProvider.dll"),
#if !CORECLR
Path.Combine(BaseDir, "Microsoft.PackageManagement.MsuProvider.dll"),
Path.Combine(BaseDir, "Microsoft.PackageManagement.MsiProvider.dll")
#endif
});
#endif

#if DEEP_DEBUG
providerAssemblies = providerAssemblies.ToArray();

foreach (var each in providerAssemblies) {
request.Debug("possible assembly with manifest: {0}".format(each));
}
#endif

providerAssemblies = providerAssemblies.OrderByDescending(each => {
try {
// try to get a version from the file first
Expand Down Expand Up @@ -1611,4 +1602,4 @@ private bool LoadViaMetaProvider(IMetaProvider metaProvider, string name, FourPa
return found;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public IDictionary<string, List<string>> Features {
/// <param name="providerPath"></param>
public void SetSwidTag(string providerPath)
{
#if !LINUX
if (!string.IsNullOrWhiteSpace(providerPath))
{
// check whether there is swidtag attached to the provider path
Expand All @@ -92,6 +93,7 @@ public void SetSwidTag(string providerPath)
SetSwidTag(new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), swid));
}
}
#endif
}

public IEnumerable<string> SupportedFileExtensions {
Expand Down Expand Up @@ -207,4 +209,4 @@ public IAsyncEnumerable<DynamicOption> GetDynamicOptions(OptionCategory category
return new DynamicOptionRequestObject(this, requestObject, request => Provider.GetDynamicOptions(category.ToString(), request), category);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ public bool IsSignedAndTrusted(string filename, IRequest request) {

Debug(request, "Calling 'ProviderService::IsSignedAndTrusted, '{0}'", filename);

// we are not using this function anywhere
#if !LINUX
var wtd = new WinTrustData(filename);

var result = NativeMethods.WinVerifyTrust(new IntPtr(-1), new Guid("{00AAC56B-CD44-11d0-8CC2-00C04FC295EE}"), wtd);
return result == WinVerifyTrustResult.Success;
#endif
}
return false;
}
Expand Down Expand Up @@ -233,4 +237,4 @@ public bool Debug(IRequest request, string messageText, params object[] args) {
return request.Debug(request.FormatMessageString(messageText, args));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ namespace Microsoft.PackageManagement.Internal.Utility.Extensions {

internal static class ExceptionExtensions {
public static void Dump(this Exception e) {
#if !LINUX
var text = string.Format(CultureInfo.CurrentCulture, "{0}/{1}\r\n{2}", e.GetType().Name, e.Message, e.StackTrace);
// for now, this is the only way we'll see exceptions in the wild.
NativeMethods.OutputDebugString(text);
#endif
}

#if DETAILED_DEBUG
Expand All @@ -35,4 +37,4 @@ public static T DumpTime<T>(this T nothing) {
}
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,22 @@ public static void TryHardToDelete(this string location) {
// move the file to the tmp file
// and tell the OS to remove it next reboot.
var tmpFilename = GenerateTemporaryFileOrDirectoryNameInTempDirectory() + ".delete_me"; // generates a unique filename but not a file!
MoveFileOverwrite(location, tmpFilename);
File.Move(location, tmpFilename);

if (File.Exists(location) || Directory.Exists(location)) {
// of course, if the tmpFile isn't on the same volume as the location, this doesn't work.
// then, last ditch effort, let's rename it in the current directory
// and then we can hide it and mark it for cleanup .
tmpFilename = Path.Combine(Path.GetDirectoryName(location), "tmp." + CounterHex + "." + Path.GetFileName(location) + ".delete_me");
MoveFileOverwrite(location, tmpFilename);
File.Move(location, tmpFilename);
if (File.Exists(tmpFilename) || Directory.Exists(location)) {
// hide the file for convenience.
File.SetAttributes(tmpFilename, File.GetAttributes(tmpFilename) | FileAttributes.Hidden);
}
}

// Now we mark the locked file to be deleted upon next reboot (or until another coapp app gets there)
MoveFileOverwrite(File.Exists(tmpFilename) ? tmpFilename : location, null);
File.Move(File.Exists(tmpFilename) ? tmpFilename : location, null);
} catch {
// really. Hmmm.
}
Expand All @@ -101,19 +101,6 @@ public static void TryHardToDelete(this string location) {
return;
}

/// <summary>
/// File move abstraction that can be implemented to handle non-windows platforms
/// </summary>
/// <param name="sourceFile"></param>
/// <param name="destinationFile"></param>
public static void MoveFileOverwrite(string sourceFile, string destinationFile) {
NativeMethods.MoveFileEx(sourceFile, destinationFile, MoveFileFlags.ReplaceExisting);
}

public static void MoveFileAtNextBoot(string sourceFile, string destinationFile) {
NativeMethods.MoveFileEx(sourceFile, destinationFile, MoveFileFlags.DelayUntilReboot);
}

/// <summary>
/// Create a temporary file name in the temp directory so we can move file that we cannot delete over
/// </summary>
Expand Down Expand Up @@ -199,6 +186,7 @@ public static string CanonicalizePath(this string path, bool isPotentiallyRelati

// is this a unc path?
if (string.IsNullOrWhiteSpace(pathUri.Host)) {
#if !LINUX
// no, this is a drive:\path path
// use API to resolve out the drive letter to see if it is a remote
var drive = pathUri.Segments[1].Replace('/', '\\'); // the zero segment is always just '/'
Expand All @@ -212,6 +200,7 @@ public static string CanonicalizePath(this string path, bool isPotentiallyRelati
return pathUri.Segments.Skip(2).Aggregate(sb.ToString().Trim(), (current, item) => current + item);
}
}
#endif
}
// not a remote (or resovably-remote) path or
// it is already a path that is in it's correct form (via localpath)
Expand Down Expand Up @@ -265,4 +254,4 @@ public static string MakeSafeFileName(this string input) {
return new Regex(@"-+").Replace(new Regex(@"[^\d\w\[\]_\-\.\ ]").Replace(input, "-"), "-").Replace(" ", "");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Microsoft.PackageManagement.Internal.Utility.Platform {
internal static class Manifest {
private static readonly byte[] _utf = {0xef, 0xbb, 0xbf};

#if !LINUX
public static IEnumerable<XElement> LoadFrom(string filename) {
var manifests = new List<XElement>();

Expand Down Expand Up @@ -68,5 +69,7 @@ public static IEnumerable<XElement> LoadFrom(string filename) {
}
return manifests;
}
#endif

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.
//

#if !LINUX
namespace Microsoft.PackageManagement.Internal.Utility.Platform {
using System;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -334,4 +335,6 @@ internal static class NativeMethods {
public static extern void OutputDebugString(string debugMessageText);
#endif
}
}
}
#endif

2 changes: 1 addition & 1 deletion src/Microsoft.PackageManagement/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"netstandard1.6": {
"imports": [ "dnxcore50" ],
"buildOptions": {
"define": [ "CORECLR" ],
"define": [ "CORECLR", "PORTABLE" ],
"compile": {
"exclude": [ "Providers/Inbox/Common/*" ]
}
Expand Down
Loading