1 |
commit: 2b91248cfb513dce06368c4485c55fd6746ee642 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Dec 29 13:25:21 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Dec 29 13:25:21 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=2b91248c |
7 |
|
8 |
libq/tree: remove tree_pkg_vdb_openat as public function |
9 |
|
10 |
convert the only consumer of tree_pkg_vdb_openat to |
11 |
tree_pkg_vdb_fopenat, such that we can transparently provide this |
12 |
functionality for binpkgs (via xpak). |
13 |
|
14 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
15 |
|
16 |
libq/tree.c | 2 +- |
17 |
libq/tree.h | 1 - |
18 |
qcheck.c | 30 +++++++++++++----------------- |
19 |
3 files changed, 14 insertions(+), 19 deletions(-) |
20 |
|
21 |
diff --git a/libq/tree.c b/libq/tree.c |
22 |
index cc8cf3e..f0c8ddb 100644 |
23 |
--- a/libq/tree.c |
24 |
+++ b/libq/tree.c |
25 |
@@ -474,7 +474,7 @@ tree_next_pkg(tree_cat_ctx *cat_ctx) |
26 |
return ret; |
27 |
} |
28 |
|
29 |
-int |
30 |
+static int |
31 |
tree_pkg_vdb_openat( |
32 |
tree_pkg_ctx *pkg_ctx, |
33 |
const char *file, |
34 |
|
35 |
diff --git a/libq/tree.h b/libq/tree.h |
36 |
index d769b7b..aacfb14 100644 |
37 |
--- a/libq/tree.h |
38 |
+++ b/libq/tree.h |
39 |
@@ -123,7 +123,6 @@ void tree_close_cat(tree_cat_ctx *cat_ctx); |
40 |
int tree_filter_pkg(const struct dirent *de); |
41 |
tree_pkg_ctx *tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name); |
42 |
tree_pkg_ctx *tree_next_pkg(tree_cat_ctx *cat_ctx); |
43 |
-int tree_pkg_vdb_openat(tree_pkg_ctx *pkg_ctx, const char *file, int flags, mode_t mode); |
44 |
FILE *tree_pkg_vdb_fopenat(tree_pkg_ctx *pkg_ctx, const char *file, |
45 |
int flags, mode_t mode, const char *fmode); |
46 |
#define tree_pkg_vdb_fopenat_ro(pkg_ctx, file) \ |
47 |
|
48 |
diff --git a/qcheck.c b/qcheck.c |
49 |
index f77a501..ab4356b 100644 |
50 |
--- a/qcheck.c |
51 |
+++ b/qcheck.c |
52 |
@@ -72,7 +72,6 @@ struct qcheck_opt_state { |
53 |
static int |
54 |
qcheck_process_contents(tree_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state) |
55 |
{ |
56 |
- int fd_contents; |
57 |
FILE *fp_contents, *fp_contents_update; |
58 |
size_t num_files, num_files_ok, num_files_unknown, num_files_ignored; |
59 |
char *buffer, *line; |
60 |
@@ -85,18 +84,9 @@ qcheck_process_contents(tree_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state) |
61 |
fp_contents_update = NULL; |
62 |
|
63 |
/* Open contents */ |
64 |
- fd_contents = tree_pkg_vdb_openat(pkg_ctx, "CONTENTS", |
65 |
- O_RDONLY | O_CLOEXEC, 0); |
66 |
- if (fd_contents == -1) |
67 |
+ fp_contents = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS"); |
68 |
+ if ((fp_contents = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS")) == NULL) |
69 |
return EXIT_SUCCESS; |
70 |
- if (fstat(fd_contents, &cst)) { |
71 |
- close(fd_contents); |
72 |
- return EXIT_SUCCESS; |
73 |
- } |
74 |
- if ((fp_contents = fdopen(fd_contents, "r")) == NULL) { |
75 |
- close(fd_contents); |
76 |
- return EXIT_SUCCESS; |
77 |
- } |
78 |
|
79 |
/* Open contents_update, if needed */ |
80 |
atom = tree_get_atom(pkg_ctx, false); |
81 |
@@ -322,11 +312,17 @@ qcheck_process_contents(tree_pkg_ctx *pkg_ctx, struct qcheck_opt_state *state) |
82 |
} |
83 |
|
84 |
if (state->qc_update) { |
85 |
- if (fchown(fd_contents, cst.st_uid, cst.st_gid)) { |
86 |
- /* meh */; |
87 |
- } |
88 |
- if (fchmod(fd_contents, cst.st_mode)) { |
89 |
- /* meh */; |
90 |
+ int fd_contents = fileno(fp_contents); |
91 |
+ int fd_update = fileno(fp_contents_update); |
92 |
+ |
93 |
+ /* copy original ownership and mode */ |
94 |
+ if (fstat(fd_contents, &cst) == 0) { |
95 |
+ if (fchown(fd_update, cst.st_uid, cst.st_gid)) { |
96 |
+ /* meh */; |
97 |
+ } |
98 |
+ if (fchmod(fd_update, cst.st_mode)) { |
99 |
+ /* meh */; |
100 |
+ } |
101 |
} |
102 |
fclose(fp_contents_update); |
103 |
if (renameat(pkg_ctx->fd, "CONTENTS~", pkg_ctx->fd, "CONTENTS")) |