-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
This change deletes the temporary packfile that the indexer creates to avoid littering the pack/ directory with garbage.
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. |
in |
Now with a test that actually fails if I remove the check in |
I forgot that Windows chokes while trying to delete open files.
now the tests actually pass -_-. PTAL. |
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.
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)) |
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.
git_buf_len(&tmp_path)
is correct here.
is_allocated
literally looks at whether we have malloc
ed 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.
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.
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)); |
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.
We do not cast unused return values to void
. There are a few other places in here that should be removed also.
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.
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)) { |
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.
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.
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.
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.
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.
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"); | ||
} |
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.
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.)
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.
Done
I added a quick check before doing the |
This change deletes the temporary packfile that the indexer creates to
avoid littering the pack/ directory with garbage.