@@ -14,6 +14,7 @@ import (
14
14
15
15
"github.com/codeclysm/extract/v4"
16
16
"github.com/go-git/go-git/v5"
17
+ cp "github.com/otiai10/copy"
17
18
)
18
19
19
20
func downloadFile (filepath string , url string ) (err error ) {
@@ -121,25 +122,39 @@ func main() {
121
122
// Use packer/tar and compress/bzip2 to extract the file
122
123
file , err := os .Open (filepath .Join (tmpDir , filename ))
123
124
if err != nil {
124
- fmt .Println ("Error opening zip file :" , err )
125
+ fmt .Println ("Error opening archive :" , err )
125
126
return
126
127
}
127
128
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 )
131
131
if err != nil {
132
- fmt .Println ("Error copying firmware folder :" , err )
132
+ fmt .Println ("Error extracting archive :" , err )
133
133
return
134
134
}
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" ))
138
152
if err != nil {
139
- fmt .Println ("Error renaming variants folder:" , err )
153
+ fmt .Println ("Error copying firmware folder:" , err )
140
154
return
141
155
}
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" ))
143
158
if err != nil {
144
159
fmt .Println ("Error copying variants folder:" , err )
145
160
return
0 commit comments