Skip to content

Commit 1abc0d0

Browse files
authored
add support for getting path to backend, where supported (#331)
Signed-off-by: Avi Deitcher <[email protected]>
1 parent 69d81d3 commit 1abc0d0

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

backend/file/file.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import (
1212

1313
type rawBackend struct {
1414
storage fs.File
15+
path string
1516
readOnly bool
1617
}
1718

18-
// Create a backend.Storage from provided fs.File
19+
// Create a backend.Storage from provided fs.File. Will not store any path.
1920
func New(f fs.File, readOnly bool) backend.Storage {
2021
return rawBackend{
2122
storage: f,
@@ -49,6 +50,7 @@ func OpenFromPath(pathName string, readOnly bool) (backend.Storage, error) {
4950
return rawBackend{
5051
storage: f,
5152
readOnly: readOnly,
53+
path: pathName,
5254
}, nil
5355
}
5456

@@ -74,6 +76,7 @@ func CreateFromPath(pathName string, size int64) (backend.Storage, error) {
7476
return rawBackend{
7577
storage: f,
7678
readOnly: false,
79+
path: pathName,
7780
}, nil
7881
}
7982

@@ -125,3 +128,7 @@ func (f rawBackend) Seek(offset int64, whence int) (int64, error) {
125128
}
126129
return -1, backend.ErrNotSuitable
127130
}
131+
132+
func (f rawBackend) Path() string {
133+
return f.path
134+
}

backend/interface.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ type Storage interface {
3030
Sys() (*os.File, error)
3131
// file for read-write operations
3232
Writable() (WritableFile, error)
33+
// Path returns the path to the underlying storage, if any; returns empty string if not applicable
34+
Path() string
3335
}

backend/substorage.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ type SubStorage struct {
1010
underlying Storage
1111
offset int64
1212
size int64
13+
path string
1314
}
1415

1516
func Sub(u Storage, offset, size int64) Storage {
1617
return SubStorage{
1718
underlying: u,
1819
offset: offset,
1920
size: size,
21+
path: u.Path(),
2022
}
2123
}
2224

@@ -76,6 +78,10 @@ func (s SubStorage) Writable() (WritableFile, error) {
7678
}, nil
7779
}
7880

81+
func (s SubStorage) Path() string {
82+
return s.path
83+
}
84+
7985
type subWritable struct {
8086
underlying WritableFile
8187
offset int64

0 commit comments

Comments
 (0)