6
6
"log"
7
7
"os"
8
8
"path/filepath"
9
- "strings"
10
9
11
10
hcversion "github.com/hashicorp/go-version"
12
11
@@ -28,24 +27,9 @@ func copySchemas() error {
28
27
return fmt .Errorf ("remove dir: %w" , err )
29
28
}
30
29
31
- err = os .MkdirAll (dstDir , os .ModePerm )
30
+ err = os .CopyFS (dstDir , os .DirFS ( "jsonschema" ) )
32
31
if err != nil {
33
- return fmt .Errorf ("make dir: %w" , err )
34
- }
35
-
36
- // The key is the destination file.
37
- // The value is the source file.
38
- files := map [string ]string {}
39
-
40
- entries , err := os .ReadDir ("jsonschema" )
41
- if err != nil {
42
- return fmt .Errorf ("read dir: %w" , err )
43
- }
44
-
45
- for _ , entry := range entries {
46
- if strings .HasSuffix (entry .Name (), ".jsonschema.json" ) {
47
- files [entry .Name ()] = entry .Name ()
48
- }
32
+ return fmt .Errorf ("copy FS: %w" , err )
49
33
}
50
34
51
35
latest , err := github .GetLatestVersion ()
@@ -59,13 +43,10 @@ func copySchemas() error {
59
43
}
60
44
61
45
versioned := fmt .Sprintf ("golangci.v%d.%d.jsonschema.json" , version .Segments ()[0 ], version .Segments ()[1 ])
62
- files [versioned ] = "golangci.jsonschema.json"
63
46
64
- for dst , src := range files {
65
- err := copyFile (filepath .Join ("jsonschema" , src ), filepath .Join (dstDir , dst ))
66
- if err != nil {
67
- return fmt .Errorf ("copy files: %w" , err )
68
- }
47
+ err = copyFile (filepath .FromSlash ("jsonschema/golangci.jsonschema.json" ), filepath .Join (dstDir , versioned ))
48
+ if err != nil {
49
+ return fmt .Errorf ("copy files: %w" , err )
69
50
}
70
51
71
52
return nil
0 commit comments