<commit_before>require "shellwords"

module VagrantDarwinSMB
  module Errors
    class DarwinMountFailed < Vagrant::Errors::VagrantError
      error_key(:darwin_mount_failed)
    end 
  end

  module Cap
    class MountSMBSharedFolder
      extend Vagrant::Util::Retryable
      def self.mount_smb_shared_folder(machine, name, guestpath, options)
        expanded_guest_path = machine.guest.capability(:shell_expand_guest_path, guestpath)
        # create the guest path if it doesn't exist
        machine.communicate.execute("mkdir -p #{expanded_guest_path}")

        smb_password = <PASSWORD>words.shellescape(options[:smb_password])
        mount_opts = options[:mount_options];
        mount_command = "mount -t smbfs " +
          (mount_opts ? "-o '#{mount_opts.join(",")}' " : "") +
          "'//#{options[:smb_username]}:#{smb_password}@#{options[:smb_host]}/#{name}' " +
          "#{expanded_guest_path}"
        retryable(on: Errors::DarwinMountFailed, tries: 10, sleep: 5) do 
          machine.communicate.execute(
            mount_command,
            error_class: Errors::DarwinMountFailed)
        end
      end
    end
  end
end<commit_msg>Mounting to paths where user has no write permissions (e.g. /)<commit_after>require "shellwords"

module VagrantDarwinSMB
  module Errors
    class DarwinMountFailed < Vagrant::Errors::VagrantError
      error_key(:darwin_mount_failed)
    end 
  end

  module Cap
    class MountSMBSharedFolder
      extend Vagrant::Util::Retryable
      def self.mount_smb_shared_folder(machine, name, guestpath, options)
        expanded_guest_path = machine.guest.capability(:shell_expand_guest_path, guestpath)
        
        mount_point_owner = options[:owner];
        if mount_point_owner
          machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
          machine.communicate.sudo("chown #{mount_point_owner} #{expanded_guest_path}")
        else
          # fallback to assumption that user has permission
          # to create the specified mountpoint
          machine.communicate.execute("mkdir -p #{expanded_guest_path}")
        end

        smb_password = <PASSWORD>(options[:smb_password])
        mount_opts = options[:mount_options];
        mount_command = "mount -t smbfs " +
          (mount_opts ? "-o '#{mount_opts.join(",")}' " : "") +
          "'//#{options[:smb_username]}:#{smb_password}@#{options[:smb_host]}/#{name}' " +
          "#{expanded_guest_path}"
        retryable(on: Errors::DarwinMountFailed, tries: 10, sleep: 2) do
          machine.communicate.execute(
            mount_command,
            error_class: Errors::DarwinMountFailed)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11023916292974589, 'fraction_numerical': 0.002242152466367713, 'mean_word_length': 3.0438066465256797, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3103554', 'n_tokens_mistral': 837, 'n_tokens_neox': 832, 'n_words': 157}