@@ -20,6 +20,7 @@ import (
2020 "compress/gzip"
2121 "fmt"
2222 "io"
23+ "io/fs"
2324 "mime/multipart"
2425 "net/http"
2526 "os"
@@ -54,17 +55,17 @@ var (
5455)
5556
5657func UploadTarball (
57- directory string ,
58+ directory fs. FS ,
5859 presignedUrl string ,
5960 presignedPostRequest * livekit.PresignedPostRequest ,
6061 excludeFiles []string ,
6162 projectType ProjectType ,
6263) error {
6364 excludeFiles = append (excludeFiles , defaultExcludePatterns ... )
6465
65- loadExcludeFiles := func (filename string ) (bool , string , error ) {
66- if _ , err := os .Stat (filename ); err == nil {
67- content , err := os .ReadFile (filename )
66+ loadExcludeFiles := func (dir fs. FS , filename string ) (bool , string , error ) {
67+ if _ , err := fs .Stat (dir , filename ); err == nil {
68+ content , err := fs .ReadFile (dir , filename )
6869 if err != nil {
6970 return false , "" , err
7071 }
@@ -75,7 +76,7 @@ func UploadTarball(
7576
7677 foundDockerIgnore := false
7778 for _ , exclude := range ignoreFilePatterns {
78- found , content , err := loadExcludeFiles (path . Join ( directory , exclude ) )
79+ found , content , err := loadExcludeFiles (directory , exclude )
7980 if err != nil {
8081 logger .Debugw ("failed to load exclude file" , "filename" , exclude , "error" , err )
8182 continue
@@ -89,7 +90,7 @@ func UploadTarball(
8990 // need to ensure we use a dockerignore file
9091 // if we fail to load a dockerignore file, we have to exit
9192 if ! foundDockerIgnore {
92- dockerIgnoreContent , err := fs .ReadFile (path .Join ("examples" , string (projectType )+ ".dockerignore" ))
93+ dockerIgnoreContent , err := fs .ReadFile (directory , path .Join ("examples" , string (projectType )+ ".dockerignore" ))
9394 if err != nil {
9495 return fmt .Errorf ("failed to load exclude file %s: %w" , string (projectType ), err )
9596 }
@@ -105,7 +106,7 @@ func UploadTarball(
105106 excludeFiles [i ] = strings .TrimSpace (exclude )
106107 }
107108
108- checkFilesToInclude := func (path string , info os. FileInfo ) bool {
109+ checkFilesToInclude := func (path string ) bool {
109110 fileName := filepath .Base (path )
110111 // we have to include the Dockerfile in the upload, as it is required for the build
111112 if strings .Contains (fileName , "Dockerfile" ) {
@@ -123,17 +124,17 @@ func UploadTarball(
123124 // we walk the directory first to calculate the total size of the tarball
124125 // this lets the progress bar show the correct progress
125126 var totalSize int64
126- err = filepath . Walk (directory , func (path string , info os. FileInfo , err error ) error {
127+ err = fs . WalkDir (directory , "." , func (path string , d fs. DirEntry , err error ) error {
127128 if err != nil {
128129 return err
129130 }
130131
131- relPath , err := filepath . Rel ( directory , path )
132+ info , err := d . Info ( )
132133 if err != nil {
133- return nil
134+ return err
134135 }
135136
136- if ! checkFilesToInclude (relPath , info ) {
137+ if ! checkFilesToInclude (path ) {
137138 return nil
138139 }
139140
@@ -166,17 +167,19 @@ func UploadTarball(
166167 tarWriter := tar .NewWriter (gzipWriter )
167168 defer tarWriter .Close ()
168169
169- err = filepath . Walk (directory , func (path string , info os. FileInfo , err error ) error {
170+ err = fs . WalkDir (directory , "." , func (path string , d fs. DirEntry , err error ) error {
170171 if err != nil {
171172 return err
172173 }
173174
174- relPath , err := filepath . Rel ( directory , path )
175+ info , err := d . Info ( )
175176 if err != nil {
176- return fmt . Errorf ( "failed to calculate relative path for %s: %w" , path , err )
177+ return err
177178 }
178179
179- if ! checkFilesToInclude (relPath , info ) {
180+ relPath := path
181+
182+ if ! checkFilesToInclude (relPath ) {
180183 logger .Debugw ("excluding file from tarball" , "path" , path )
181184 return nil
182185 }
0 commit comments