-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
Consolidate fileutil functions in a package #1457
Conversation
@manish-sethi I know that we had agreed to
Can we please move There are 42 famous golang projects (https://github.com/golang-standards/project-layout/tree/master/pkg) which heavily use |
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.
Thanks Manish, a couple of minor nits
I would surely prefer having these kind of util stuff at a common place. As of now, we have it all scattered. /pkg sounds good home for these kind of stuff to me. There are more than one reference projects that have it like this.
However, I would like to hear if @sykesm is in agreement with this or his preference is to keep in |
@manish-sethi As per Golang-standard repo, only 6 famous projects use On the name, I prefer |
Packages with an
True or not, it's not particularly relevant. The location of the code should reflect the scope and the intent.
This is not how we should be thinking of the Fabric repository. If the value of Fabric is that we offer file management utilities, or logging utilities, or certificate management utilities, we've failed. We also don't do proper versioning or dependency management of our code; we barely manage that for the packages we actually pulled out to be consumed as libraries.
As to the question: I don't believe 'internal' is the right location for this. Moving it to a |
I am aware of this. While it make sense to restrict say some ledger sub-packages being imported into other layer (for e.g., we import Keeping code in Why only 6 projects use Another simple approach is to keep everything inside |
The purpose of |
I'd really like to avoid getting dragged into a debate on this. I spent a great deal of time and energy in 2018 trying to get others to detangle the code base into proper packages that were easier to reason about and more loosely coupled. While I'm happy to see some of that happening now, I've lost the passion. Based on convention, things in If we think that If we think it's a shared bit of code to consolidate what we do, it belongs in Moving something out of So, you wrote the package. Is this something internal or something for others? Which consumer did you have in mind? Are we committing to make changes that are strictly backward compatible? Those questions should inform your answer. |
Thanks for the detailed explanation @sykesm I stand corrected. Understood the reasoning. Make sense. I agree that keeping stuff in Going forward, we will use this rule for all new packages and old packages present within the |
Thanks @sykesm. I agree on |
ac0bf1f
to
ea7c2cd
Compare
Signed-off-by: manish <[email protected]>
+1 It would be really good if we do this. Otherwise, we are continuously adding things to the existing bad pattern. |
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.
LGTM. Just a minor comment.
if err := os.Rename(tempFilePath, finalFilePath); 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.
Shouldn't we do syncDir(dir)
here after the rename? -- https://www.slideshare.net/nan1nan1/eat-my-data
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 left it to the user to call this explicitly. As I do here.
If we do implicit here then it would be better to do in this function as well, in order to maintain a uniform behavior but the latter function may sometime not need it based on the context. So, I decided to leave up to the consumer to explicitly invoke it - So, does the function name convey. Atomicity and durability are two different dimensions. syncDir is more for the durability.
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.
Thanks, Manish, for the offline discussion. https://man7.org/linux/man-pages/man2/fsync.2.html clarified some details for me. So both APIs ensures that the data is written to the disk and sync of parent directory is left to the caller.
if err := os.MkdirAll(dirPath, 0755); err != nil { | ||
return false, errors.Wrapf(err, "error while creating dir: %s", dirPath) | ||
} | ||
if err := SyncParentDir(dirPath); err != 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.
Out of curiosity, do we only need to sync the direct parent of the directory created? What if the MkdirAll
on line 78 needs to create multiple folders in the 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.
Yes @caod123 - you are right, this should be on all new folders in the path. I copied this function from existing one where assumption was that up to parent it exists. But better to fix this here. I'll fix this in a separate PR after this.
Signed-off-by: manish [email protected]
Type of change
Description
Consolidate fileutil functions in a package
Additional details
There were some file util functions in a
common/ledger/util
package and some more functions were added to bothcommon/ledger
andcore/ledger
. This PR consolidates all these functions incommon/ledger/fileutil
package.