@@ -22,6 +22,7 @@ import (
2222 "io"
2323 "net/http"
2424 "os"
25+ pathpkg "path"
2526 "path/filepath"
2627 "strings"
2728
4243 }
4344
4445 ignoreFilePatterns = []string {
45- ".gitignore" ,
4646 ".dockerignore" ,
4747 }
4848)
@@ -61,8 +61,17 @@ func UploadTarball(directory string, presignedUrl string, excludeFiles []string)
6161 }
6262 }
6363
64- for i , exclude := range excludeFiles {
65- excludeFiles [i ] = strings .TrimSpace (exclude )
64+ // Normalize and filter ignore patterns
65+ {
66+ filtered := make ([]string , 0 , len (excludeFiles ))
67+ for _ , exclude := range excludeFiles {
68+ exclude = strings .TrimSpace (exclude )
69+ if exclude == "" || strings .HasPrefix (exclude , "#" ) {
70+ continue
71+ }
72+ filtered = append (filtered , filepath .ToSlash (exclude ))
73+ }
74+ excludeFiles = filtered
6675 }
6776
6877 var totalSize int64
@@ -75,17 +84,19 @@ func UploadTarball(directory string, presignedUrl string, excludeFiles []string)
7584 if err != nil {
7685 return nil
7786 }
87+ // Use forward slashes inside tar archives regardless of OS
88+ relPath = filepath .ToSlash (relPath )
7889
7990 for _ , exclude := range excludeFiles {
8091 if exclude == "" || strings .Contains (exclude , "Dockerfile" ) {
8192 continue
8293 }
8394 if info .IsDir () {
84- if strings .HasPrefix (relPath , exclude + "/" ) || strings . HasPrefix ( relPath , exclude ) {
95+ if strings .HasPrefix (relPath , exclude + "/" ) || relPath == exclude {
8596 return filepath .SkipDir
8697 }
8798 }
88- matched , err := filepath .Match (exclude , relPath )
99+ matched , err := pathpkg .Match (exclude , relPath )
89100 if err != nil {
90101 return nil
91102 }
@@ -132,20 +143,22 @@ func UploadTarball(directory string, presignedUrl string, excludeFiles []string)
132143 if err != nil {
133144 return fmt .Errorf ("failed to calculate relative path for %s: %w" , path , err )
134145 }
146+ // Normalize to forward slashes for tar header names and matching
147+ relPath = filepath .ToSlash (relPath )
135148
136149 for _ , exclude := range excludeFiles {
137150 if exclude == "" || strings .Contains (exclude , "Dockerfile" ) {
138151 continue
139152 }
140153
141154 if info .IsDir () {
142- if strings .HasPrefix (relPath , exclude + "/" ) || strings . HasPrefix ( relPath , exclude ) {
155+ if strings .HasPrefix (relPath , exclude + "/" ) || relPath == exclude {
143156 logger .Debugw ("excluding directory from tarball" , "path" , path )
144157 return filepath .SkipDir
145158 }
146159 }
147160
148- matched , err := filepath .Match (exclude , relPath )
161+ matched , err := pathpkg .Match (exclude , relPath )
149162 if err != nil {
150163 return nil
151164 }
0 commit comments