overlay @main -
refs -
log -
-
https://git.jolheiser.com/overlay.git
Overlay FS
Add ReadFile, interface guard, and drone CI (#2)
Reviewed-on: https://git.jojodev.com/jolheiser/overlay/pulls/2
Co-authored-by: jolheiser <john.olheiser@gmail.com>
Co-committed-by: jolheiser <john.olheiser@gmail.com>
4 changed files, 42 additions(+), 2 deletions(-)
diff --git a/.drone.yml b/.drone.yml
new file mode 100644
index 0000000000000000000000000000000000000000..7d4d6317270968bd853fc5bff381f4d7fa90b986
--- /dev/null
+++ b/.drone.yml
@@ -0,0 +1,17 @@
+---
+kind: pipeline
+name: compliance
+trigger:
+ event:
+ - pull_request
+steps:
+ - name: build
+ pull: always
+ image: golang:1.16
+ commands:
+ - make test
+ - name: check
+ pull: always
+ image: golang:1.16
+ commands:
+ - make vet
\ No newline at end of file
diff --git a/README.md b/README.md
index 2f32c46f2b5a669669b08efc6e6a4d84fbcad2a6..4f0db5a95038aa5b8f58cec3b0c80bce1bcccf0a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,7 @@
# Overlay
+
+[![Build Status](https://ci.jojodev.com/api/badges/jolheiser/overlay/status.svg?ref=refs/heads/main)](https://ci.jojodev.com/jolheiser/overlay)
+
Overlay File System
Overlay is an easy way to implement a file system in such a way that
diff --git a/overlay.go b/overlay.go
index 8dab55d4f2bfc65b08fb7b47be9f2b02bffbca84..512bf1c77ece17e9cc8deba0777e8c8ea60d8e10 100644
--- a/overlay.go
+++ b/overlay.go
@@ -6,6 +6,10 @@ "os"
"path"
)
+// Interface guard
+// fs.ReadFileFS also fulfills fs.FS
+var _ fs.ReadFileFS = (*FS)(nil)
+
// FS is an overlay File System
type FS struct {
fs fs.FS
@@ -39,6 +43,14 @@ }
return f.fs.Open(name)
}
+// ReadFile reads a file, preferring disk
+func (f *FS) ReadFile(name string) ([]byte, error) {
+ if f.exists(name) {
+ return os.ReadFile(f.apn(name))
+ }
+ return fs.ReadFile(f.fs, name)
+}
+
// ReadDir reads []fs.DirEntry
// This method will prefer EMBEDDED, because that is the "real" FS for overlay
func (f *FS) ReadDir(name string) ([]fs.DirEntry, error) {
@@ -64,6 +76,15 @@ }
}
return x, nil
+}
+
+// MustNew returns New and panics on error
+func MustNew(root string, fs fs.FS, opts ...Option) *FS {
+ f, err := New(root, fs, opts...)
+ if err != nil {
+ panic(err)
+ }
+ return f
}
// WithSub sets a fs.Sub for an FS
diff --git a/overlay_test.go b/overlay_test.go
index 07ec8d203d4ec7feb418e99987c7f6938d9820e8..80ce9189c6af47c7ba0ebf5414a700ecc83bacc6 100644
--- a/overlay_test.go
+++ b/overlay_test.go
@@ -2,7 +2,6 @@ package overlay
import (
"embed"
- "io"
"io/fs"
"os"
"strings"
@@ -49,7 +48,7 @@ t.FailNow()
}
defer fi.Close()
- contents, err := io.ReadAll(fi)
+ contents, err := x.ReadFile(tc.File)
if err != nil {
t.Log(err)
t.FailNow()