Branch data Line data Source code
1 : : /*
2 : : * libdpkg - Debian packaging suite library routines
3 : : * options-dirs.c - CLI options parsing directories
4 : : *
5 : : * Copyright © 2022 Guillem Jover <guillem@debian.org>
6 : : *
7 : : * This is free software; you can redistribute it and/or modify
8 : : * it under the terms of the GNU General Public License as published by
9 : : * the Free Software Foundation; either version 2 of the License, or
10 : : * (at your option) any later version.
11 : : *
12 : : * This is distributed in the hope that it will be useful,
13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : : * GNU General Public License for more details.
16 : : *
17 : : * You should have received a copy of the GNU General Public License
18 : : * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 : : */
20 : :
21 : : #include <config.h>
22 : : #include <compat.h>
23 : :
24 : : #include <stdlib.h>
25 : :
26 : : #include <dpkg/macros.h>
27 : : #include <dpkg/dpkg.h>
28 : : #include <dpkg/dpkg-db.h>
29 : : #include <dpkg/fsys.h>
30 : : #include <dpkg/options.h>
31 : :
32 : : void
33 : 178 : set_instdir(const struct cmdinfo *cip, const char *value)
34 : : {
35 : : /* Make sure the database is initialized before the root directory,
36 : : * otherwise, on first use it would get initialized based on the
37 : : * newly set root directory. */
38 : 178 : dpkg_db_get_dir();
39 : :
40 : 178 : dpkg_fsys_set_dir(value);
41 : 178 : }
42 : :
43 : : void
44 : 214 : set_admindir(const struct cmdinfo *cip, const char *value)
45 : : {
46 : 214 : dpkg_db_set_dir(value);
47 : 214 : }
48 : :
49 : : void
50 : 120 : set_root(const struct cmdinfo *cip, const char *value)
51 : : {
52 : : char *db_dir;
53 : :
54 : : /* Initialize the root directory. */
55 : 120 : dpkg_fsys_set_dir(value);
56 : :
57 : : /* Set the database directory based on the new root directory. */
58 : 120 : db_dir = dpkg_fsys_get_path(ADMINDIR);
59 : 120 : dpkg_db_set_dir(db_dir);
60 : 120 : free(db_dir);
61 : 120 : }
|