/*
- $Id: ea.c,v 1.21 2010-04-04 08:24:38 franklahm Exp $
Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
This program is free software; you can redistribute it and/or modify
size_t attrsize,
int bitmap)
{
+ int ea_existed = 0;
unsigned int count = 0;
void *tmprealloc;
if (ea->ea_count > 0) {
while (count < ea->ea_count) {
if (strcmp(attruname, (*ea->ea_entries)[count].ea_name) == 0) {
- LOG(log_debug, logtype_afpd, "ea_addentry('%s'): exists", attruname);
+ ea_existed = 1;
+ LOG(log_debug, logtype_afpd, "ea_addentry('%s', bitmap:0x%x): exists", attruname, bitmap);
if (bitmap & kXAttrCreate)
/* its like O_CREAT|O_EXCL -> fail */
return -1;
- if ( ! (bitmap & kXAttrReplace))
- /* replace was not requested, then its an error */
- return -1;
- break;
+ (*(ea->ea_entries))[count].ea_size = attrsize;
+ return 0;
}
count++;
}
}
+ if ((bitmap & kXAttrReplace) && ! ea_existed)
+ /* replace was requested, but EA didn't exist */
+ return -1;
+
if (ea->ea_count == 0) {
ea->ea_entries = malloc(sizeof(struct ea_entry));
if ( ! ea->ea_entries) {
LOG(log_error, logtype_afpd, "ea_addentry: OOM");
return -1;
}
- } else {
+ } else if (! ea_existed) {
tmprealloc = realloc(ea->ea_entries, sizeof(struct ea_entry) * (ea->ea_count + 1));
if ( ! tmprealloc) {
LOG(log_error, logtype_afpd, "ea_addentry: OOM");
unsigned int count = 0;
if (ea->ea_count == 0) {
- LOG(log_error, logtype_afpd, "ea_delentry('%s'): illegal ea_count of 0 on deletion");
+ LOG(log_error, logtype_afpd, "ea_delentry('%s'): illegal ea_count of 0 on deletion",
+ attruname);
return -1;
}
while (count < ea->ea_count) {
/* search matching EA */
- if (strcmp(attruname, (*ea->ea_entries)[count].ea_name) == 0) {
+ if ((*ea->ea_entries)[count].ea_name &&
+ strcmp(attruname, (*ea->ea_entries)[count].ea_name) == 0) {
free((*ea->ea_entries)[count].ea_name);
(*ea->ea_entries)[count].ea_name = NULL;
if (read(fd, rbuf, toread) != (ssize_t)toread) {
LOG(log_error, logtype_afpd, "get_eacontent('%s/%s'): short read", uname, attruname);
+ close(fd);
ret = AFPERR_MISC;
break;
}