-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add FS store #25
Add FS store #25
Conversation
67a5d12
to
dacfd39
Compare
In golang, we put the test file in the same directory
Your implementation doesn't need to care whether it is an absolute path or a relative path but fyi I expect the fsPath will be an absolute path in the config file |
pkg/kv/fs.go
Outdated
defer s.lock.Unlock() | ||
|
||
path := fmt.Sprintf("%s/%s/%s", s.fsPath, ns, key) | ||
s.Touch(path) |
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.
According to https://pkg.go.dev/os#WriteFile, it will automatically create if necessary. You don't need to touch it.
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.
In my testing it will consistently throw no such file or directory
error if not Touch the path beforehand.
I think it might be related to this SO question about os.Create, excerpt:
... you need to ensure that the base directory exists, because os.Create does not handle it.
pkg/kv/fs.go
Outdated
if file, err := os.OpenFile(fpath, os.O_RDONLY|os.O_CREATE, 0644); err != nil { | ||
return err | ||
} else { | ||
return file.Close() | ||
} |
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.
- If all branches of the if-elseif-else are returning something, usually we don't write the else case because it will create too much indentation and make worse readability.
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.
- Golang people like multiple ifs and check err one by one
file, err := os.OpenFile(...)
if err != nil {
return err
}
err = file.Close()
if err != nil {
return err
}
return nil
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.
So strange, why not just return file.Close()
🤔 I will apply this change to os.WriteFile
call in Set
also
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.
readme.md
has conflicts 🤔
It would be best to also be able to automatically remove the fs directory produced by this test.
6ff247a
to
e9cc950
Compare
Will there be squash when merging (turn 6 commits into 1)? |
Refer issue #22
Two questions
fs_test.go
?fsPath/namespace/key
or./fsPath/namepsace/key
? -L 34;51