summaryrefslogtreecommitdiff
path: root/src/database.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/database.c b/src/database.c
index f4169ff..5f4e5e6 100644
--- a/src/database.c
+++ b/src/database.c
@@ -933,7 +933,7 @@ static int apk_db_write_fdb(struct apk_database *db, struct apk_ostream *os)
struct apk_db_dir_instance *diri;
struct apk_db_file *file;
struct hlist_node *c1, *c2;
- char buf[1024];
+ char buf[1024+PATH_MAX];
apk_blob_t bbuf = APK_BLOB_BUF(buf);
int r;
@@ -976,6 +976,12 @@ static int apk_db_write_fdb(struct apk_database *db, struct apk_ostream *os)
if (diri->acl != apk_default_acl_dir)
apk_blob_push_db_acl(&bbuf, 'M', diri->acl);
+ bbuf = apk_blob_pushed(APK_BLOB_BUF(buf), bbuf);
+ if (APK_BLOB_IS_NULL(bbuf)) return -ENOBUFS;
+ r = apk_ostream_write(os, bbuf.ptr, bbuf.len);
+ if (r != bbuf.len) return r < 0 ? r : -ENOSPC;
+ bbuf = APK_BLOB_BUF(buf);
+
hlist_for_each_entry(file, c2, &diri->owned_files, diri_files_list) {
apk_blob_push_blob(&bbuf, APK_BLOB_STR("R:"));
apk_blob_push_blob(&bbuf, APK_BLOB_PTR_LEN(file->name, file->namelen));
@@ -990,13 +996,12 @@ static int apk_db_write_fdb(struct apk_database *db, struct apk_ostream *os)
apk_blob_push_blob(&bbuf, APK_BLOB_STR("\n"));
}
- if (apk_ostream_write(os, buf, bbuf.ptr - buf) != bbuf.ptr - buf)
- return -EIO;
+ bbuf = apk_blob_pushed(APK_BLOB_BUF(buf), bbuf);
+ if (APK_BLOB_IS_NULL(bbuf)) return -ENOBUFS;
+ r = apk_ostream_write(os, bbuf.ptr, bbuf.len);
+ if (r != bbuf.len) return r < 0 ? r : -ENOSPC;
bbuf = APK_BLOB_BUF(buf);
}
- if (apk_ostream_write(os, buf, bbuf.ptr - buf) != bbuf.ptr - buf)
- return -EIO;
- bbuf = APK_BLOB_BUF(buf);
}
apk_ostream_write(os, "\n", 1);
}