Sha256: e9cf19349ddb769b305e68860e976f1887ecbb2ca8e124e663d67f806797f066

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

function Test-ReparsePoint([string]$path) {
  $file = Get-Item $path -Force -ea 0
  return [bool]($file.Attributes -band [IO.FileAttributes]::ReparsePoint)
}

$MountPoint = [System.IO.Path]::GetFullPath("<%= options[:mount_point] %>")
$ShareName = "<%= options[:share_name] %>"
$VmProviderUncPath = "<%= options[:vm_provider_unc_path] %>"

# https://github.com/BIAINC/vagrant-windows/issues/4
# Not sure why this works, but it does.

& net use $ShareName 2>&1 | Out-Null

Write-Output "Attempting to mount $ShareName to $MountPoint"
if( (Test-Path "$MountPoint") -and (Test-ReparsePoint "$MountPoint") )
{
  Write-Output "Junction already exists, so I will delete it"
  # Powershell refuses to delete junctions, oh well use cmd
  cmd /c rd "$MountPoint"

  if ( $LASTEXITCODE -ne 0 )
  {
    Write-Error "Failed to delete symbolic link at $MountPoint"
    exit 1
  }

}
elseif(Test-Path $MountPoint)
{
  Write-Output "Mount point already exists and is not a symbolic link"
  exit 1
}

$BaseDirectory = [System.IO.Path]::GetDirectoryName($MountPoint)

if (-not (Test-Path $BaseDirectory))
{
  Write-Output "Creating parent directory for mount point $BaseDirectory"
  New-Item $BaseDirectory -Type Directory -Force | Out-Null
}

& cmd.exe /c mklink /D "$MountPoint" "$VmProviderUncPath" | out-null

if ( $LASTEXITCODE -ne 0 )
{
  exit 1
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-guest-msys2-0.0.5 lib/vagrant-guest-msys2/scripts/mount_volume.ps1.erb