Skip to content

Commit 03f5f8d

Browse files
committed
Add missing doc comments
1 parent a83f6d9 commit 03f5f8d

13 files changed

+42
-4
lines changed

libraries/bad_file_cleaner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
)
99

10+
// FailIfHasUndesiredFiles returns an error if the folder contains any undesired files.
1011
func FailIfHasUndesiredFiles(folder string) error {
1112
err := failIfContainsForbiddenFileInRoot(folder)
1213
if err != nil {
@@ -15,6 +16,7 @@ func FailIfHasUndesiredFiles(folder string) error {
1516
return failIfContainsExes(folder)
1617
}
1718

19+
// ForbiddenFiles is the names of the forbidden files.
1820
var ForbiddenFiles = []string{".development"}
1921

2022
func failIfContainsForbiddenFileInRoot(folder string) error {
@@ -27,6 +29,7 @@ func failIfContainsForbiddenFileInRoot(folder string) error {
2729
return nil
2830
}
2931

32+
// Patterns is the file patterns of executables.
3033
var Patterns = []string{"*.exe"}
3134

3235
func failIfContainsExes(folder string) error {

libraries/clamav.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func modifyEnv(env []string, key, value string) []string {
3131
return envMapToSlice(envMap)
3232
}
3333

34+
// RunAntiVirus scans the folder for viruses.
3435
func RunAntiVirus(folder string) ([]byte, error) {
3536
cmd := exec.Command("clamdscan", "-i", folder)
3637
cmd.Env = modifyEnv(os.Environ(), "LANG", "en")

libraries/cron/fill_missing_checksums.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
)
99

1010
/*
11-
Check for missing size and checksum field and fills them
12-
by downloading a copy of the file.
11+
FillMissingChecksumsForDownloadArchives checks for missing size and checksum field and fills them
12+
by downloading a copy of the file.
1313
*/
1414
func FillMissingChecksumsForDownloadArchives(URL string, filename string) (int64, string, error) {
1515
size, err := download(URL, filename)

libraries/db/db.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ type Dependency struct {
5555
Version string
5656
}
5757

58+
// New returns a new DB object.
5859
func New(libraryFile string) *DB {
5960
return &DB{libraryFile: libraryFile}
6061
}
6162

63+
// AddLibrary adds a library to the database.
6264
func (db *DB) AddLibrary(library *Library) error {
6365
db.mutex.Lock()
6466
defer db.mutex.Unlock()
@@ -70,6 +72,7 @@ func (db *DB) AddLibrary(library *Library) error {
7072
return nil
7173
}
7274

75+
// HasLibrary returns whether the database already contains the given library.
7376
func (db *DB) HasLibrary(libraryName string) bool {
7477
db.mutex.Lock()
7578
defer db.mutex.Unlock()
@@ -81,6 +84,7 @@ func (db *DB) hasLibrary(libraryName string) bool {
8184
return found != nil
8285
}
8386

87+
// FindLibrary returns the Library object for the given name.
8488
func (db *DB) FindLibrary(libraryName string) (*Library, error) {
8589
db.mutex.Lock()
8690
defer db.mutex.Unlock()
@@ -96,6 +100,7 @@ func (db *DB) findLibrary(libraryName string) (*Library, error) {
96100
return nil, errors.New("library not found")
97101
}
98102

103+
// AddRelease adds a library release to the database.
99104
func (db *DB) AddRelease(release *Release, repoURL string) error {
100105
db.mutex.Lock()
101106
defer db.mutex.Unlock()
@@ -120,6 +125,7 @@ func (db *DB) AddRelease(release *Release, repoURL string) error {
120125
return nil
121126
}
122127

128+
// HasReleaseByNameVersion returns whether the database contains a release for the given library and version number.
123129
func (db *DB) HasReleaseByNameVersion(libraryName string, libraryVersion string) bool {
124130
db.mutex.Lock()
125131
defer db.mutex.Unlock()
@@ -131,6 +137,7 @@ func (db *DB) hasReleaseByNameVersion(libraryName string, libraryVersion string)
131137
return found != nil
132138
}
133139

140+
// HasRelease returns whether the database already contains the given Release object.
134141
func (db *DB) HasRelease(release *Release) bool {
135142
db.mutex.Lock()
136143
defer db.mutex.Unlock()
@@ -141,6 +148,7 @@ func (db *DB) hasRelease(release *Release) bool {
141148
return db.hasReleaseByNameVersion(release.LibraryName, release.Version.String())
142149
}
143150

151+
// FindRelease returns the Release object from the database that matches the given object.
144152
func (db *DB) FindRelease(release *Release) (*Release, error) {
145153
db.mutex.Lock()
146154
defer db.mutex.Unlock()
@@ -156,6 +164,7 @@ func (db *DB) findReleaseByNameVersion(libraryName string, libraryVersion string
156164
return nil, errors.New("library not found")
157165
}
158166

167+
// LoadFromFile returns a DB object loaded from the given filename.
159168
func LoadFromFile(filename string) (*DB, error) {
160169
file, err := os.Open(filename)
161170
if err != nil {
@@ -170,6 +179,7 @@ func LoadFromFile(filename string) (*DB, error) {
170179
return db, nil
171180
}
172181

182+
// Load returns a DB object loaded from the given reader.
173183
func Load(r io.Reader) (*DB, error) {
174184
decoder := json.NewDecoder(r)
175185
db := new(DB)
@@ -180,6 +190,7 @@ func Load(r io.Reader) (*DB, error) {
180190
return db, nil
181191
}
182192

193+
// SaveToFile saves the database to a file.
183194
func (db *DB) SaveToFile() error {
184195
db.mutex.Lock()
185196
defer db.mutex.Unlock()
@@ -191,6 +202,7 @@ func (db *DB) SaveToFile() error {
191202
return db.save(file)
192203
}
193204

205+
// Save writes the database via the given writer.
194206
func (db *DB) Save(r io.Writer) error {
195207
db.mutex.Lock()
196208
defer db.mutex.Unlock()
@@ -222,6 +234,7 @@ func (db *DB) findLatestReleaseOfLibrary(lib *Library) (*Release, error) {
222234
return found, nil
223235
}
224236

237+
// FindReleasesOfLibrary returns the database's releases for the given Library object.
225238
func (db *DB) FindReleasesOfLibrary(lib *Library) []*Release {
226239
db.mutex.Lock()
227240
defer db.mutex.Unlock()
@@ -239,10 +252,12 @@ func (db *DB) findReleasesOfLibrary(lib *Library) []*Release {
239252
return releases
240253
}
241254

255+
// Commit saves the database to disk.
242256
func (db *DB) Commit() error {
243257
return db.SaveToFile()
244258
}
245259

260+
// Init loads a database from file and returns it.
246261
func Init(libraryFile string) *DB {
247262
libs, err := LoadFromFile(libraryFile)
248263
if err != nil {

libraries/db/versioning.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,34 @@ package db
22

33
import "encoding/json"
44

5+
// Version is the type for library versions.
56
type Version struct {
67
version string
78
}
89

10+
// Less returns whether the receiver version is lower than the argument.
911
func (version *Version) Less(other Version) (bool, error) {
1012
// TODO: apply semantic versioning
1113
return version.version < other.version, nil
1214
}
1315

16+
// String returns the version in string form.
1417
func (version *Version) String() string {
1518
return version.version
1619
}
1720

21+
// UnmarshalJSON parses the JSON-encoded argument and stores the result in the receiver.
1822
func (version *Version) UnmarshalJSON(data []byte) error {
1923
return json.Unmarshal(data, &version.version)
2024
}
2125

26+
// MarshalJSON returns the JSON encoding of the receiver.
2227
func (version *Version) MarshalJSON() ([]byte, error) {
2328
// Encode version as a string
2429
return json.Marshal(version.version)
2530
}
2631

32+
// VersionFromString parses a string to a Version object.
2733
func VersionFromString(str string) Version {
2834
return Version{version: str}
2935
}

libraries/file/SCCS.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package file
22

3+
// SCCSFiles is a map of folder names used internally by source code control systems.
34
var SCCSFiles = map[string]bool{
45
"CVS": true,
56
"RCS": true,
@@ -8,6 +9,7 @@ var SCCSFiles = map[string]bool{
89
".hg": true,
910
".bzr": true}
1011

12+
// IsSCCS returns whether the given string is a folder name used internally by source code control systems.
1113
func IsSCCS(name string) bool {
1214
return SCCSFiles[name]
1315
}

libraries/github_release_downloader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
)
1111

12+
// GithubDownloadRelease downloads GitHub's archive of the release.
1213
func GithubDownloadRelease(repoURL, version string) (string, int64, string, error) {
1314
tempfile, err := ioutil.TempFile("", "github")
1415
if err != nil {

libraries/hash/checksumhelper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"os"
88
)
99

10-
// Calculate hash for the file
10+
// Checksum calculates the hash for the file.
1111
func Checksum(filename string) (string, error) {
1212
hasher := sha256.New()
1313
file, err := os.Open(filename)

libraries/repoarchive.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"arduino.cc/repository/libraries/zip"
1010
)
1111

12+
// ZipRepo creates a ZIP archive of the repo folder and returns its path.
1213
func ZipRepo(repoFolder string, baseFolder string, zipFolderName string) (string, error) {
1314
err := os.MkdirAll(baseFolder, os.FileMode(0755))
1415
if err != nil {
@@ -23,6 +24,7 @@ func ZipRepo(repoFolder string, baseFolder string, zipFolderName string) (string
2324
return absoluteFileName, nil
2425
}
2526

27+
// ZipFolderName returns the name to use for the folder.
2628
func ZipFolderName(library *metadata.LibraryMetadata) string {
2729
pattern := regexp.MustCompile("[^a-zA-Z0-9]")
2830
return pattern.ReplaceAllString(library.Name, "_") + "-" + library.Version

libraries/repoclone.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Repository struct {
2222
URL string
2323
}
2424

25+
// CloneOrFetch returns a Repository object. If the repository is already present, it is opened. Otherwise, cloned.
2526
func CloneOrFetch(repoMeta *Repo, folderName string) (*Repository, error) {
2627
repo := Repository{
2728
FolderPath: folderName,
@@ -64,6 +65,7 @@ func CloneOrFetch(repoMeta *Repo, folderName string) (*Repository, error) {
6465
return &repo, err
6566
}
6667

68+
// GenerateLibraryFromRepo parses a repository and returns the library metadata.
6769
func GenerateLibraryFromRepo(repo *Repository) (*metadata.LibraryMetadata, error) {
6870
bytes, err := ioutil.ReadFile(filepath.Join(repo.FolderPath, "library.properties"))
6971
if err != nil {
@@ -88,6 +90,7 @@ func GenerateLibraryFromRepo(repo *Repository) (*metadata.LibraryMetadata, error
8890
return library, nil
8991
}
9092

93+
// UpdateLibrary adds a release to the library database.
9194
func UpdateLibrary(release *db.Release, repoURL string, libraryDb *db.DB) error {
9295
var err error
9396

libraries/repolist.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ func (_ repoMatcherIfGithub) Match(r string) bool {
6464
}
6565
*/
6666

67+
// GitURLsError is the type for the unknown or unsupported repositories data.
6768
type GitURLsError struct {
6869
Repos []*Repo
6970
}
7071

72+
// Repo is the type for the library repository data.
7173
type Repo struct {
7274
URL string
7375
Types []string
@@ -87,6 +89,7 @@ func (repo *Repo) AsFolder() (string, error) {
8789
return folderName, nil
8890
}
8991

92+
// ReposByURL is the type for the libraries repository data.
9093
type ReposByURL []*Repo
9194

9295
func (r ReposByURL) Len() int {
@@ -180,6 +183,7 @@ func toListOfUniqueRepos(repos []*Repo) []*Repo {
180183
return finalRepos
181184
}
182185

186+
// ListRepos loads a list from the given filename.
183187
func ListRepos(reposFilename string) ([]*Repo, error) {
184188
repos, err := loadRepoListFromFile(reposFilename)
185189
if err != nil {

libraries/zip/ziphelper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"arduino.cc/repository/libraries/file"
1111
)
1212

13-
// ZipDirectory creates a new zip archive that contains a copy of "rootFolder" into "zipFile".
13+
// Directory creates a new zip archive that contains a copy of "rootFolder" into "zipFile".
1414
// Inside the archive "rootFolder" will be renamed to "zipRootFolderName".
1515
func Directory(rootFolder string, zipRootFolderName string, zipFile string) error {
1616
checks := func(path string, info os.FileInfo, err error) error {

sync_libraries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/go-git/go-git/v5/plumbing"
1818
)
1919

20+
// Config is the type of the engine configuration.
2021
type Config struct {
2122
BaseDownloadURL string
2223
LibrariesFolder string

0 commit comments

Comments
 (0)