Delete temporary packfile in indexer by lhchavez · Pull Request #4060 · libgit2/libgit2 · GitHub
Skip to content

Delete temporary packfile in indexer#4060

Merged
ethomson merged 5 commits into
libgit2:masterfrom
lhchavez:fix-indexer-tmp-pack
Jan 21, 2017
Merged

Delete temporary packfile in indexer#4060
ethomson merged 5 commits into
libgit2:masterfrom
lhchavez:fix-indexer-tmp-pack

Conversation

@lhchavez

@lhchavez lhchavez commented Jan 1, 2017

Copy link
Copy Markdown
Contributor

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

carlosmn commented Jan 2, 2017

Copy link
Copy Markdown
Member

@lhchavez

lhchavez commented Jan 2, 2017

Copy link
Copy Markdown
Contributor Author

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

lhchavez commented Jan 2, 2017

Copy link
Copy Markdown
Contributor Author

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

lhchavez commented Jan 4, 2017

Copy link
Copy Markdown
Contributor Author

now the tests actually pass -_-. PTAL.

@ethomson ethomson left a comment

Copy link
Copy Markdown
Member

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!

Comment thread src/indexer.c Outdated
if (fd != -1)
p_close(fd);

if (git_buf_is_allocated(&tmp_path))

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/indexer.c Outdated
p_close(fd);

if (git_buf_is_allocated(&tmp_path))
(void)p_unlink(git_buf_cstr(&tmp_path));

Copy link
Copy Markdown
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
Copy Markdown
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).

Comment thread tests/pack/indexer.c Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread tests/pack/indexer.c Outdated
cl_warning(git_buf_cstr(&first_tmp_file));
git_buf_free(&first_tmp_file);
cl_fail("Found a temporary file");
}

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

@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