Respond to PR feedback

上级 26488169
...@@ -72,14 +72,33 @@ internal Func<Stream> GetCreateStreamFunc(DiagnosticBag diagnostics) ...@@ -72,14 +72,33 @@ internal Func<Stream> GetCreateStreamFunc(DiagnosticBag diagnostics)
return () => CreateStream(diagnostics); return () => CreateStream(diagnostics);
} }
internal void Dispose() internal void Close()
{ {
_tempInfo?.tempStream.Dispose();
_tempInfo = null;
// The _stream value is deliberately excluded from being disposed here. That value is not // The _stream value is deliberately excluded from being disposed here. That value is not
// owned by this type. // owned by this type.
_stream = null; _stream = null;
if (_tempInfo.HasValue)
{
var (tempStream, tempFilePath) = _tempInfo.GetValueOrDefault();
_tempInfo = null;
try
{
tempStream.Dispose();
}
finally
{
try
{
File.Delete(tempFilePath);
}
catch
{
// Not much to do if we can't delete from the temp directory
}
}
}
} }
/// <summary> /// <summary>
...@@ -139,53 +158,44 @@ internal bool Complete(StrongNameKeys strongNameKeys, CommonMessageProvider mess ...@@ -139,53 +158,44 @@ internal bool Complete(StrongNameKeys strongNameKeys, CommonMessageProvider mess
Debug.Assert(_stream != null); Debug.Assert(_stream != null);
Debug.Assert(_emitStreamSignKind != EmitStreamSignKind.SignedWithFile || _tempInfo.HasValue); Debug.Assert(_emitStreamSignKind != EmitStreamSignKind.SignedWithFile || _tempInfo.HasValue);
if (_tempInfo.HasValue) try
{ {
Debug.Assert(_emitStreamSignKind == EmitStreamSignKind.SignedWithFile); if (_tempInfo.HasValue)
var (tempStream, tempFilePath) = _tempInfo.GetValueOrDefault();
try
{ {
// Dispose the temp stream to ensure all of the contents are written to Debug.Assert(_emitStreamSignKind == EmitStreamSignKind.SignedWithFile);
// disk. var (tempStream, tempFilePath) = _tempInfo.GetValueOrDefault();
tempStream.Dispose();
_strongNameProvider.SignFile(strongNameKeys, tempFilePath); try
using (var tempFileStream = new FileStream(tempFilePath, FileMode.Open))
{ {
tempFileStream.CopyTo(_stream); // Dispose the temp stream to ensure all of the contents are written to
// disk.
tempStream.Dispose();
_strongNameProvider.SignFile(strongNameKeys, tempFilePath);
using (var tempFileStream = new FileStream(tempFilePath, FileMode.Open))
{
tempFileStream.CopyTo(_stream);
}
} }
} catch (DesktopStrongNameProvider.ClrStrongNameMissingException)
catch (DesktopStrongNameProvider.ClrStrongNameMissingException)
{
diagnostics.Add(StrongNameKeys.GetError(strongNameKeys.KeyFilePath, strongNameKeys.KeyContainer,
new CodeAnalysisResourcesLocalizableErrorArgument(nameof(CodeAnalysisResources.AssemblySigningNotSupported)), messageProvider));
return false;
}
catch (IOException ex)
{
diagnostics.Add(StrongNameKeys.GetError(strongNameKeys.KeyFilePath, strongNameKeys.KeyContainer, ex.Message, messageProvider));
return false;
}
finally
{
try
{ {
File.Delete(tempFilePath); diagnostics.Add(StrongNameKeys.GetError(strongNameKeys.KeyFilePath, strongNameKeys.KeyContainer,
new CodeAnalysisResourcesLocalizableErrorArgument(nameof(CodeAnalysisResources.AssemblySigningNotSupported)), messageProvider));
return false;
} }
catch catch (IOException ex)
{ {
// Not much to do if we can't delete from the temp directory diagnostics.Add(StrongNameKeys.GetError(strongNameKeys.KeyFilePath, strongNameKeys.KeyContainer, ex.Message, messageProvider));
return false;
} }
tempStream.Dispose();
_tempInfo = null;
_stream = null;
} }
} }
finally
{
Close();
}
_stream = null;
return true; return true;
} }
} }
......
...@@ -2739,8 +2739,8 @@ internal void EnsureAnonymousTypeTemplates(CancellationToken cancellationToken) ...@@ -2739,8 +2739,8 @@ internal void EnsureAnonymousTypeTemplates(CancellationToken cancellationToken)
finally finally
{ {
nativePdbWriter?.Dispose(); nativePdbWriter?.Dispose();
emitPeStream?.Dispose(); emitPeStream?.Close();
emitMetadataStream?.Dispose(); emitMetadataStream?.Close();
pdbBag?.Free(); pdbBag?.Free();
metadataDiagnostics?.Free(); metadataDiagnostics?.Free();
} }
......
...@@ -103,7 +103,7 @@ internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContai ...@@ -103,7 +103,7 @@ internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContai
} }
} }
return new StrongNameKeys(keyPair, publicKey, null, container, keyFilePath, hasCounterSignature); return new StrongNameKeys(keyPair, publicKey, privateKey: null, container, keyFilePath, hasCounterSignature);
} }
/// <summary> /// <summary>
...@@ -159,13 +159,15 @@ internal virtual void ReadKeysFromContainer(string keyContainer, out ImmutableAr ...@@ -159,13 +159,15 @@ internal virtual void ReadKeysFromContainer(string keyContainer, out ImmutableAr
internal override void SignFile(StrongNameKeys keys, string filePath) internal override void SignFile(StrongNameKeys keys, string filePath)
{ {
if (keys.KeyContainer != null) Debug.Assert(string.IsNullOrEmpty(keys.KeyFilePath) != string.IsNullOrEmpty(keys.KeyContainer));
if (!string.IsNullOrEmpty(keys.KeyFilePath))
{ {
Sign(filePath, keys.KeyContainer); Sign(filePath, keys.KeyPair);
} }
else else
{ {
Sign(filePath, keys.KeyPair); Sign(filePath, keys.KeyContainer);
} }
} }
......
...@@ -31,7 +31,7 @@ protected StrongNameProvider() ...@@ -31,7 +31,7 @@ protected StrongNameProvider()
internal abstract void SignFile(StrongNameKeys keys, string filePath); internal abstract void SignFile(StrongNameKeys keys, string filePath);
/// <summary> /// <summary>
/// Signs the contents of <paramref name="peBuilder"/> using <paramref name="privateKey"/>. /// Signs the contents of <paramref name="peBlob"/> using <paramref name="peBuilder"/> and <paramref name="privateKey"/>.
/// </summary> /// </summary>
internal abstract void SignBuilder(ExtendedPEBuilder peBuilder, BlobBuilder peBlob, RSAParameters privateKey); internal abstract void SignBuilder(ExtendedPEBuilder peBuilder, BlobBuilder peBlob, RSAParameters privateKey);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册