-
Notifications
You must be signed in to change notification settings - Fork 45
Conversation
Implement Seek() as required by io.Seeker() interface specification. As there is no predefined interface that implements both Read(), Write(), Seek() and Close(), return *nfs.File from Open() and OpenFile() calls instead of io.* interfaces. So now nfs.File implements even more interfaces, including io.ReadSeeker(), io.ReadWriteCloser() and so on.
nfs/file.go
Outdated
switch whence { | ||
case io.SeekStart: | ||
if offset < 0 { | ||
return int64(f.curr), fmt.Errorf("offset cannot be negative") |
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 you use errors.New
instead?
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.
OK, I will!
nfs/file.go
Outdated
f.curr = uint64(int64(f.curr) + offset) | ||
return int64(f.curr), nil | ||
case io.SeekEnd: | ||
return int64(f.curr), fmt.Errorf("SeekEnd is not supported yet") |
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.
Same comment. errors.New()
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.
Done
Well, before submitting the updated version of the patch I have to go through approval process for VMWare CLA, as I'm submitting this as Google employee and Google doesn't allow signing CLAs that are not approved yet. I'll get back to you shortly. |
I got an approval from Google to sign VMWare CLA. As soon as VMWare receives all required information from Google we can proceed with this pull request! |
CLA thing is sorted out! |
nfs/file.go
Outdated
return int64(f.curr), errors.New("SeekEnd is not supported yet") | ||
default: | ||
// This indicates serious programming error | ||
panic("Invalid whence") |
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 am thinking that panic might be heavy handed here? My main concern is people using this as a client may be surprised if it causes an unhandled panic unexpectedly.
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 cannot imagine situation other than developer's mistake that could lead to "whence" values being something else than those three values (since this is more something you get from outside). But no problem, I'll update the code to just return an error instead.
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.
Sorry, I meant "not something" of course...
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.
Done!
Thanks this looks great!!! |
Implement Seek() as required by io.Seeker() interface specification.
As there is no predefined interface that implements both Read(), Write(),
Seek() and Close(), return nfs.File from Open() and OpenFile() calls
instead of io. interfaces.
So now nfs.File implements even more interfaces, including io.ReadSeeker(), io.ReadWriteCloser()
and so on.