File: fsutil.go

package info (click to toggle)
golang-github-theupdateframework-go-tuf 0.5.2-5~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 7,596 kB
  • sloc: python: 163; sh: 37; makefile: 12
file content (23 lines) | stat: -rw-r--r-- 527 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Package fsutil defiens a set of internal utility functions used to
// interact with the file system.
package fsutil

import (
	"fmt"
	"os"
	"path/filepath"
)

// IsMetaFile tests wheter a DirEntry appears to be a metadata file or not.
func IsMetaFile(e os.DirEntry) (bool, error) {
	if e.IsDir() || filepath.Ext(e.Name()) != ".json" {
		return false, nil
	}

	info, err := e.Info()
	if err != nil {
		return false, fmt.Errorf("error retrieving FileInfo for %s: %w", e.Name(), err)
	}

	return info.Mode().IsRegular(), nil
}