@@ -47,7 +47,7 @@ struct rpmdbstate {
4747
4848 int dbenvopened ; /* database environment opened */
4949 int pkgdbopened ; /* package database openend */
50- int is_ostree ; /* read-only db that lives in /usr/share/rpm */
50+ const char * dbpath ; /* path to the database */
5151
5252 DB_ENV * dbenv ; /* database environment */
5353 DB * db ; /* packages database */
@@ -70,17 +70,20 @@ access_rootdir(struct rpmdbstate *state, const char *dir, int mode)
7070}
7171
7272static void
73- detect_ostree (struct rpmdbstate * state )
73+ detect_dbpath (struct rpmdbstate * state )
7474{
75- state -> is_ostree = access_rootdir (state , "/var/lib/rpm" , W_OK ) == -1 &&
76- access_rootdir (state , "/usr/share/rpm/Packages" , R_OK ) == 0 ? 1 : -1 ;
75+ state -> dbpath = access_rootdir (state , "/var/lib/rpm" , W_OK ) == -1
76+ && access_rootdir (state , "/usr/share/rpm/Packages" , R_OK ) == 0
77+ ? "/usr/share/rpm" : "/var/lib/rpm" ;
7778}
7879
7980static int
8081stat_database_name (struct rpmdbstate * state , char * dbname , struct stat * statbuf , int seterror )
8182{
8283 char * dbpath ;
83- dbpath = solv_dupjoin (state -> rootdir , state -> is_ostree > 0 ? "/usr/share/rpm/" : "/var/lib/rpm/" , dbname );
84+ if (!state -> dbpath )
85+ detect_dbpath (state );
86+ dbpath = solv_dupjoin (state -> rootdir , state -> dbpath , dbname );
8487 if (stat (dbpath , statbuf ))
8588 {
8689 if (seterror )
@@ -95,9 +98,7 @@ stat_database_name(struct rpmdbstate *state, char *dbname, struct stat *statbuf,
9598static int
9699stat_database (struct rpmdbstate * state , struct stat * statbuf )
97100{
98- if (!state -> is_ostree )
99- detect_ostree (state );
100- return stat_database_name (state , "Packages" , statbuf , 1 );
101+ return stat_database_name (state , "/Packages" , statbuf , 1 );
101102}
102103
103104
@@ -171,7 +172,6 @@ serialize_dbenv_ops(struct rpmdbstate *state)
171172static int
172173opendbenv (struct rpmdbstate * state )
173174{
174- const char * rootdir = state -> rootdir ;
175175 char * dbpath ;
176176 DB_ENV * dbenv = 0 ;
177177 int r ;
@@ -181,16 +181,16 @@ opendbenv(struct rpmdbstate *state)
181181#if (defined(FEDORA ) || defined(MAGEIA )) && (DB_VERSION_MAJOR >= 5 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5 ))
182182 dbenv -> set_thread_count (dbenv , 8 );
183183#endif
184- dbpath = solv_dupjoin ( rootdir , "/var/lib/rpm" , 0 ) ;
185- state -> is_ostree = -1 ;
184+ state -> dbpath = "/var/lib/rpm" ;
185+ dbpath = solv_dupjoin ( state -> rootdir , state -> dbpath , 0 ) ;
186186 if (access (dbpath , W_OK ) == -1 )
187187 {
188- free ( dbpath );
189- dbpath = solv_dupjoin ( rootdir , "/usr/share/rpm/Packages" , 0 );
190- if ( access ( dbpath , R_OK ) == 0 )
191- state -> is_ostree = 1 ;
192- free ( dbpath );
193- dbpath = solv_dupjoin ( rootdir , state -> is_ostree > 0 ? "/usr/share/rpm" : "/var/lib/rpm" , 0 );
188+ if ( access_rootdir ( state , "/usr/share/rpm/Packages" , R_OK ) == 0 )
189+ {
190+ state -> dbpath = "/usr/share/rpm" ;
191+ free ( dbpath ) ;
192+ dbpath = solv_dupjoin ( state -> rootdir , state -> dbpath , 0 );
193+ }
194194 r = dbenv -> open (dbenv , dbpath , DB_CREATE |DB_PRIVATE |DB_INIT_MPOOL , 0 );
195195 }
196196 else
@@ -426,7 +426,7 @@ count_headers(struct rpmdbstate *state)
426426 DBT dbkey ;
427427 DBT dbdata ;
428428
429- if (stat_database_name (state , "Name" , & statbuf , 0 ))
429+ if (stat_database_name (state , "/ Name" , & statbuf , 0 ))
430430 return 0 ;
431431 memset (& dbkey , 0 , sizeof (dbkey ));
432432 memset (& dbdata , 0 , sizeof (dbdata ));
@@ -502,7 +502,9 @@ hash_name_index(struct rpmdbstate *state, Chksum *chk)
502502 int fd , l ;
503503 char buf [4096 ];
504504
505- dbpath = solv_dupjoin (state -> rootdir , state -> is_ostree > 0 ? "/usr/share/rpm/" : "/var/lib/rpm/" , "Name" );
505+ if (!state -> dbpath )
506+ detect_dbpath (state );
507+ dbpath = solv_dupjoin (state -> rootdir , state -> dbpath , "/Name" );
506508 if ((fd = open (dbpath , O_RDONLY )) < 0 )
507509 return -1 ;
508510 while ((l = read (fd , buf , sizeof (buf ))) > 0 )
0 commit comments