daemon: Sort extended attributes when returning them.

A single file can have multiple xattrs.  Previously these were
returned in the same order as the kernel returns them.  However it is
more useful if they are sorted by attribute name.
This commit is contained in:
Richard W.M. Jones
2013-12-17 19:32:42 +00:00
parent 937ea7f16f
commit c7a2dce607

View File

@@ -113,6 +113,15 @@ do_lremovexattr (const char *xattr, const char *path)
#endif
}
static int
compare_xattrs (const void *vxa1, const void *vxa2)
{
const guestfs_int_xattr *xa1 = vxa1;
const guestfs_int_xattr *xa2 = vxa2;
return strcmp (xa1->attrname, xa2->attrname);
}
static guestfs_int_xattr_list *
getxattrs (const char *path,
ssize_t (*listxattr) (const char *path, char *list, size_t size),
@@ -202,6 +211,12 @@ getxattrs (const char *path,
}
}
/* Sort the entries by attrname. */
qsort (&r->guestfs_int_xattr_list_val[0],
(size_t) r->guestfs_int_xattr_list_len,
sizeof (guestfs_int_xattr),
compare_xattrs);
return r;
error:
@@ -409,6 +424,9 @@ do_internal_lxattrlist (const char *path, char *const *names)
reply_with_perror ("strdup");
goto error;
}
/* Sort the entries by attrname (only for this single file). */
qsort (&entry[1], nr_attrs, sizeof (guestfs_int_xattr), compare_xattrs);
}
return ret;