Skip to content

Commit b946d76

Browse files
committed
sync-zephyr-artifacts: use otiai10/copy instead of os.CopyFS to overwrite
1 parent 2d00fc4 commit b946d76

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

extra/sync-zephyr-artifacts/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.24.1
55
require (
66
github.com/codeclysm/extract/v4 v4.0.0
77
github.com/go-git/go-git/v5 v5.14.0
8+
github.com/otiai10/copy v1.14.1
89
)
910

1011
require (
@@ -23,13 +24,15 @@ require (
2324
github.com/juju/loggo v1.0.0 // indirect
2425
github.com/kevinburke/ssh_config v1.2.0 // indirect
2526
github.com/klauspost/compress v1.15.13 // indirect
27+
github.com/otiai10/mint v1.6.3 // indirect
2628
github.com/pjbgf/sha1cd v0.3.2 // indirect
2729
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
2830
github.com/skeema/knownhosts v1.3.1 // indirect
2931
github.com/ulikunitz/xz v0.5.12 // indirect
3032
github.com/xanzy/ssh-agent v0.3.3 // indirect
3133
golang.org/x/crypto v0.35.0 // indirect
3234
golang.org/x/net v0.36.0 // indirect
35+
golang.org/x/sync v0.8.0 // indirect
3336
golang.org/x/sys v0.30.0 // indirect
3437
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
3538
gopkg.in/warnings.v0 v0.1.2 // indirect

extra/sync-zephyr-artifacts/go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ github.com/mattn/go-colorable v0.0.6/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO
6565
github.com/mattn/go-isatty v0.0.0-20160806122752-66b8e73f3f5c/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
6666
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
6767
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
68+
github.com/otiai10/copy v1.14.1 h1:5/7E6qsUMBaH5AnQ0sSLzzTg1oTECmcCmT6lvF45Na8=
69+
github.com/otiai10/copy v1.14.1/go.mod h1:oQwrEDDOci3IM8dJF0d8+jnbfPDllW6vUjNc3DoZm9I=
70+
github.com/otiai10/mint v1.6.3 h1:87qsV/aw1F5as1eH1zS/yqHY85ANKVMgkDrf9rcxbQs=
71+
github.com/otiai10/mint v1.6.3/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
6872
github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4=
6973
github.com/pjbgf/sha1cd v0.3.2/go.mod h1:zQWigSxVmsHEZow5qaLtPYxpcKMMQpa09ixqBxuCS6A=
7074
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -97,6 +101,8 @@ golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
97101
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
98102
golang.org/x/net v0.36.0 h1:vWF2fRbw4qslQsQzgFqZff+BItCvGFQqKzKIzx1rmoA=
99103
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
104+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
105+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
100106
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
101107
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
102108
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

extra/sync-zephyr-artifacts/main.go

+25-10
Original file line numberDiff line numberDiff line change
@@ -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

1920
func 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

Comments
 (0)