Skip to content

Commit

Permalink
fix(kvstoreentry/create): rework --dir
Browse files Browse the repository at this point in the history
Simplify code and exclude directory when inserting keys into the KV store.
Before this change `create --dir=foo`, will create:

	foo/abc
	foo/def

After this change:

	abc
	def
  • Loading branch information
fgsch committed Jan 16, 2025
1 parent c3deac6 commit 228f618
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions pkg/commands/kvstoreentry/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ func (c *CreateCommand) ProcessDir(in io.Reader, out io.Writer) error {
msg := "%s %d of %d files"
spinner.Message(fmt.Sprintf(msg, "Processing", 0, filesTotal) + "...")

base := filepath.Base(path)
processed := make(chan struct{}, c.dirConcurrency)
sem := make(chan struct{}, c.dirConcurrency)
filesVerboseOutput := make(chan string, filesTotal)
Expand Down Expand Up @@ -240,14 +239,8 @@ func (c *CreateCommand) ProcessDir(in io.Reader, out io.Writer) error {
}()
defer wg.Done()

filePath := filepath.Join(c.dirPath, file.Name())
dir, filename := filepath.Split(filePath)
index := strings.Index(dir, base)
// If the user runs from `--dir .` (current directory)
if index == -1 {
index = 0
}
filename = filepath.Join(dir[index:], filename)
filename := file.Name()
filePath := filepath.Join(path, filename)

if c.Globals.Verbose() {
filesVerboseOutput <- filename
Expand Down

0 comments on commit 228f618

Please sign in to comment.