Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Delete temporary packfile in indexer #4060

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

Merged
merged 5 commits into from
Jan 21, 2017

Conversation

lhchavez
Copy link
Contributor

@lhchavez lhchavez commented Jan 1, 2017

This change deletes the temporary packfile that the indexer creates to
avoid littering the pack/ directory with garbage.

This change deletes the temporary packfile that the indexer creates to
avoid littering the pack/ directory with garbage.
@carlosmn
Copy link
Member

carlosmn commented Jan 2, 2017

What errors are you seeing that cause this function to fail? It should be exceedingly rare that anything in this function fails and the most likely culprit would be the creation of this file itself.

@lhchavez
Copy link
Contributor Author

lhchavez commented Jan 2, 2017

in git_indexer_new? nothing I can think of, it's just there for correctness, but I can remove it if needed. git_indexer_free will always leak the file if it git_indexer_commit was not called before (say, because you were writing a validator for a pack that was uploaded, and although the packfile was correct, the commit itself would fail validation).

@lhchavez
Copy link
Contributor Author

lhchavez commented Jan 2, 2017

Now with a test that actually fails if I remove the check in git_indexer_commit. PTAL!

I forgot that Windows chokes while trying to delete open files.
@lhchavez
Copy link
Contributor Author

lhchavez commented Jan 4, 2017

now the tests actually pass -_-. PTAL.

Copy link
Member

@ethomson ethomson left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this - I have some stylistic comments, but on the whole it looks good! Thanks!

@@ -151,6 +151,12 @@ int git_indexer_new(
if (fd != -1)
p_close(fd);

if (git_buf_is_allocated(&tmp_path))
Copy link
Member

Choose a reason for hiding this comment

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

git_buf_len(&tmp_path) is correct here.

is_allocated literally looks at whether we have malloced the structure, not whether it has contents. These are orthogonal concepts: the buffer may point to static memory and thus be nonempty but not allocated, similarly, we could allocate a buffer, set contents into it, then clear the contents, but it would still be allocated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -151,6 +151,12 @@ int git_indexer_new(
if (fd != -1)
p_close(fd);

if (git_buf_is_allocated(&tmp_path))
(void)p_unlink(git_buf_cstr(&tmp_path));
Copy link
Member

Choose a reason for hiding this comment

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

We do not cast unused return values to void. There are a few other places in here that should be removed also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (saw this was used inconsistently in a few other places).

cl_git_pass(git_buf_sets(&path, clar_sandbox_path()));
cl_git_pass(find_tmp_file_recurs(&first_tmp_file, &path));
git_buf_free(&path);
if (git_buf_is_allocated(&first_tmp_file)) {
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't cl_skip here. Do you expect temp files might exist? Then please don't skip the test, fix it. If not, assert that they don't so that we fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i expect they shouldn't exist (and currently don't), but cannot make that guarantee currently (I opened #4066 for that).

If we are cool with this test failing when other tests leak files, i can change the skip to a warning to make it clear that it wasn't this test that caused the failure, but another one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After a second thought, if this fails, it is obvious from the comment in L154 that it's not this test's fault, so changed it to simple assert with no log after all.

cl_warning(git_buf_cstr(&first_tmp_file));
git_buf_free(&first_tmp_file);
cl_fail("Found a temporary file");
}
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to free things on failures, we don't bother testing for memory leaks if it doesn't even work. This 5 lines can be more easily rewritten as:

cl_assert(git_buf_len(&first_tmp_file) > 0)
git_buf_free(&first_tmp_file);

(Which, I think, is probably what the test above should look like.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@ethomson ethomson merged commit f5586f5 into libgit2:master Jan 21, 2017
@ethomson
Copy link
Member

I added a quick check before doing the unlink to avoid calling it when we have already moved the file into place. I merged this manually; thanks again for fixing this!

@lhchavez lhchavez deleted the fix-indexer-tmp-pack branch January 21, 2017 20:52
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