Merge pull request #632 from KushalP/master

config: do not read temporary editor files, fixes #548
This commit is contained in:
Mitchell Hashimoto 2014-12-15 15:07:03 -08:00
commit c2385a5012
5 changed files with 71 additions and 1 deletions

View File

@ -162,7 +162,7 @@ func dirFiles(dir string) ([]string, []string, error) {
// Only care about files that are valid to load
name := fi.Name()
extValue := ext(name)
if extValue == "" {
if extValue == "" || isTemporaryFile(name) {
continue
}
@ -182,3 +182,12 @@ func dirFiles(dir string) ([]string, []string, error) {
return files, overrides, nil
}
// isTemporaryFile returns true or false depending on whether the
// provided file name is a temporary file for the following editors:
// emacs or vim.
func isTemporaryFile(name string) bool {
return strings.HasSuffix(name, "~") || // vim
strings.HasPrefix(name, ".#") || // emacs
(strings.HasPrefix(name, "#") && strings.HasSuffix(name, "#")) // emacs
}

View File

@ -383,6 +383,13 @@ func TestLoad_createBeforeDestroy(t *testing.T) {
}
}
func TestLoad_temporary_files(t *testing.T) {
_, err := LoadDir(filepath.Join(fixtureDir, "dir-temporary-files"))
if err == nil {
t.Fatalf("Expected to see an error stating no config files found")
}
}
const basicOutputsStr = `
web_ip
vars

View File

@ -0,0 +1,20 @@
provider "do" {
api_key = "${var.foo}"
}
resource "aws_security_group" "firewall" {
count = 5
}
resource aws_instance "web" {
ami = "${var.foo}"
security_groups = [
"foo",
"${aws_security_group.firewall.foo}"
]
network_interface {
device_index = 0
description = "Main network interface"
}
}

View File

@ -0,0 +1,17 @@
variable "foo" {
default = "bar"
description = "bar"
}
provider "aws" {
access_key = "foo"
secret_key = "bar"
}
resource "aws_instance" "db" {
security_groups = "${aws_security_group.firewall.*.id}"
}
output "web_ip" {
value = "${aws_instance.web.private_ip}"
}

View File

@ -0,0 +1,17 @@
variable "foo" {
default = "bar"
description = "bar"
}
provider "aws" {
access_key = "foo"
secret_key = "bar"
}
resource "aws_instance" "db" {
security_groups = "${aws_security_group.firewall.*.id}"
}
output "web_ip" {
value = "${aws_instance.web.private_ip}"
}