-
Notifications
You must be signed in to change notification settings - Fork 518
Add RootStore #1282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add RootStore #1282
Conversation
Thank you for this PR! The usage of |
Both stores are incompatible and merging them into one would result in breaking changes, as the filestore allows for absolute path, which the rootstore by design cannot support. |
Would it be possible to offer an option in |
I don't think this is possible without breaking changes. The current interface of FileStore is |
We probably could share quite a bit of code though between both implementations. |
Good point. In that case, this might be something for the next major release, where we can introduce such changes. I'm quite hesitant to merge the PR as is because it duplicates a lot of code. |
Okay added another way: A |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates. This seems to be going in a good direction.
"os" | ||
) | ||
|
||
type osFS struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can osFS
be replaced by os.DirFS
(https://pkg.go.dev/os#DirFS)? Then we don't have to implement the interface on our own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. os.DirFS
returns a read-only fs.FS
, we need writing functions like Create
or Remove
.
|
||
// RootStore is a file based storage backend that uses the | ||
// os.Root type to safely store uploads. | ||
type RootStore struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we actually have to export a RootStore. If we expose a filestore that can work with any io/fs.FS
, then users just supply the corresponding file system interface for their root and use then. Makes it more flexible and less generalized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something along these lines, which is similar to what you have proposed in this PR already:
struct FSStore {
FS fs.FS
}
// Implementation of FSStore function omitted.
struct FileStore {
Dir string
}
func (store FileStore) fsStore() FSStore {
return FSStore{os.DirFS(store.Dir)}
}
func (store FileStore) NewUpload(ctx context.Context, info handler.FileInfo) (handler.Upload, error) {
return store.fsStore().NewUpload(ctx, info)
}
Just noticed another minor (?) breaking change: Changing the the |
Add a new
RootStore
DataStore
that uses theos.Root
type introduced in Go 1.24.This type ensures that all files accessed are only in the directory passed and protects against path traversal attacks.
Read more abount
os.Root
here: https://go.dev/blog/osroot