Microsoft.PowerShell.Archive icon indicating copy to clipboard operation
Microsoft.PowerShell.Archive copied to clipboard

Compress-Archive -Update delete archive if file could not be appended

Open Platzer opened this issue 3 years ago • 2 comments

Description

When using Compress-Archive with -Update to append a file to an existing ZIP file, and the current file used is locked by another process the ZIP file is deleted. If it make sense or not to append an open file Compress-Archive should not remove a not empty archive.

Reproduce

# Setup test files
'Test file one content' > 'test_file_1.txt';
'Test file two content' > 'test_file_2.txt';

# Prepare file handle
$lockFile = Get-ChildItem '.\test_file_2.txt';
$lockTestFile2 = [System.IO.File]::Open($lockFile.FullName, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Write, [System.IO.FileShare]::ReadWrite)

Compress-Archive -Path .\test_file_1.txt -DestinationPath 'ZipFile.zip' -Update

# Watch ZipFile.zip disappear
Compress-Archive -Path .\test_file_2.txt -DestinationPath 'ZipFile.zip' -Update

$lockTestFile2.Dispose();

Platzer avatar Dec 16 '21 10:12 Platzer

This issue also occurs when -Path is empty:

@() | Compress-Archive -DestinationPath 'ZipFile.zip' -Update

Chris--A avatar Aug 25 '22 08:08 Chris--A

I believe this issue is solved in the 2.0 preview, but I need to double check and make sure.

ayousuf23 avatar Oct 26 '22 01:10 ayousuf23