使用Windows在Vagrant中错误同步文件夹映射

时间:2014-06-28 15:30:52

标签: windows vagrant sync shared

我使用Vagrant进行Windows主机的Web开发。 然而,我似乎有一个奇怪的问题,挖掘各种谷歌的结果不会给我任何解决方案。

问题:

我在Windows中使用此结构定义了同步文件夹 d:/ VM /教程测试/流浪/ VagrantFile d:/VM/tutorial-test/vagrant/tutorial/index.php

因此VagrantFile配置为使用文件夹“教程”挂载为Sync文件夹。 这是在Linux的子文件夹“/ var / www”

有一半时间安装得非常正确。 子文件夹已安装,我可以添加和删除文件。 另一半“流浪汉”正在运行,似乎他安装了一个不同的Windows文件夹。它主要是在我的VagrantFile所在的树中的1或2个文件夹。

这是我的VagrantFile:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "hashicorp/precise32" 
  config.vm.provision :shell, path: "bootstrap.sh" 
  config.vm.provision "shell", path: "after-boot.sh", run: "always"
  config.vm.network :forwarded_port, host: 80, guest: 80
  config.vm.network :private_network, ip: '192.168.50.50'

  config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
    v.customize ["modifyvm", :id, "--memory", 2048]
    v.customize ["modifyvm", :id, "--cpus", 2]
  end

  config.vm.synced_folder "vhosts/", "/etc/apache2/sites-available",
    owner: "root", group: "root"
  config.vm.synced_folder "tutorial/", "/var/www/tutorial",
    owner: "www-data", group: "www-data"

end

当我发起“流浪汉”时会发生什么

enter image description here

如您所见,它安装了“D:/ VM”文件夹。 这里的实际结构应该是D:/ VM / tutorial-test / vagrant / tutorial 定义了多个同步文件夹。他对每个同步文件夹均采取行动。

必须有一些东西会混淆Vagrant安装脚本。

修改

我做了一些测试。看起来Vagrantfile被正确加入,但Vagrant Root在Windows文件树中将达到2级。

编辑2:

用户Emyl带我上了轨道,可能是我的通话脚本坏了。使用正常的Shell正在运行。 因为我发布了我写的Bash脚本,因为无论如何它都是开源的:

@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >>     "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------

cls
dir
cd %~dp0
dir
cd vagrant
dir
:start
echo Please select an Option:
echo -------------------------
echo 1: Start Vagrant VM
echo 2: Reload Vagrant VM
echo 3: Shutdown Vagrant VM
echo 4: Suspend Vagrant VM
echo 5: Destroy Vagrant VM (see Note)
echo 6: Command Line (for other commands)
echo 7: Exit
echo -------------------------
echo Note: Destroy will uninstall the VM, exept the Files in the Vagrant Folder! &     echo.Please create a Database-Dump before destroying the VM, to prevent Data-Loss.
echo -------------------------
set /p choice=Enter a Number: 
if '%choice%'=='1' goto :up
if '%choice%'=='2' goto :reload
if '%choice%'=='3' goto :halt
if '%choice%'=='4' goto :suspend
if '%choice%'=='5' goto :destroy
if '%choice%'=='6' goto :command
if '%choice%'=='7' goto :end
echo %Choice% is not a valid option. Please try again.
echo ...
goto :start
:up
vagrant up
goto :start
:reload
vagrant reload
goto :start
:halt
vagrant halt
goto :start
:suspend
vagrant suspend
goto :start
:destroy
vagrant destroy
goto :start
:command
set /p command=Enter Command: 
call %%command%%
goto :start
:end
pause
exit

编辑3:

问题依赖于使用批处理脚本调用文件。 问题是长路径名称被Windows缩短,如TUTORI~2。 这似乎打破了Vagrants Env Variable一代。

编辑4 - 解决方案:

如前所述,我使用批处理脚本调用Vagrant。 当使用当前脚本的位置“%~dp0”时,Vagrant不喜欢我的CMD生成的缩短的URL。 解决方案如下所述:

Solution

使用此代码片段,我可以创建一个Windows路径。使用此路径将导致Vagrant不再出现问题,并且正确生成了我的同步文件夹。

0 个答案:

没有答案
相关问题