Skip to content

Commit

Permalink
Merge pull request #251 from test-kitchen/afiune/250/fix-windows-cach…
Browse files Browse the repository at this point in the history
…e-dir

Fix cache directory on windows
  • Loading branch information
Salim Afiune authored Nov 30, 2016
2 parents 46e32fa + 16c346e commit ae31b86
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,23 @@ Vagrant.configure("2") do |config|
end
```

### <a name="config-cache_directory"></a> cache_directory

Customize the cache directory on the instance. This parameter must be an
absolute path.

The defaults are:
* Windows: `C:\\omnibus\\cache`
* Unix: `/tmp/omnibus/cache`

The example:

```yaml
---
driver:
cache_directory: Z:\\custom\\cache
```

### <a name="config-vagrantfile-erb"></a> vagrantfile\_erb

An alternate Vagrantfile ERB template that will be rendered for use by this
Expand Down
6 changes: 5 additions & 1 deletion lib/kitchen/driver/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class Vagrant < Kitchen::Driver::Base
driver.windows_os? ? nil : driver.instance.name
end

default_config(:cache_directory) do |driver|
driver.windows_os? ? "C:\\omnibus\\cache" : "/tmp/omnibus/cache"
end

no_parallel_for :create, :destroy

# Creates a Vagrant VM instance.
Expand Down Expand Up @@ -173,7 +177,7 @@ def winrm_transport?
# and share a local folder to that directory so that we don't pull them
# down every single time
def cache_directory
windows_os? ? "$env:TEMP\\omnibus\\cache" : "/tmp/omnibus/cache"
config[:cache_directory]
end

protected
Expand Down
30 changes: 29 additions & 1 deletion spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def run_command(_cmd, options = {})
let(:win_cache_directory_array) do
[
File.expand_path("~/.kitchen/cache"),
"$env:TEMP\\omnibus\\cache",
"C:\\omnibus\\cache",
"create: true"
]
end
Expand Down Expand Up @@ -468,6 +468,34 @@ def run_command(_cmd, options = {})
])
end
end

context "when cache_directory is customized" do

let(:custom_cache_directory_array) do
[
File.expand_path("~/.kitchen/cache"),
"Z:\\awesome\\cache",
"create: true"
]
end

before { config[:cache_directory] = 'Z:\\awesome\\cache' }

it "sets :synced_folders with the custom cache_directory" do
expect(driver[:synced_folders]).to eq([custom_cache_directory_array])
end

it "replaces %{instance_name} with instance name in :synced_folders" do
config[:synced_folders] = [
["/root/%{instance_name}", "/vm_path", "stuff"]
]

expect(driver[:synced_folders]).to eq([
[File.expand_path("/root/suitey-fooos-99"), "/vm_path", "stuff"],
custom_cache_directory_array
])
end
end
end

describe "#verify_dependencies" do
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# limitations under the License.

if ENV["CODECLIMATE_REPO_TOKEN"]
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
require "simplecov"
SimpleCov.start
elsif ENV["COVERAGE"]
require "simplecov"
SimpleCov.profiles.define "gem" do
Expand Down

1 comment on commit ae31b86

@kernelsmith
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually tried this change manually and it didn't work, seems like the cache string is getting interpreted twice. I had to use c:\\omnibus\\cache otherwise it continued to present as c:omnibusche

 default: -- /Users/me/.kitchen/cache: C:omnibusche
STDERR: The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

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("C:omnibusche")
$ShareName = "C:omnibusche"
$VmProviderUncPath = "\\vmware-host\Shared Folders\C:omnibusche"

Please sign in to comment.