repo: Port uncompressed cache GC to libglnx

- Kills a user of `gs_file_unlink`
 - Is fd-relative
 - Is way less malloc-y.

Closes: #312
Approved by: giuseppe
This commit is contained in:
Colin Walters 2016-05-29 13:29:18 -04:00 committed by Atomic Bot
parent 33047d5d4f
commit 9d39d3af85
1 changed files with 22 additions and 24 deletions

View File

@ -957,38 +957,36 @@ ostree_repo_checkout_gc (OstreeRepo *self,
g_hash_table_iter_init (&iter, to_clean_dirs); g_hash_table_iter_init (&iter, to_clean_dirs);
while (to_clean_dirs && g_hash_table_iter_next (&iter, &key, &value)) while (to_clean_dirs && g_hash_table_iter_next (&iter, &key, &value))
{ {
g_autoptr(GFile) objdir = NULL; g_autofree char *objdir_name = g_strdup_printf ("%02x", GPOINTER_TO_UINT (key));
g_autoptr(GFileEnumerator) enumerator = NULL; g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
g_autofree char *objdir_name = NULL;
objdir_name = g_strdup_printf ("%02x", GPOINTER_TO_UINT (key)); if (!glnx_dirfd_iterator_init_at (self->uncompressed_objects_dir_fd, objdir_name, FALSE,
objdir = g_file_get_child (self->uncompressed_objects_dir, objdir_name); &dfd_iter, error))
enumerator = g_file_enumerate_children (objdir, "standard::name,standard::type,unix::inode,unix::nlink",
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
cancellable,
error);
if (!enumerator)
goto out; goto out;
while (TRUE) while (TRUE)
{ {
GFileInfo *file_info; struct dirent *dent;
guint32 nlinks; struct stat stbuf;
if (!gs_file_enumerator_iterate (enumerator, &file_info, NULL, if (!glnx_dirfd_iterator_next_dent (&dfd_iter, &dent, cancellable, error))
cancellable, error))
goto out; goto out;
if (file_info == NULL) if (dent == NULL)
break; break;
nlinks = g_file_info_get_attribute_uint32 (file_info, "unix::nlink"); if (fstatat (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW) != 0)
if (nlinks == 1)
{ {
g_autoptr(GFile) objpath = NULL; glnx_set_error_from_errno (error);
objpath = g_file_get_child (objdir, g_file_info_get_name (file_info)); goto out;
if (!gs_file_unlink (objpath, cancellable, error)) }
goto out;
if (stbuf.st_nlink == 1)
{
if (unlinkat (dfd_iter.fd, dent->d_name, 0) != 0)
{
glnx_set_error_from_errno (error);
goto out;
}
} }
} }
} }