From 76bcc3ee9f0e2d1a75ddbb510b5b154c26571df3 Mon Sep 17 00:00:00 2001 From: BIOS999 <74330424+BIOS999@users.noreply.github.com> Date: Thu, 11 Feb 2021 03:56:33 +0500 Subject: [PATCH 1/3] Update seafile-symlink.ps1 Resolve powershell "notbug-but-feature" square brackets interpretation in path-strings --- seafile-symlink.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/seafile-symlink.ps1 b/seafile-symlink.ps1 index e709885..dfbacad 100644 --- a/seafile-symlink.ps1 +++ b/seafile-symlink.ps1 @@ -142,11 +142,13 @@ function Get-NonsymbolicPaths { # Convert param list to hash $params = Get-ParamHash $ParamArray + $DirPathEncoded = $DirPath.replace('[', '``[').replace(']', '``]') + # Get symbolic links located directly within this directory - $links = @(Get-ChildItem -Path "$DirPath\*" @params | ForEach-Object { $_.FullName }) + $links = @(Get-ChildItem -Path "$DirPathEncoded\*" @params | ForEach-Object { $_.FullName }) # Get all subdirectories, excluding symbolic links - $subdirs = @(Get-ChildItem -Path $DirPath -Attributes Directory+!ReparsePoint) + $subdirs = @(Get-ChildItem -LiteralPath $DirPath -Attributes Directory+!ReparsePoint) # Call this function on each subdirectory and append the result foreach ($subdir in $subdirs) { @@ -172,7 +174,7 @@ function Get-PlaceholderPaths ([string]$DirPath, [string]$PlaceholderExt) { function Test-IsDirectory ([string]$Path) { - (Get-Item -Path $Path) -is [System.IO.DirectoryInfo] + (Get-Item -LiteralPath $Path) -is [System.IO.DirectoryInfo] } From 66a24eb2dd74c2fae9cbaea5e673f4000ffa1ce7 Mon Sep 17 00:00:00 2001 From: BIOS999 <74330424+BIOS999@users.noreply.github.com> Date: Thu, 11 Feb 2021 04:06:06 +0500 Subject: [PATCH 2/3] Update seafile-symlink.ps1 add missing places --- seafile-symlink.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/seafile-symlink.ps1 b/seafile-symlink.ps1 index dfbacad..93c3b05 100644 --- a/seafile-symlink.ps1 +++ b/seafile-symlink.ps1 @@ -192,8 +192,8 @@ function Assert-IsDirectory ([string]$DirPath, [string]$Param) { # https://stackoverflow.com/questions/3038337/powershell-resolve-path-that-might-not-exist function Get-RelativePath ([string]$Path, [string]$DirPath) { Assert-IsDirectory $DirPath 'DirPath' - Push-Location -Path $DirPath - $out = Resolve-Path $Path -Relative -ErrorAction 'SilentlyContinue' -ErrorVariable '_frperror' + Push-Location -LiteralPath $DirPath + $out = Resolve-Path -LiteralPath $Path -Relative -ErrorAction 'SilentlyContinue' -ErrorVariable '_frperror' if (-not($out)) { $out = $_frperror[0].TargetObject } @@ -280,7 +280,7 @@ function Get-SymbolicLinkRawData ([string]$LibraryPath) { Get-SymbolicLinkPaths $LibraryPath | ForEach-Object { @{ LinkPath = $_ - DestPath = Get-Item -Path $_ | Select-Object -ExpandProperty Target + DestPath = Get-Item -LiteralPath $_ | Select-Object -ExpandProperty Target } } } @@ -401,7 +401,7 @@ function New-SymbolicLink ([string]$LinkPath, [string]$DestPath, [string]$Librar $DestPath = Get-BusinessDestPath $LinkPath $DestPath $LibraryPath # We need to enter the folder where the symlink will be located for any relative paths to resolve - Push-Location -Path (Get-LinkParentPath $LinkPath) + Push-Location -LiteralPath (Get-LinkParentPath $LinkPath) # https://stackoverflow.com/questions/894430/creating-hard-and-soft-links-using-powershell New-Item -Path $LinkPath -ItemType SymbolicLink -Value $DestPath -Force | Out-Null @@ -436,7 +436,7 @@ function New-Placeholder ([string]$LinkPath, [string]$DestPath, [string]$Placeho # Expects both $LinkPath and $DestPath for splatting convenience, but only needs the former. function Remove-Placeholder ([string]$LinkPath, [string]$DestPath, [string]$PlaceholderExt) { $placeholderPath = Get-PlaceholderPath $LinkPath $PlaceholderExt - if (Test-Path $placeholderPath) { + if (Test-Path -LiteralPath $placeholderPath) { Remove-Item -Path $placeholderPath Write-Host "Removed placeholder: `"$placeholderPath`"" } From aa92dcc6250564e3ee6e079afc229fbeca1a16f9 Mon Sep 17 00:00:00 2001 From: BIOS999 <74330424+BIOS999@users.noreply.github.com> Date: Thu, 11 Feb 2021 05:12:34 +0500 Subject: [PATCH 3/3] Update seafile-symlink.ps1 Wrong quotes used --- seafile-symlink.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seafile-symlink.ps1 b/seafile-symlink.ps1 index 93c3b05..2da1d85 100644 --- a/seafile-symlink.ps1 +++ b/seafile-symlink.ps1 @@ -142,7 +142,7 @@ function Get-NonsymbolicPaths { # Convert param list to hash $params = Get-ParamHash $ParamArray - $DirPathEncoded = $DirPath.replace('[', '``[').replace(']', '``]') + $DirPathEncoded = $DirPath.replace('[', "``[").replace(']', "``]") # Get symbolic links located directly within this directory $links = @(Get-ChildItem -Path "$DirPathEncoded\*" @params | ForEach-Object { $_.FullName })