-
Notifications
You must be signed in to change notification settings - Fork 362
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 copy to adapter #797
add copy to adapter #797
Conversation
Codecov Report
@@ Coverage Diff @@
## master #797 +/- ##
==========================================
- Coverage 42.08% 41.62% -0.47%
==========================================
Files 134 133 -1
Lines 10434 10384 -50
==========================================
- Hits 4391 4322 -69
- Misses 5461 5483 +22
+ Partials 582 579 -3
Continue to review full report at Codecov.
|
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.
Cool, thanks!
We do need to test this, understandably such integration testing is not part of this PR. So please do open an issue to do that.
The only required change is to pass ObjectPointer
s in the adapter interface, just like all other methods do. That also means getting rid of the icky resolve
calls in the adapter I think.
@@ -56,6 +56,7 @@ type Adapter interface { | |||
GetRange(obj ObjectPointer, startPosition int64, endPosition int64) (io.ReadCloser, error) | |||
GetProperties(obj ObjectPointer) (Properties, error) | |||
Remove(obj ObjectPointer) error | |||
Copy(sourceObj, destinationObj ObjectPointer) error |
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.
Don't these need to be ObjectPointer
s? Otherwise how do we handle namespaces?
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.
They are ObjectPointer
s
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.
Aaah, evidently I can copy but I cannot read.
block/local/adapter.go
Outdated
_ = destinationFile.Close() | ||
}() | ||
source := l.getPath(sourceObj.Identifier) | ||
sourceFile, err := os.OpenFile(source, os.O_RDONLY, 0755) |
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.
Why not os.Open
? (You anyway pass weird permissions, that are then ignored.)
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.
👍
@@ -93,6 +93,27 @@ func (l *Adapter) Remove(obj block.ObjectPointer) error { | |||
return os.Remove(p) | |||
} | |||
|
|||
func (l *Adapter) Copy(sourceObj, destinationObj block.ObjectPointer) error { | |||
dest := l.getPath(destinationObj.Identifier) | |||
destinationFile, err := os.Create(dest) |
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.
Create after opening the source - opening the source is a cheaper operation.
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.
changed it, Thanks
return err | ||
} | ||
defer func() { | ||
_ = destinationFile.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.
- This ignores errors.
- This leaves a bad (empty) file when the copy fails (or even if the source cannot be opened, because of create-before-open above). It should instead delete 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.
Yikes, sorry!
Please see other change requests, nothing there is in any way blocking.
@@ -56,6 +56,7 @@ type Adapter interface { | |||
GetRange(obj ObjectPointer, startPosition int64, endPosition int64) (io.ReadCloser, error) | |||
GetProperties(obj ObjectPointer) (Properties, error) | |||
Remove(obj ObjectPointer) error | |||
Copy(sourceObj, destinationObj ObjectPointer) error |
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.
Aaah, evidently I can copy but I cannot read.
Co-authored-by: arielshaqed <ariels@treeverse.io>
change order between create and open in local/adapter
No description provided.