Skip to content

Commit e8fd146

Browse files
author
Andrew
authored
Merge pull request #29 from anmenaga/FixDirSeparatorsOnUnix
Fixing module on Unix
2 parents 74ef974 + d5c42b4 commit e8fd146

File tree

2 files changed

+223
-209
lines changed

2 files changed

+223
-209
lines changed

Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psm1

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,10 @@ function Expand-Archive
419419
}
420420
elseif ($PassThru -and $expandedItems.Count -gt 0)
421421
{
422-
# Return the expanded items, being careful to remove trailing backslashes from
422+
# Return the expanded items, being careful to remove trailing directory separators from
423423
# any folder paths for consistency
424-
Get-Item -LiteralPath ($expandedItems -replace '\\+$')
424+
$trailingDirSeparators = '\' + [System.IO.Path]::DirectorySeparatorChar + '+$'
425+
Get-Item -LiteralPath ($expandedItems -replace $trailingDirSeparators)
425426
}
426427
}
427428
}
@@ -669,22 +670,22 @@ function CompressSingleDirHelper
669670
$sourceDirInfo = New-Object -TypeName System.IO.DirectoryInfo -ArgumentList $sourceDirPath
670671
$sourceDirFullName = $sourceDirInfo.Parent.FullName
671672

672-
# If the directory is present at the drive level the DirectoryInfo.Parent include '\' example: C:\
673+
# If the directory is present at the drive level the DirectoryInfo.Parent include directory separator. example: C:\
673674
# On the other hand if the directory exists at a deper level then DirectoryInfo.Parent
674-
# has just the path (without an ending '\'). example C:\source
675+
# has just the path (without an ending directory separator). example C:\source
675676
if($sourceDirFullName.Length -eq 3)
676677
{
677678
$modifiedSourceDirFullName = $sourceDirFullName
678679
}
679680
else
680681
{
681-
$modifiedSourceDirFullName = $sourceDirFullName + "\"
682+
$modifiedSourceDirFullName = $sourceDirFullName + [System.IO.Path]::DirectorySeparatorChar
682683
}
683684
}
684685
else
685686
{
686687
$sourceDirFullName = $sourceDirPath
687-
$modifiedSourceDirFullName = $sourceDirFullName + "\"
688+
$modifiedSourceDirFullName = $sourceDirFullName + [System.IO.Path]::DirectorySeparatorChar
688689
}
689690

690691
$dirContents = Get-ChildItem -LiteralPath $sourceDirPath -Recurse
@@ -704,7 +705,7 @@ function CompressSingleDirHelper
704705
$files = $currentContent.GetFiles()
705706
if($files.Count -eq 0)
706707
{
707-
$subDirFiles.Add($currentContent.FullName + "\")
708+
$subDirFiles.Add($currentContent.FullName + [System.IO.Path]::DirectorySeparatorChar)
708709
}
709710
}
710711
}
@@ -795,8 +796,8 @@ function ZipArchiveHelper
795796

796797
# If a directory needs to be added to an archive file,
797798
# by convention the .Net API's expect the path of the diretcory
798-
# to end with '\' to detect the path as an directory.
799-
if(!$relativeFilePath.EndsWith("\", [StringComparison]::OrdinalIgnoreCase))
799+
# to end with directory separator to detect the path as an directory.
800+
if(!$relativeFilePath.EndsWith([System.IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase))
800801
{
801802
try
802803
{
@@ -975,9 +976,9 @@ function ExpandArchiveHelper
975976
$extension = [system.IO.Path]::GetExtension($currentArchiveEntryPath)
976977

977978
# The current archive entry is an empty directory
978-
# The FullName of the Archive Entry representing a directory would end with a trailing '\'.
979+
# The FullName of the Archive Entry representing a directory would end with a trailing directory separator.
979980
if($extension -eq [string]::Empty -and
980-
$currentArchiveEntryPath.EndsWith("\", [StringComparison]::OrdinalIgnoreCase))
981+
$currentArchiveEntryPath.EndsWith([System.IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase))
981982
{
982983
$pathExists = Test-Path -LiteralPath $currentArchiveEntryPath
983984

0 commit comments

Comments
 (0)