Src/Pscx/Commands/IO/Compression/ArchiveWriter/WriterBase.cs
/// <summary>
/// Try to clean up any partially finished archive files, if applicable.
/// <remarks>We cannot use Command methods here as they will not return due to the cmdlet's "stopping" state.</remarks>
/// </summary>
Try to clean up any partially finished archive files, if applicable.
We cannot use Command methods here as they will not return due to the cmdlet's "stopping" state.
Try to clean up any partially finished archive files if applicable . We cannot use Command methods here as they will not return due to the cmdlet ' s " stopping " state .
public virtual void StopProcessing()
        {
            Debug.WriteLine("Begin", "WriterBase.StopProcessing");
            if (_outputCompleted == false)
            {
                Debug.WriteLine("Trying to delete partial output...", "WriterBase.StopProcessing");
                try
                {
                    if (_currentOutputStream != null)
                    {
                        try
                        {
                            _currentOutputStream.Close();
                            Debug.WriteLine("Forcibly closed output stream.", "WriterBase.StopProcessing");
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex, "WriterBase.StopProcessing Stream Close Error");
                        }
                        File.Delete(CurrentOutputFile);
                        Debug.WriteLine("Deleted partial output.", "WriterBase.StopProcessing");
                    }
                    else
                    {
                        Debug.WriteLine("CurrentOutputStream is null!", "WriterBase.StopProcessing");
                    }
                }
                catch (IOException ex)
                {
                    Trace.WriteLine(ex, "WriterBase.StopProcessing Error");
                }
            }
            else
            {
                Debug.WriteLine("CurrentOutputStream appears properly completed before breaking, no need to clean up.",
                                "WriterBase.StopProcessing");
            }
            Debug.WriteLine("End", "WriterBase.StopProcessing");
        }
public virtual void StopProcessing ( ) { Debug . WriteLine ( " " , " " ) ; if ( _outputCompleted == false ) { Debug . WriteLine ( " " , " " ) ; try { if ( _currentOutputStream != null ) { try { _currentOutputStream . Close ( ) ; Debug . WriteLine ( " " , " " ) ; } catch ( Exception ex ) { Trace . WriteLine ( ex , " " ) ; } File . Delete ( CurrentOutputFile ) ; Debug . WriteLine ( " " , " " ) ; } else { Debug . WriteLine ( " " , " " ) ; } } catch ( IOException ex ) { Trace . WriteLine ( ex , " " ) ; } } else { Debug . WriteLine ( " " , " " ) ; } Debug . WriteLine ( " " , " " ) ; }
Try to clean up any partially finished archive files, if applicable.
Try to clean up any partially finished archive files if applicable .
// using inner try/catch here as sometimes SharpZipLib // will manage to close the handle, but throw an exception for some // other non-determinate reason, due to invalid state. // need to close the file handle as it's locking the output file // ok, we tried our best to delete the output file and still failed.