VirtualBox7.0+vagrant_2.3.5搭建虚拟环境时报错“权限被拒绝“

        在Windows11操作系统中使用VirtualBox7.0+vagrant_2.3.5搭建虚拟环境。在执行vagrant up命令时,提示如下错误。

D:/softTool/Vagrant/embedded/gems/gems/vagrant-2.3.5/lib/vagrant/util/file_mutex.rb:27:in `delete': Permission denied @ apply2files -     D:/softTool/Vagrant/.vagrant.d/tmp/box268f3b7ad82a60ceb55f991152a6e2021bc589b7.lock (Errno::EACCES)

      上述错误的信息提示为:权限被拒绝

    解决办法:D:\softTool\Vagrant\embedded\gems\gems\vagrant-2.3.5\lib\vagrant\util\目录下的file_mutex.rb文件内容进行替换

  替换内容如下:

module Vagrant
  module Util
    # Utility to provide a simple mutex via file lock
    class FileMutex
      # Create a new FileMutex instance
      #
      # @param mutex_path [String] path for file
      def initialize(mutex_path)
        @mutex_path = mutex_path
      end

      # Execute provided block within lock and unlock
      # when completed
      def with_lock(&block)
        lock
        begin
          block.call
        rescue => e
          raise e
        ensure
          unlock
        end
      end

      # Attempt to acquire the lock
      def lock
        if lock_file.flock(File::LOCK_EX|File::LOCK_NB) === false
          raise Errors::VagrantLocked, lock_file_path: @mutex_path
        end
      end

      # Unlock the file
      def unlock
        lock_file.flock(File::LOCK_UN)
        lock_file.close
        File.delete(@mutex_path) if File.file?(@mutex_path)
      end

      protected

      def lock_file
        return @lock_file if @lock_file && !@lock_file.closed?
        @lock_file = File.open(@mutex_path, "w+")
      end
    end
  end
end

  文件内容的获取地址:

vagrant/lib/vagrant/util/file_mutex.rb at 1f26256680a5bc4c78a8e14187aa8a0b926119be · chrisroberts/vagrant · GitHub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值