-
Notifications
You must be signed in to change notification settings - Fork 259
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
sysfs: reopening file doesn't update fd #2319
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2dfadcb
Issue #2318.
ncruces 9624e9d
Docs.
ncruces c4d684a
Unused interface.
ncruces 15a0dc1
Check same file.
ncruces 063b70f
Docs.
ncruces 9b288f7
More.
ncruces 81f140e
Never truncate.
ncruces 01d7431
Only reopen dirs.
ncruces File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,13 +87,10 @@ func (f *osFile) SetAppend(enable bool) (errno experimentalsys.Errno) { | |
f.flag &= ^(experimentalsys.O_CREAT | experimentalsys.O_TRUNC) | ||
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. Don't needlessly update the file/flags. |
||
|
||
// appendMode (bool) cannot be changed later, so we have to re-open the | ||
// file. https://github.com/golang/go/blob/go1.20/src/os/file_unix.go#L60 | ||
// file. https://github.com/golang/go/blob/go1.23/src/os/file_unix.go#L60 | ||
return fileError(f, f.closed, f.reopen()) | ||
} | ||
|
||
// compile-time check to ensure osFile.reopen implements reopenFile. | ||
var _ reopenFile = (*osFile)(nil).reopen | ||
|
||
func (f *osFile) reopen() (errno experimentalsys.Errno) { | ||
// Clear any create flag, as we are re-opening, not re-creating. | ||
f.flag &= ^experimentalsys.O_CREAT | ||
|
@@ -116,11 +113,17 @@ func (f *osFile) reopen() (errno experimentalsys.Errno) { | |
} | ||
} | ||
|
||
_ = f.close() | ||
f.file, errno = OpenFile(f.path, f.flag, f.perm) | ||
file, errno := OpenFile(f.path, f.flag, f.perm) | ||
if errno != 0 { | ||
return errno | ||
} | ||
errno = f.checkSameFile(file) | ||
if errno != 0 { | ||
return errno | ||
} | ||
_ = f.close() | ||
f.file = file | ||
f.fd = file.Fd() | ||
|
||
if !isDir { | ||
_, err = f.file.Seek(offset, io.SeekStart) | ||
|
@@ -132,6 +135,21 @@ func (f *osFile) reopen() (errno experimentalsys.Errno) { | |
return 0 | ||
} | ||
|
||
func (f *osFile) checkSameFile(osf *os.File) experimentalsys.Errno { | ||
fi1, err := f.file.Stat() | ||
if err != nil { | ||
return experimentalsys.UnwrapOSError(err) | ||
} | ||
fi2, err := osf.Stat() | ||
if err != nil { | ||
return experimentalsys.UnwrapOSError(err) | ||
} | ||
if os.SameFile(fi1, fi2) { | ||
return 0 | ||
} | ||
return experimentalsys.ENOENT | ||
} | ||
|
||
// IsNonblock implements the same method as documented on fsapi.File | ||
func (f *osFile) IsNonblock() bool { | ||
return isNonblock(f) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This wasn't being used anywhere. The compile time check is not very useful, tbh.