Respond to PR feedback

上级 26488169
......@@ -72,14 +72,33 @@ internal Func<Stream> GetCreateStreamFunc(DiagnosticBag 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
// owned by this type.
_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>
......@@ -139,53 +158,44 @@ internal bool Complete(StrongNameKeys strongNameKeys, CommonMessageProvider mess
Debug.Assert(_stream != null);
Debug.Assert(_emitStreamSignKind != EmitStreamSignKind.SignedWithFile || _tempInfo.HasValue);
if (_tempInfo.HasValue)
try
{
Debug.Assert(_emitStreamSignKind == EmitStreamSignKind.SignedWithFile);
var (tempStream, tempFilePath) = _tempInfo.GetValueOrDefault();
try
if (_tempInfo.HasValue)
{
// Dispose the temp stream to ensure all of the contents are written to
// disk.
tempStream.Dispose();
Debug.Assert(_emitStreamSignKind == EmitStreamSignKind.SignedWithFile);
var (tempStream, tempFilePath) = _tempInfo.GetValueOrDefault();
_strongNameProvider.SignFile(strongNameKeys, tempFilePath);
using (var tempFileStream = new FileStream(tempFilePath, FileMode.Open))
try
{
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)
{
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
catch (DesktopStrongNameProvider.ClrStrongNameMissingException)
{
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;
}
}
......
......@@ -2739,8 +2739,8 @@ internal void EnsureAnonymousTypeTemplates(CancellationToken cancellationToken)
finally
{
nativePdbWriter?.Dispose();
emitPeStream?.Dispose();
emitMetadataStream?.Dispose();
emitPeStream?.Close();
emitMetadataStream?.Close();
pdbBag?.Free();
metadataDiagnostics?.Free();
}
......
......@@ -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>
......@@ -159,13 +159,15 @@ internal virtual void ReadKeysFromContainer(string keyContainer, out ImmutableAr
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
{
Sign(filePath, keys.KeyPair);
Sign(filePath, keys.KeyContainer);
}
}
......
......@@ -31,7 +31,7 @@ protected StrongNameProvider()
internal abstract void SignFile(StrongNameKeys keys, string filePath);
/// <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>
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.
先完成此消息的编辑!
想要评论请 注册