Skip to content
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

Merged
merged 4 commits into from
Oct 11, 2020
Merged

add copy to adapter #797

merged 4 commits into from
Oct 11, 2020

Conversation

guy-har
Copy link
Contributor

@guy-har guy-har commented Oct 11, 2020

No description provided.

@codecov-io
Copy link

codecov-io commented Oct 11, 2020

Codecov Report

Merging #797 into master will decrease coverage by 0.46%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
block/adapter.go 0.00% <ø> (ø)
block/gs/adapter.go 0.00% <0.00%> (ø)
block/local/adapter.go 5.71% <0.00%> (-0.74%) ⬇️
block/s3/adapter.go 0.00% <0.00%> (ø)
catalog/cataloger_create_entry.go 94.73% <0.00%> (-5.27%) ⬇️
api/handler.go

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f8824d...a938576. Read the comment docs.

@guy-har guy-har requested a review from arielshaqed October 11, 2020 13:43
Copy link
Contributor

@arielshaqed arielshaqed left a 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 ObjectPointers 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
Copy link
Contributor

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 ObjectPointers? Otherwise how do we handle namespaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are ObjectPointers

Copy link
Contributor

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/gs/adapter.go Outdated Show resolved Hide resolved
_ = destinationFile.Close()
}()
source := l.getPath(sourceObj.Identifier)
sourceFile, err := os.OpenFile(source, os.O_RDONLY, 0755)
Copy link
Contributor

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.)

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This ignores errors.
  2. 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.

Copy link
Contributor

@arielshaqed arielshaqed left a 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
Copy link
Contributor

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.

guy-har and others added 3 commits October 11, 2020 17:19
Co-authored-by: arielshaqed <ariels@treeverse.io>
change order between create and open in local/adapter
@guy-har guy-har merged commit 4b38e9d into master Oct 11, 2020
@guy-har guy-har deleted the feature/adapter-copy branch October 11, 2020 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants