Skip to content

Commit a251fda

Browse files
committed
a better workaround
1 parent e47186c commit a251fda

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

internal/orchestrator/orchestrator.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,35 +1253,32 @@ func configureMicroInRamMode(
12531253
srv rpc.ArduinoCoreServiceServer,
12541254
inst *rpc.Instance,
12551255
) error {
1256+
emptyBinDir := paths.New("/tmp/empty")
1257+
defer emptyBinDir.RemoveAll()
1258+
if err := emptyBinDir.MkdirAll(); err != nil {
1259+
return err
1260+
}
1261+
12561262
zeros, err := os.Open("/dev/zero")
12571263
if err != nil {
12581264
return err
12591265
}
12601266
defer zeros.Close()
12611267

1262-
// FIXME: arduino-cli upload checks that a file exist but the extension is added after by the platform configuration.
1263-
// So we create two temporary files with some zeros.
1264-
for _, tmpFile := range paths.NewPathList("/tmp/empty", "/tmp/empty.elf-zsk.bin") {
1265-
if err := func(path *paths.Path) error {
1266-
empty, err := path.Create()
1267-
if err != nil {
1268-
return err
1269-
}
1270-
defer empty.Close()
1271-
if _, err := io.CopyN(empty, zeros, 50); err != nil {
1272-
return err
1273-
}
1274-
return nil
1275-
}(tmpFile); err != nil {
1276-
return fmt.Errorf("failed to write empty file %q: %w", tmpFile.String(), err)
1277-
}
1268+
empty, err := emptyBinDir.Join("empty.ino.elf-zsk.bin").Create()
1269+
if err != nil {
1270+
return err
1271+
}
1272+
defer empty.Close()
1273+
if _, err := io.CopyN(empty, zeros, 50); err != nil {
1274+
return err
12781275
}
12791276

12801277
stream, _ := commands.UploadToServerStreams(ctx, w, w)
12811278
return srv.Upload(&rpc.UploadRequest{
1282-
Instance: inst,
1283-
Fqbn: "arduino:zephyr:unoq:flash_mode=flash",
1284-
ImportFile: "/tmp/empty",
1279+
Instance: inst,
1280+
Fqbn: "arduino:zephyr:unoq:flash_mode=flash",
1281+
ImportDir: emptyBinDir.String(),
12851282
}, stream)
12861283
}
12871284

0 commit comments

Comments
 (0)