@@ -17,13 +17,11 @@ package sketch
17
17
18
18
import (
19
19
"context"
20
- "io/ioutil"
21
- "os"
22
- "path/filepath"
23
20
24
21
"github.com/arduino/arduino-cli/arduino/globals"
25
22
"github.com/arduino/arduino-cli/commands"
26
23
"github.com/arduino/arduino-cli/configuration"
24
+ paths "github.com/arduino/go-paths-helper"
27
25
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
28
26
)
29
27
@@ -36,31 +34,31 @@ void loop() {
36
34
` )
37
35
38
36
// CreateSketch creates a new sketch
39
- func CreateSketch (sketchDir string , sketchName string ) (string , error ) {
40
- if err := os .MkdirAll (sketchDir , os . FileMode ( 0755 ) ); err != nil {
41
- return "" , err
37
+ func CreateSketch (sketchDirPath * paths. Path ) (* paths. Path , error ) {
38
+ if err := sketchDirPath .MkdirAll (); err != nil {
39
+ return nil , err
42
40
}
43
- baseSketchName := filepath .Base (sketchDir )
44
- sketchFile := filepath .Join (sketchDir , baseSketchName + globals .MainFileValidExtension )
45
- if err := ioutil .WriteFile (sketchFile , emptySketch , os . FileMode ( 0644 ) ); err != nil {
46
- return "" , err
41
+ baseSketchName := sketchDirPath .Base ()
42
+ sketchFilePath := sketchDirPath .Join (baseSketchName + globals .MainFileValidExtension )
43
+ if err := sketchFilePath .WriteFile (emptySketch ); err != nil {
44
+ return nil , err
47
45
}
48
- return sketchFile , nil
46
+ return sketchFilePath , nil
49
47
}
50
48
51
- // NewSketch FIXMEDOC
49
+ // NewSketch creates a new sketch via gRPC
52
50
func NewSketch (ctx context.Context , req * rpc.NewSketchRequest ) (* rpc.NewSketchResponse , error ) {
53
51
var sketchesDir string
54
52
if len (req .SketchDir ) > 0 {
55
53
sketchesDir = req .SketchDir
56
54
} else {
57
55
sketchesDir = configuration .Settings .GetString ("directories.User" )
58
56
}
59
- sketchDir := filepath . Join (sketchesDir , req .SketchName )
60
- sketchFile , err := CreateSketch (sketchDir , req . SketchName )
57
+ sketchDirPath := paths . New (sketchesDir ). Join ( req .SketchName )
58
+ sketchFilePath , err := CreateSketch (sketchDirPath )
61
59
if err != nil {
62
60
return nil , & commands.CantCreateSketchError {Cause : err }
63
61
}
64
62
65
- return & rpc.NewSketchResponse {MainFile : sketchFile }, nil
63
+ return & rpc.NewSketchResponse {MainFile : sketchFilePath . String () }, nil
66
64
}
0 commit comments