| | | 1 | | package fs |
| | | 2 | | |
| | | 3 | | import ( |
| | | 4 | | "io/fs" |
| | | 5 | | "os" |
| | | 6 | | "path/filepath" |
| | | 7 | | |
| | | 8 | | "github.com/jedi-knights/go-semantic-release/internal/ports" |
| | | 9 | | ) |
| | | 10 | | |
| | | 11 | | // Compile-time interface compliance check. |
| | | 12 | | var _ ports.FileSystem = (*OSFileSystem)(nil) |
| | | 13 | | |
| | | 14 | | // OSFileSystem implements ports.FileSystem using the real filesystem. |
| | | 15 | | type OSFileSystem struct{} |
| | | 16 | | |
| | | 17 | | // NewOSFileSystem creates a real filesystem adapter. |
| | 6 | 18 | | func NewOSFileSystem() *OSFileSystem { |
| | 6 | 19 | | return &OSFileSystem{} |
| | 6 | 20 | | } |
| | | 21 | | |
| | | 22 | | func (f *OSFileSystem) ReadFile(path string) ([]byte, error) { |
| | | 23 | | return os.ReadFile(path) |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | func (f *OSFileSystem) WriteFile(path string, data []byte, perm fs.FileMode) error { |
| | | 27 | | return os.WriteFile(path, data, perm) |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | func (f *OSFileSystem) Exists(path string) bool { |
| | | 31 | | _, err := os.Stat(path) |
| | | 32 | | return err == nil |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | func (f *OSFileSystem) Walk(root string, fn fs.WalkDirFunc) error { |
| | | 36 | | return filepath.WalkDir(root, fn) |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | func (f *OSFileSystem) Glob(pattern string) ([]string, error) { |
| | | 40 | | return filepath.Glob(pattern) |
| | | 41 | | } |