-
Notifications
You must be signed in to change notification settings - Fork 47
osfs: add file.Sync()
support
#126
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,10 @@ func (*FileMock) Stat() (fs.FileInfo, error) { | |
return nil, nil | ||
} | ||
|
||
func (*FileMock) Sync() error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test to confirm Sync is being called. |
||
return nil | ||
} | ||
|
||
func (*FileMock) Truncate(_ int64) error { | ||
return nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,11 @@ func (f *file) Unlock() error { | |
return nil | ||
} | ||
|
||
// Sync is a no-op in memfs. | ||
func (f *file) Sync() error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid LSP violations, we don't implement the Sync on any structure that does not really support it. |
||
return nil | ||
} | ||
|
||
type fileInfo struct { | ||
name string | ||
size int | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -116,6 +116,10 @@ func WriteFile(fs billy.Basic, filename string, data []byte, perm fs.FileMode) ( | |||||||
if err == nil && n < len(data) { | ||||||||
err = io.ErrShortWrite | ||||||||
} | ||||||||
err = f.Sync() | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should call Sync for implementations that support it:
Suggested change
|
||||||||
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.
Instead of expanding the existing interface, let's create a new interface for this:
type Syncer interface {
Sync() error
}