mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-30 13:30:57 +08:00
Fix entry writing, truncate file if rewriting.
This commit is contained in:
parent
e3c59d222c
commit
7b245a0a55
@ -144,21 +144,18 @@ static char * slurp_file(int fd) {
|
||||
return entry;
|
||||
}
|
||||
|
||||
static int spew_file(int fd, char * spew) {
|
||||
int written = 0;
|
||||
static int spew_file(int fd, char * spew, int len) {
|
||||
int writeres = 0;
|
||||
int len = strlen(spew);
|
||||
char * spewptr = spew;
|
||||
|
||||
while(written < len) {
|
||||
writeres = write(fd, spewptr, len - written);
|
||||
while(len > 0) {
|
||||
writeres = write(fd, spew, len);
|
||||
if(writeres == -1) {
|
||||
perror("could not spew write");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
spewptr += writeres;
|
||||
written += writeres;
|
||||
spew += writeres;
|
||||
len -= writeres;
|
||||
}
|
||||
}
|
||||
return writeres;
|
||||
@ -171,7 +168,7 @@ static int spew_entry(Entry * e, struct berval * path) {
|
||||
int entry_length;
|
||||
char * entry_as_string;
|
||||
|
||||
openres = open(path->bv_val, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
|
||||
openres = open(path->bv_val, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
if(openres == -1) {
|
||||
if(errno == ENOENT)
|
||||
rs = LDAP_NO_SUCH_OBJECT;
|
||||
@ -204,7 +201,7 @@ static int spew_entry(Entry * e, struct berval * path) {
|
||||
close(openres);
|
||||
}
|
||||
else {
|
||||
spew_res = spew_file(openres, entry_as_string);
|
||||
spew_res = spew_file(openres, entry_as_string, entry_length);
|
||||
close(openres);
|
||||
if(spew_res == -1)
|
||||
rs = LDAP_UNWILLING_TO_PERFORM;
|
||||
|
Loading…
Reference in New Issue
Block a user