-
Notifications
You must be signed in to change notification settings - Fork 5
/
file.go
41 lines (32 loc) · 842 Bytes
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package check
import (
"fmt"
"log"
"os"
"path/filepath"
)
type FileCheck interface {
Run(string) error
RunAll([]string) error
}
type FileOptions struct {
BasePath string
}
func (opts *FileOptions) FullPath(path string) string {
if opts.BasePath != "" {
return filepath.Join(opts.BasePath, path)
}
return path
}
// FileSizeCheck verifies that documentation file is below the Terraform Registry storage limit.
func FileSizeCheck(fullpath string) error {
fi, err := os.Stat(fullpath)
if err != nil {
return err
}
log.Printf("[DEBUG] File %s size: %d (limit: %d)", fullpath, fi.Size(), RegistryMaximumSizeOfFile)
if fi.Size() >= int64(RegistryMaximumSizeOfFile) {
return fmt.Errorf("exceeded maximum (%d) size of documentation file for Terraform Registry: %d", RegistryMaximumSizeOfFile, fi.Size())
}
return nil
}