@@ -22,6 +22,7 @@ import (
2222 "io"
2323 "net/http"
2424 "os"
25+ pathpkg "path"
2526 "path/filepath"
2627 "strings"
2728
4344 }
4445
4546 ignoreFilePatterns = []string {
46- ".gitignore" ,
4747 ".dockerignore" ,
4848 }
4949)
@@ -62,8 +62,17 @@ func UploadTarball(directory string, presignedUrl string, excludeFiles []string)
6262 }
6363 }
6464
65- for i , exclude := range excludeFiles {
66- excludeFiles [i ] = strings .TrimSpace (exclude )
65+ // Normalize and filter ignore patterns
66+ {
67+ filtered := make ([]string , 0 , len (excludeFiles ))
68+ for _ , exclude := range excludeFiles {
69+ exclude = strings .TrimSpace (exclude )
70+ if exclude == "" || strings .HasPrefix (exclude , "#" ) {
71+ continue
72+ }
73+ filtered = append (filtered , filepath .ToSlash (exclude ))
74+ }
75+ excludeFiles = filtered
6776 }
6877
6978 var totalSize int64
@@ -76,17 +85,19 @@ func UploadTarball(directory string, presignedUrl string, excludeFiles []string)
7685 if err != nil {
7786 return nil
7887 }
88+ // Use forward slashes inside tar archives regardless of OS
89+ relPath = filepath .ToSlash (relPath )
7990
8091 for _ , exclude := range excludeFiles {
8192 if exclude == "" || strings .Contains (exclude , "Dockerfile" ) {
8293 continue
8394 }
8495 if info .IsDir () {
85- if strings .HasPrefix (relPath , exclude + "/" ) || strings . HasPrefix ( relPath , exclude ) {
96+ if strings .HasPrefix (relPath , exclude + "/" ) || relPath == exclude {
8697 return filepath .SkipDir
8798 }
8899 }
89- matched , err := filepath .Match (exclude , relPath )
100+ matched , err := pathpkg .Match (exclude , relPath )
90101 if err != nil {
91102 return nil
92103 }
@@ -133,20 +144,22 @@ func UploadTarball(directory string, presignedUrl string, excludeFiles []string)
133144 if err != nil {
134145 return fmt .Errorf ("failed to calculate relative path for %s: %w" , path , err )
135146 }
147+ // Normalize to forward slashes for tar header names and matching
148+ relPath = filepath .ToSlash (relPath )
136149
137150 for _ , exclude := range excludeFiles {
138151 if exclude == "" || strings .Contains (exclude , "Dockerfile" ) {
139152 continue
140153 }
141154
142155 if info .IsDir () {
143- if strings .HasPrefix (relPath , exclude + "/" ) || strings . HasPrefix ( relPath , exclude ) {
156+ if strings .HasPrefix (relPath , exclude + "/" ) || relPath == exclude {
144157 logger .Debugw ("excluding directory from tarball" , "path" , path )
145158 return filepath .SkipDir
146159 }
147160 }
148161
149- matched , err := filepath .Match (exclude , relPath )
162+ matched , err := pathpkg .Match (exclude , relPath )
150163 if err != nil {
151164 return nil
152165 }
0 commit comments