Add caller-defined xattr handling features to private libarchive.

This commit is contained in:
Moinak Ghosh 2014-09-11 19:17:02 +05:30
parent 9ecbbbafd0
commit 08a30d270d
2 changed files with 61 additions and 0 deletions

View file

@ -498,6 +498,15 @@ __LA_DECL void archive_entry_xattr_add_entry(struct archive_entry *,
const char * /* name */, const void * /* value */,
size_t /* size */);
/*
* Interfaces to support tagging archive entries with caller-defined xattrs.
*/
__LA_DECL void archive_entry_xattr_delete_entry(struct archive_entry *,
const char * /* name */);
__LA_DECL int archive_entry_has_xattr(struct archive_entry *entry,
const char * /* name */, const void ** /* value */,
size_t * /* size */)
/*
* To retrieve the xattr list, first "reset", then repeatedly ask for the
* "next" entry.

View file

@ -109,6 +109,58 @@ archive_entry_xattr_add_entry(struct archive_entry *entry,
entry->xattr_head = xp;
}
/*
* Delete the named extended attribute, if present.
*/
void
archive_entry_xattr_delete_entry(struct archive_entry *entry,
const char *name)
{
struct ae_xattr *xp, *pxp;
pxp = NULL;
for (xp = entry->xattr_head; xp != NULL; xp = xp->next)
{
if (strcmp(name, xp->name) == 0) {
free(xp->name);
if (xp->size > 0)
free(xp->value);
if (pxp == NULL) {
/*
* Free at head.
*/
entry->xattr_head = xp->next;
free(xp);
} else {
pxp->next = xp->next;
free(xp);
}
break;
}
pxp = xp;
}
}
/*
* Search for the named extended attribute. Return it's value and size
* if present.
*/
int
archive_entry_has_xattr(struct archive_entry *entry,
const char *name, const void **value, size_t *size)
{
struct ae_xattr *xp;
for (xp = entry->xattr_head; xp != NULL; xp = xp->next)
{
if (strcmp(name, xp->name) == 0) {
*value = xp->value;
*size = xp->size;
return (1);
}
}
return (0);
}
/*
* returns number of the extended attribute entries