@@ -14,6 +14,7 @@ import (
1414
1515 "github.com/codeclysm/extract/v4"
1616 "github.com/go-git/go-git/v5"
17+ cp "github.com/otiai10/copy"
1718)
1819
1920func downloadFile (filepath string , url string ) (err error ) {
@@ -121,25 +122,39 @@ func main() {
121122 // Use packer/tar and compress/bzip2 to extract the file
122123 file , err := os .Open (filepath .Join (tmpDir , filename ))
123124 if err != nil {
124- fmt .Println ("Error opening zip file :" , err )
125+ fmt .Println ("Error opening archive :" , err )
125126 return
126127 }
127128 defer file .Close ()
128- extract .Bz2 (context .Background (), file , filepath .Join (tmpDir , "extract" ), nil )
129- // Copy the content of firmware folder to gitCorePath/firmware
130- err = os .CopyFS (filepath .Join (gitCorePath , "firmwares" ), os .DirFS (filepath .Join (tmpDir , "extract" , "ArduinoCore-zephyr" , "firmwares" )))
129+
130+ err = extract .Bz2 (context .Background (), file , filepath .Join (tmpDir , "extract" ), nil )
131131 if err != nil {
132- fmt .Println ("Error copying firmware folder :" , err )
132+ fmt .Println ("Error extracting archive :" , err )
133133 return
134134 }
135- // Copy the content of variants folder to gitCorePath/variants
136- // Since CopyFS does not overwrite, before doing so remove gitCorePath/variants
137- err = os .RemoveAll (filepath .Join (gitCorePath , "variants" ))
135+
136+ // Remove old firmwares and variants/*/llext-edk files
137+ os .RemoveAll (filepath .Join (gitCorePath , "firmwares" ))
138+ filepath .WalkDir (filepath .Join (gitCorePath , "variants" ), func (path string , d os.DirEntry , err error ) error {
139+ if err != nil {
140+ fmt .Println ("Error:" , err )
141+ return nil
142+ }
143+
144+ if d .IsDir () && d .Name () == "llext-edk" {
145+ os .RemoveAll (path )
146+ }
147+ return nil
148+ })
149+
150+ // Copy the content of firmware folder to gitCorePath/firmware
151+ err = cp .Copy (filepath .Join (tmpDir , "extract" , "ArduinoCore-zephyr" , "firmwares" ), filepath .Join (gitCorePath , "firmwares" ))
138152 if err != nil {
139- fmt .Println ("Error renaming variants folder:" , err )
153+ fmt .Println ("Error copying firmware folder:" , err )
140154 return
141155 }
142- err = os .CopyFS (filepath .Join (gitCorePath , "variants" ), os .DirFS (filepath .Join (tmpDir , "extract" , "ArduinoCore-zephyr" , "variants" )))
156+ // Copy the content of variants folder to gitCorePath/variants
157+ err = cp .Copy (filepath .Join (tmpDir , "extract" , "ArduinoCore-zephyr" , "variants" ), filepath .Join (gitCorePath , "variants" ))
143158 if err != nil {
144159 fmt .Println ("Error copying variants folder:" , err )
145160 return
0 commit comments