From 41b2f0869597c77bf63202a85052ebe1864996bd Mon Sep 17 00:00:00 2001 From: Blake Covarrubias Date: Tue, 10 Aug 2021 14:42:05 -0700 Subject: [PATCH] cli: Fix broken KV import on Windows (#10820) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consul 1.10 (PR #9792) introduced the ability to specify a prefix when importing KV's. This however introduced a regression on Windows systems which breaks `kv import`. The key name is joined with specified`-prefix` using `filepath.Join()` which uses a forward slash (/) to delimit values on Unix-based systems, and a backslash (\) to delimit values on Windows – the latter of which is incompatible with Consul KV paths. This commit replaces filepath.Join() with path.Join() which uses a forward slash as the delimiter, providing consistent key join behavior across supported operating systems. Fixes #10583 --- .changelog/10820.txt | 3 +++ command/kv/imp/kv_import.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .changelog/10820.txt diff --git a/.changelog/10820.txt b/.changelog/10820.txt new file mode 100644 index 000000000..506355c27 --- /dev/null +++ b/.changelog/10820.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: Fix broken KV import command on Windows. +``` diff --git a/command/kv/imp/kv_import.go b/command/kv/imp/kv_import.go index 0c46ffd5b..6188dbf4f 100644 --- a/command/kv/imp/kv_import.go +++ b/command/kv/imp/kv_import.go @@ -10,7 +10,7 @@ import ( "io" "io/ioutil" "os" - "path/filepath" + "path" "github.com/hashicorp/consul/api" "github.com/hashicorp/consul/command/flags" @@ -79,7 +79,7 @@ func (c *cmd) Run(args []string) int { } pair := &api.KVPair{ - Key: filepath.Join(c.prefix, entry.Key), + Key: path.Join(c.prefix, entry.Key), Flags: entry.Flags, Value: value, }