mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fixing update/save-help on Linux.
This commit is contained in:
committed by
Mike Richmond
parent
7c302856d8
commit
fea4d883e8
@@ -4595,7 +4595,12 @@ $RawUI.SetBufferContents(
|
||||
else
|
||||
{
|
||||
// Porting note: non-Windows platforms use `clear`
|
||||
return "& (Get-Command -CommandType Application clear | Select-Object -First 1).Definition";
|
||||
return @"
|
||||
& (Get-Command -CommandType Application clear | Select-Object -First 1).Definition
|
||||
# .Link
|
||||
# https://go.microsoft.com/fwlink/?LinkID=225747
|
||||
# .ExternalHelp System.Management.Automation.dll-help.xml
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!module.HelpInfoUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
|
||||
if (!(module.HelpInfoUri.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || module.HelpInfoUri.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
if (!noErrors)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,11 @@ namespace System.Management.Automation.Help
|
||||
/// </summary>
|
||||
internal class UpdatableHelpModuleInfo
|
||||
{
|
||||
#if UNIX
|
||||
internal static readonly string HelpContentZipName = "HelpContent.zip";
|
||||
#else
|
||||
internal static readonly string HelpContentZipName = "HelpContent.cab";
|
||||
#endif
|
||||
internal static readonly string HelpIntoXmlName = "HelpInfo.xml";
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -17,8 +17,8 @@ using System.Text;
|
||||
using Microsoft.PowerShell.Commands;
|
||||
using Microsoft.Win32;
|
||||
using System.Security;
|
||||
|
||||
#if CORECLR
|
||||
using System.IO.Compression;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
// Use stub for SerializableAttribute, SerializationInfo and ISerializable related types. WebClient.
|
||||
@@ -1209,9 +1209,9 @@ namespace System.Management.Automation.Help
|
||||
OnProgressChanged(this, new UpdatableHelpProgressEventArgs(CurrentModule, commandType, StringUtil.Format(
|
||||
HelpDisplayStrings.UpdateProgressInstalling), 0));
|
||||
|
||||
string combinedSourcePath = Path.Combine(sourcePath, fileName);
|
||||
string combinedSourcePath = GetFilePath(Path.Combine(sourcePath, fileName));
|
||||
|
||||
if (!File.Exists(combinedSourcePath))
|
||||
if (string.IsNullOrEmpty(combinedSourcePath))
|
||||
{
|
||||
throw new UpdatableHelpSystemException("HelpContentNotFound", StringUtil.Format(HelpDisplayStrings.HelpContentNotFound),
|
||||
ErrorCategory.ResourceUnavailable, null, null);
|
||||
@@ -1249,6 +1249,37 @@ namespace System.Management.Automation.Help
|
||||
}
|
||||
}
|
||||
|
||||
#if UNIX
|
||||
private bool ExpandArchive(string source, string destination)
|
||||
{
|
||||
bool sucessfulDecompression = false;
|
||||
|
||||
try
|
||||
{
|
||||
using (FileStream archiveFileStream = new FileStream(source, IO.FileMode.Open, FileAccess.Read))
|
||||
using (ZipArchive zipArchive = new ZipArchive(archiveFileStream, ZipArchiveMode.Read, false))
|
||||
{
|
||||
foreach (ZipArchiveEntry entry in zipArchive.Entries)
|
||||
{
|
||||
string extractPath = Path.Combine(destination, entry.FullName);
|
||||
entry.ExtractToFile(extractPath);
|
||||
}
|
||||
sucessfulDecompression = true;
|
||||
}
|
||||
}
|
||||
catch (ArgumentException) { }
|
||||
catch (InvalidDataException) { }
|
||||
catch (NotSupportedException) { }
|
||||
catch (FileNotFoundException) { }
|
||||
catch (IOException) { }
|
||||
catch (SecurityException) { }
|
||||
catch (UnauthorizedAccessException) { }
|
||||
catch (ObjectDisposedException) { }
|
||||
|
||||
return sucessfulDecompression;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Unzips to help content to a given location
|
||||
/// </summary>
|
||||
@@ -1265,20 +1296,25 @@ namespace System.Management.Automation.Help
|
||||
Directory.CreateDirectory(destPath);
|
||||
}
|
||||
|
||||
string cabDir = Path.GetDirectoryName(srcPath);
|
||||
|
||||
string sourceDirectory = Path.GetDirectoryName(srcPath);
|
||||
bool sucessfulDecompression = false;
|
||||
#if UNIX
|
||||
sucessfulDecompression = ExpandArchive(Path.Combine(sourceDirectory, Path.GetFileName(srcPath)), destPath);
|
||||
#else
|
||||
// Cabinet API doesn't handle the trailing back slash
|
||||
if (!cabDir.EndsWith("\\", StringComparison.Ordinal))
|
||||
if (!sourceDirectory.EndsWith("\\", StringComparison.Ordinal))
|
||||
{
|
||||
cabDir += "\\";
|
||||
sourceDirectory += "\\";
|
||||
}
|
||||
|
||||
if (!destPath.EndsWith("\\", StringComparison.Ordinal))
|
||||
{
|
||||
destPath += "\\";
|
||||
}
|
||||
|
||||
if (!CabinetExtractorFactory.GetCabinetExtractor().Extract(Path.GetFileName(srcPath), cabDir, destPath))
|
||||
|
||||
sucessfulDecompression = CabinetExtractorFactory.GetCabinetExtractor().Extract(Path.GetFileName(srcPath), sourceDirectory, destPath);
|
||||
#endif
|
||||
if (!sucessfulDecompression)
|
||||
{
|
||||
throw new UpdatableHelpSystemException("UnableToExtract", StringUtil.Format(HelpDisplayStrings.UnzipFailure),
|
||||
ErrorCategory.InvalidOperation, null, null);
|
||||
@@ -1574,9 +1610,10 @@ namespace System.Management.Automation.Help
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(path))
|
||||
string filePath = GetFilePath(path);
|
||||
if (!string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
using (FileStream currentHelpInfoFile = new FileStream(path, FileMode.Open, FileAccess.Read))
|
||||
using (FileStream currentHelpInfoFile = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
StreamReader reader = new StreamReader(currentHelpInfoFile);
|
||||
|
||||
@@ -1587,6 +1624,43 @@ namespace System.Management.Automation.Help
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate the given path. If it exists, return the full path to the file.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
internal static string GetFilePath(string path)
|
||||
{
|
||||
#if UNIX
|
||||
// On Linux, file paths are case sensitive.
|
||||
// The user does not have control over the files (HelpInfo.xml, .zip, and cab) that are generated by the Publishing team.
|
||||
// The logic below is to support updating help content via sourcepath parameter for case insensitive files.
|
||||
FileInfo item = new FileInfo(path);
|
||||
string directoryPath = item.Directory.FullName;
|
||||
string fileName = item.Name;
|
||||
|
||||
// Prerequisite: The directory in the given path must exist and it is case sensitive.
|
||||
if (Utils.NativeDirectoryExists(directoryPath))
|
||||
{
|
||||
// Get the list of files in the directory.
|
||||
string[] fileList = Directory.GetFiles(directoryPath);
|
||||
foreach (string filePath in fileList)
|
||||
{
|
||||
if (filePath.EndsWith(fileName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (Utils.NativeFileExists(path))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
#endif
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default source path from GP
|
||||
/// </summary>
|
||||
|
||||
@@ -161,6 +161,7 @@
|
||||
"System.IO.FileSystem.DriveInfo": "4.3.0-preview1-24530-04",
|
||||
"System.IO.FileSystem.Watcher": "4.3.0-preview1-24530-04",
|
||||
"System.IO.Pipes": "4.3.0-preview1-24530-04",
|
||||
"System.IO.Compression.ZipFile": "4.3.0-preview1-24530-04",
|
||||
"System.Linq.Expressions": "4.3.0-preview1-24530-04",
|
||||
"System.Net.Http": "4.3.0-preview1-24530-04",
|
||||
"System.Net.NetworkInformation": "4.3.0-preview1-24530-04",
|
||||
|
||||
Reference in New Issue
Block a user