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 LFS object verification step after upload #2868

Merged
merged 6 commits into from
Nov 8, 2017

Conversation

lafriks
Copy link
Member

@lafriks lafriks commented Nov 6, 2017

As per recommendation - #2112 (comment)

@lafriks lafriks added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Nov 6, 2017
@lafriks lafriks added this to the 1.3.0 milestone Nov 6, 2017
@codecov-io
Copy link

codecov-io commented Nov 6, 2017

Codecov Report

Merging #2868 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2868   +/-   ##
=======================================
  Coverage   26.85%   26.85%           
=======================================
  Files          89       89           
  Lines       17607    17607           
=======================================
  Hits         4728     4728           
  Misses      12193    12193           
  Partials      686      686

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 61f5c22...a648338. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 6, 2017
// Verify returns true if the object exists in the content store and size is correct.
func (s *ContentStore) Verify(meta *models.LFSMetaObject) bool {
path := filepath.Join(s.BasePath, transformKey(meta.Oid))
if fi, err := os.Stat(path); os.IsNotExist(err) || fi.Size() != meta.Size {
Copy link
Member

Choose a reason for hiding this comment

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

What if err is not nil, but is something other than a IsNotExist error. I think we should return false in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

@erhankoenig I did not want to change that as that is current behaviour also for exists method

Copy link
Member

Choose a reason for hiding this comment

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

But if err is not nil, it could be the case that fi is nil. In that case, fi.Size() will result in a nil-pointer dereference, so I think we need to check if err is nil or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's true but I don't know if in such case we should return false

@@ -69,6 +69,11 @@ func (v *RequestVars) ObjectLink() string {
return fmt.Sprintf("%s%s/%s/info/lfs/objects/%s", setting.AppURL, v.User, v.Repo, v.Oid)
}

// VerifyLink builds a URL for verifying the object.
func (v *RequestVars) VerifyLink() string {
return fmt.Sprintf("%s%s/%s/info/lfs/verify", setting.AppURL, v.User, v.Repo)
Copy link
Member

Choose a reason for hiding this comment

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

nit: use URLJoin. The current code assumes setting.AppURL has a trailing slash, and even if that assumption always holds (for now), it'd be nicer to not have to assume it in the first place.

@@ -320,6 +325,35 @@ func PutHandler(ctx *context.Context) {
logRequest(ctx.Req, 200)
}

// VerifyHandler verify oid and it's size from the content store
Copy link
Member

Choose a reason for hiding this comment

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

nit: it's -> its

@lafriks
Copy link
Member Author

lafriks commented Nov 7, 2017

@ethantkoenig fixed

@@ -66,7 +68,12 @@ type ObjectError struct {

// ObjectLink builds a URL linking to the object.
func (v *RequestVars) ObjectLink() string {
return fmt.Sprintf("%s%s/%s/info/lfs/objects/%s", setting.AppURL, v.User, v.Repo, v.Oid)
return path.Join(setting.AppURL, v.User, v.Repo, "info/lfs/objects", v.Oid)
Copy link
Member

@ethantkoenig ethantkoenig Nov 7, 2017

Choose a reason for hiding this comment

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

You can't call path.Join on URLs (example)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, sorry thought AppURL was url without domain, you are right. I'll fix that

@lafriks
Copy link
Member Author

lafriks commented Nov 7, 2017

@ethantkoenig now it's fixed

@@ -320,6 +327,35 @@ func PutHandler(ctx *context.Context) {
logRequest(ctx.Req, 200)
}

// VerifyHandler verify oid and its size from the content store
func VerifyHandler(ctx *context.Context) {

Copy link
Member

Choose a reason for hiding this comment

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

please remove blank line.

@ethantkoenig
Copy link
Member

It still seems wrong to me that verification can succeed if os.Stat(path) returns an error, but that can be fixed in another PR (for both Exist(..) and Verfiy(..)) so LGTM.

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Nov 7, 2017
@lafriks
Copy link
Member Author

lafriks commented Nov 7, 2017

@ethantkoenig I agree but there should probably needs to be bigger rewrite to return (bool, error) and handle that in caller functions but that is out of scope for this PR

@lafriks
Copy link
Member Author

lafriks commented Nov 7, 2017

@lunny fixed

@lunny
Copy link
Member

lunny commented Nov 8, 2017

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Nov 8, 2017
@lafriks
Copy link
Member Author

lafriks commented Nov 8, 2017

@ethantkoenig fixed error handling for verify function

@lafriks lafriks merged commit ba2e024 into go-gitea:master Nov 8, 2017
@lafriks lafriks deleted the feat/lfs_upload_verification branch November 8, 2017 13:05
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants