From 9bf7851cf019b46c78813345a42b498283a36e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Kivim=C3=A4ki?= Date: Fri, 15 Nov 2024 14:48:01 +0200 Subject: [PATCH] fix: make why work with Windows path --- internal/cli/why.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/cli/why.go b/internal/cli/why.go index e970d919..da6c8a17 100644 --- a/internal/cli/why.go +++ b/internal/cli/why.go @@ -78,13 +78,13 @@ func runWhy(cmd *cobra.Command, opts whyOptions) error { for _, sauce := range sauces { for file := range sauce.Files { - if fileinfo.IsDir() { - if strings.HasPrefix(file, opts.Filepath) { - cmd.Printf("Directory '%s' is created by the recipe '%s' (sauce ID %s).\n", opts.Filepath, sauce.Recipe.Name, sauce.ID) - return nil - } + cleanedFilePath := filepath.Clean(file) + if fileinfo.IsDir() && strings.HasPrefix(cleanedFilePath, opts.Filepath) { + cmd.Printf("Directory '%s' is created by the recipe '%s' (sauce ID %s).\n", opts.Filepath, sauce.Recipe.Name, sauce.ID) + return nil } - if opts.Filepath == file { + + if opts.Filepath == cleanedFilePath { // TODO: Check if the file is modified by the user by comparing hashes cmd.Printf("File '%s' is created by the recipe '%s' (sauce ID %s).\n", opts.Filepath, sauce.Recipe.Name, sauce.ID) return nil