Sha256: f1137892979a9275e4017a393ef0d9a7fda5417799ea6ea17787abd2bb0336f4

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 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[:name] %>"

Write-Host "Attempting to mount $ShareName to $MountPoint"
if( (Test-Path "$MountPoint") -and (Test-ReparsePoint "$MountPoint") )
{
  Write-Host "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-Host "Mount point already exists and is not a symbolic link"
  exit 1
}

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

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

cmd /c mklink /D "$MountPoint" "\\vboxsrv\$ShareName"

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vagrant-windows-0.0.3 lib/vagrant-windows/scripts/mount_volume.ps1.erb
vagrant-windows-0.0.2 lib/vagrant-windows/scripts/mount_volume.ps1.erb