summaryrefslogtreecommitdiffstats
path: root/src/opk
diff options
context:
space:
mode:
Diffstat (limited to 'src/opk')
-rw-r--r--src/opk/write.c62
1 files changed, 23 insertions, 39 deletions
diff --git a/src/opk/write.c b/src/opk/write.c
index c3a88c8..1561e38 100644
--- a/src/opk/write.c
+++ b/src/opk/write.c
@@ -85,7 +85,6 @@ static int
_opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
struct opkg_opk_dirent *dir, size_t path_off)
{
- int ret;
char *child_path;
int children_n;
struct dirent **children;
@@ -106,8 +105,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
size_t size;
size_t num_read;
size_t tot_read;
-
- ret = OPKG_OPK_OK;
+ int ret;
child_path = opk->path_virt + path_off;
children_n = scandir(opk->path_real, &children, _opkg_opk_opk_write_filter,
@@ -121,8 +119,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
fprintf(stderr, "Error: File name \"%s\" too "
"long",
children[children_i]->d_name);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
child_path[name_i] =
children[children_i]->d_name[name_i];
@@ -131,8 +128,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
if (lstat(opk->path_real, &st) != 0) {
fprintf(stderr, _("Error: Failed to stat \"%s\"\n"),
opk->path_real);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
/* TODO: Ownership override */
uid = st.st_uid;
@@ -143,8 +139,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
if (path_off + name_i + 2 == OPKG_OPK_USTAR_NAME_SIZE) {
fprintf(stderr, "Error: File name \"%s\" too "
"long", child_path);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
child_path[name_i] = '/';
child_path[++name_i] = '\0';
@@ -155,25 +150,21 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
OPKG_OPK_OK) {
fputs(_("Error: Failed to write header\n"),
stderr);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
if (_opkg_opk_opk_write_dir_read(opk, &child,
path_off + name_i) !=
OPKG_OPK_OK) {
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
} else if (S_ISLNK(st.st_mode)) {
link_len = readlink(opk->path_real, link,
OPKG_OPK_USTAR_LINKNAME_SIZE);
if (link_len < 0) {
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
if (link_len == OPKG_OPK_USTAR_LINKNAME_SIZE) {
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
link[link_len] = '\0';
if (opkg_opk_ustar_write_header(opk->inner_ustar,
@@ -183,8 +174,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
OPKG_OPK_OK) {
fputs(_("Error: Failed to write header\n"),
stderr);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
} else if (S_ISCHR(st.st_mode)) {
if (opkg_opk_ustar_write_header(opk->inner_ustar,
@@ -196,8 +186,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
OPKG_OPK_OK) {
fputs(_("Error: Failed to write header\n"),
stderr);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
} else if (S_ISBLK(st.st_mode)) {
if (opkg_opk_ustar_write_header(opk->inner_ustar,
@@ -209,8 +198,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
OPKG_OPK_OK) {
fputs(_("Error: Failed to write header\n"),
stderr);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
} else if (S_ISFIFO(st.st_mode)) {
if (opkg_opk_ustar_write_header(opk->inner_ustar,
@@ -220,8 +208,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
OPKG_OPK_OK) {
fputs(_("Error: Failed to write header\n"),
stderr);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
} else if (S_ISREG(st.st_mode)) {
if (opkg_opk_ustar_write_header(opk->inner_ustar,
@@ -231,16 +218,14 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
NULL) != OPKG_OPK_OK) {
fputs(_("Error: Failed to write header\n"),
stderr);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
fp = fopen(opk->path_real, "rb");
if (fp == NULL) {
fprintf(stderr, _("Error: Failed to open file "
"\"%s\"\n"),
opk->path_real);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
opkg_opk_ustar_get_buffer(opk->inner_ustar,
&buffer, &size);
@@ -253,37 +238,36 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
if (ferror(fp) != 0) {
fputs(_("Error: Error reading file\n"), stderr);
fclose(fp);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
if (fclose(fp) != 0) {
fputs(_("Error: Failed to close file\n"),
stderr);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
if ((uintmax_t) tot_read != (uintmax_t) st.st_size) {
fprintf(stderr, _("Error: Expected %jd bytes "
"but read %zu\n"),
(intmax_t) st.st_size,
num_read);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
} else {
fprintf(stderr, _("Error: Unknown type of file \"%s\"\n"
), opk->path_real);
- ret = OPKG_OPK_ERROR;
- goto out1;
+ goto err;
}
}
- out1:
+ ret = OPKG_OPK_OK;
+ goto out;
+ err:
+ ret = OPKG_OPK_ERROR;
+ out:
for (children_i = 0; children_i < children_n; ++children_i) {
free(children[children_i]);
}
free(children);
- out0:
return ret;
}