1 /*----------------------------------------------------------------------*\
2 |* spkg - The Unofficial Slackware Linux Package Manager *|
3 |* designed by Ondøej Jirman, 2005 *|
4 |*----------------------------------------------------------------------*|
5 |* No copy/usage restrictions are imposed on anybody. *|
6 \*----------------------------------------------------------------------*/
27 extern int posix_utime (const char *path
, struct utimbuf
*buf
);
31 ************************************************************************/
35 gboolean filelist_loaded
;
38 gchar
* pkgdir
; /* /var/log/packages/ */
39 gchar
* scrdir
; /* /var/log/scripts/ */
45 static struct db_state _db
; // yeah, this is really not uninitialized
47 #define e_set(n, fmt, args...) e_add(_db.err, "pkgdb", __func__, n, fmt, ##args)
49 #define _db_open_check(v) \
52 e_set(E_ERROR|DB_NOPEN, "Package database is NOT open."); \
56 #define LINEMATCH(s) (strncmp(line, s, sizeof(s)-1) == 0)
57 #define LINESIZE(s) (sizeof(s)-1)
59 /* public - open/close
60 ************************************************************************/
62 gint
db_open(const gchar
* root
, gboolean readonly
, struct error
* e
)
65 gchar
* checkdirs
[] = { "packages", "scripts", "removed_packages",
66 "removed_scripts", "setup", NULL
};
70 _db
.readonly
= readonly
;
74 e_set(E_ERROR
|DB_OPEN
, "Package database is already open.");
78 gchar
* sane_root
= sanitize_root_path(root
);
79 if (g_path_is_absolute(sane_root
))
80 _db
.topdir
= g_strdup_printf("%s%s", sane_root
, PKGDB_DIR
);
83 gchar
* cwd
= g_get_current_dir();
84 _db
.topdir
= g_strdup_printf("%s/%s%s", cwd
, sane_root
, PKGDB_DIR
);
87 _db
.pkgdir
= g_strdup_printf("%s/packages", _db
.topdir
);
88 _db
.scrdir
= g_strdup_printf("%s/scripts", _db
.topdir
);
92 for (d
= checkdirs
; *d
!= NULL
; d
++)
94 gchar
* tmpdir
= g_strdup_printf("%s/%s", _db
.topdir
, *d
);
95 /* if it is not a directory, clean it and create it */
96 if (sys_file_type(tmpdir
, 1) != SYS_DIR
)
100 e_set(E_FATAL
, "Package database directory does not exist and can't be created in readonly mode. (%s)", tmpdir
);
107 /* if it is still not a directory, return with error */
108 if (sys_file_type(tmpdir
, 1) != SYS_DIR
)
110 e_set(E_FATAL
, "Can't access package database directory. (%s)", tmpdir
);
121 gchar
*path_lock
= g_strdup_printf("%s/.lock", _db
.pkgdir
);
122 _db
.fd_lock
= sys_lock_new(path_lock
, e
);
124 if (_db
.fd_lock
== -1)
126 e_set(E_FATAL
, "Can't lock package database. (lock creation failed)");
129 if (sys_lock_trywait(_db
.fd_lock
, 20, e
))
131 e_set(E_FATAL
, "Can't lock package database. (database is already locked)");
140 sys_lock_del(_db
.fd_lock
);
145 memset(&_db
, 0, sizeof(_db
));
154 e_set(E_ERROR
, "Package database is NOT open.");
159 sys_lock_del(_db
.fd_lock
);
162 JSLFA(used
, _db
.paths
);
167 memset(&_db
, 0, sizeof(_db
));
171 ************************************************************************/
173 void db_filelist_rem_pkg_paths(const struct db_pkg
* pkg
)
175 gchar path
[MAXPATHLEN
];
180 JSLF(p1
, pkg
->paths
, path
);
183 JSLG(p2
, _db
.paths
, path
);
189 JSLD(rc
, _db
.paths
, path
);
196 JSLN(p1
, pkg
->paths
, path
);
200 void db_filelist_add_pkg_paths(const struct db_pkg
* pkg
)
202 gchar path
[MAXPATHLEN
];
206 JSLF(p1
, pkg
->paths
, path
);
209 JSLI(p2
, _db
.paths
, path
);
211 JSLN(p1
, pkg
->paths
, path
);
215 gint
db_filelist_load(gboolean force_reload
)
219 if (_db
.filelist_loaded
&& !force_reload
)
222 DIR* d
= opendir(_db
.pkgdir
);
225 e_set(E_FATAL
, "Can't open db directory. (%s)", strerror(errno
));
228 gchar sbuf
[1024*128];
237 /* for each package database entry */
238 while ((de
= readdir(d
)) != NULL
)
240 gchar
* name
= de
->d_name
;
241 /* is this valid package database entry file? */
242 if (parse_pkgname(name
, 6) == NULL
)
246 gchar
* tmpstr
= g_strdup_printf("%s/%s", _db
.pkgdir
, name
);
247 FILE* f
= fopen(tmpstr
, "r");
249 if (f
== NULL
) /* main package entry can't be open */
251 e_set(E_ERROR
, "Can't open package database file %s. (%s)", name
, strerror(errno
));
254 /* set bigger buffer */
255 setvbuf(f
, sbuf
, _IOFBF
, sizeof(sbuf
));
260 while ((linelen
= getline(&line
, &size
, f
)) >= 0)
262 /* remove new line character from the end of the line */
263 if (linelen
> 0 && line
[linelen
-1] == '\n')
264 line
[linelen
-1] = '\0', linelen
--;
265 /* if we are in the files section, add path to the list */
268 /* remove trailing / character from the end of the line */
269 if (linelen
> 0 && line
[linelen
-1] == '/')
270 line
[linelen
-1] = '\0', linelen
--;
271 /* check path size limit */
272 if (linelen
>= MAXPATHLEN
)
275 strcpy(line
+100, "...");
276 e_set(E_ERROR
, "Path too long in the package database file %s. (%s)", name
, line
);
279 #if ASSUME_BROKEN_PKGDB == 1
280 gchar
* sane_path
= path_simplify(line
);
281 if (sane_path
[0] == '\0')
283 JSLI(refs
, _db
.paths
, ".");
287 JSLI(refs
, _db
.paths
, sane_path
);
291 JSLI(refs
, _db
.paths
, line
);
295 else if (LINEMATCH("FILE LIST:"))
300 /* open and parse installation script for symbolic links */
301 tmpstr
= g_strdup_printf("%s/%s", _db
.scrdir
, name
);
302 f
= fopen(tmpstr
, "r");
304 if (f
== NULL
) /* script package entry can't be open */
305 continue; /* ignore if can't be open (may not exist) XXX: check if errno is NOTEX */
306 setvbuf(f
, sbuf
, _IOFBF
, sizeof(sbuf
));
309 while ((linelen
= getline(&line
, &size
, f
)) >= 0)
311 /* remove new line character from the end of the line */
312 if (linelen
> 0 && line
[linelen
-1] == '\n')
313 line
[linelen
-1] = '\0', linelen
--;
315 /* parse create link line */
316 gchar
*dir
, *link
, *target
;
317 if (parse_createlink(line
, &dir
, &link
, &target
))
319 gchar
* path
= g_strdup_printf("%s/%s", dir
, link
);
320 gchar
* sane_path
= path_simplify(path
);
326 /* check path size limit */
327 if (strlen(sane_path
) >= MAXPATHLEN
)
329 strcpy(sane_path
+100, "...");
330 e_set(E_ERROR
, "Path too long in the package database file %s. (%s)", name
, line
);
335 JSLI(refs
, _db
.paths
, sane_path
);
347 _db
.filelist_loaded
= TRUE
;
356 gulong
db_filelist_get_path_refs(const gchar
* path
)
359 JSLG(refs
, _db
.paths
, path
);
362 return (gulong
)(*refs
);
365 void db_filelist_free()
368 JSLFA(used
, _db
.paths
);
369 _db
.filelist_loaded
= FALSE
;
372 /* public - memmory management
373 ************************************************************************/
375 struct db_pkg
* db_alloc_pkg(gchar
* name
)
380 e_set(E_ERROR
, "Package name can't be NULL.");
383 if (parse_pkgname(name
, 6) != (gchar
*)-1)
385 e_set(E_ERROR
, "Invalid package name. (%s)", name
);
388 p
= g_new0(struct db_pkg
, 1);
389 p
->name
= parse_pkgname(name
, 5);
390 p
->shortname
= parse_pkgname(name
, 1);
391 p
->version
= parse_pkgname(name
, 2);
392 p
->arch
= parse_pkgname(name
, 3);
393 p
->build
= parse_pkgname(name
, 4);
394 p
->time
= time(NULL
);
398 void db_free_pkg(struct db_pkg
* pkg
)
404 JSLFA(freed
, pkg
->paths
);
406 g_free(pkg
->shortname
);
407 g_free(pkg
->version
);
410 g_free(pkg
->location
);
413 memset(pkg
, 0, sizeof(*pkg
));
417 gint
db_pkg_add_path(struct db_pkg
* pkg
, const gchar
* path
, db_path_type type
)
420 /* check path size limit */
421 if (strlen(path
) >= MAXPATHLEN
)
423 JSLI(ptype
, pkg
->paths
, path
);
428 db_path_type
db_pkg_get_path(struct db_pkg
* pkg
, const gchar
* path
)
431 JSLG(ptype
, pkg
->paths
, path
);
433 return (db_path_type
)(*ptype
);
437 /* public - main database package operations
438 ************************************************************************/
440 static gint
_db_add_pkg(struct db_pkg
* pkg
, gchar
* origname
)
443 gchar
*ppath
, *spath
, *ppath_tmp
, *spath_tmp
;
447 /* check if pkg contains everthing required */
448 if (pkg
== NULL
|| pkg
->name
== NULL
|| pkg
->paths
== NULL
)
450 e_set(E_BADARG
, "Incomplete package structure.");
456 e_set(E_FATAL
, "Can't add packages to the database in the readonly mode.");
460 ppath
= g_strdup_printf("%s/%s", _db
.pkgdir
, pkg
->name
);
461 spath
= g_strdup_printf("%s/%s", _db
.scrdir
, pkg
->name
);
462 ppath_tmp
= g_strdup_printf("%s/.%s", _db
.pkgdir
, pkg
->name
);
463 spath_tmp
= g_strdup_printf("%s/.%s", _db
.scrdir
, pkg
->name
);
465 /* check if package file exists */
466 if (origname
== NULL
)
468 if (sys_file_type(ppath
, 1) != SYS_NONE
)
470 e_set(E_FATAL
|DB_EXIST
, "Package is already in the database %s. (%s)", ppath
, strerror(errno
));
475 /* write package file (tmp) */
476 pf
= fopen(ppath_tmp
, "w");
479 e_set(E_FATAL
, "Can't open package file %s. (%s)", ppath_tmp
, strerror(errno
));
483 fchmod(fileno(pf
), 0644);
486 /* construct header */
489 "COMPRESSED PACKAGE SIZE: %u K\n"
490 "UNCOMPRESSED PACKAGE SIZE: %u K\n"
491 "PACKAGE LOCATION: %s\n"
492 "PACKAGE DESCRIPTION:\n"
495 pkg
->name
, pkg
->csize
, pkg
->usize
,
496 pkg
->location
? pkg
->location
: "",
497 pkg
->desc
? pkg
->desc
: "") < 0)
502 /* construct filelist */
503 gchar path
[MAXPATHLEN
];
506 JSLF(ptype
, pkg
->paths
, path
);
507 while (ptype
!= NULL
)
509 if (*ptype
== DB_PATH_FILE
)
511 if (fprintf(pf
, "%s\n", path
) < 0)
514 else if (*ptype
== DB_PATH_DIR
)
516 if (fprintf(pf
, "%s/\n", path
) < 0)
519 JSLN(ptype
, pkg
->paths
, path
);
526 struct utimbuf dt
= { pkg
->time
, pkg
->time
};
528 if (posix_utime(ppath_tmp
, &dt
) == -1)
530 if (utime(ppath_tmp
, &dt
) == -1)
533 e_set(E_ERROR
, "Can't utime package entry %s. (%s)", ppath_tmp
, strerror(errno
));
537 /* wirte script file if necessary */
540 sf
= fopen(spath_tmp
, "w");
543 e_set(E_FATAL
, "Can't open script file %s. (%s)", spath_tmp
, strerror(errno
));
547 fchmod(fileno(sf
), 0755);
549 if (fprintf(sf
, "%s", pkg
->doinst
) < 0)
551 e_set(E_FATAL
, "Can't write into script file %s. (%s)", spath_tmp
, strerror(errno
));
560 if (db_rem_pkg(origname
))
562 e_set(E_FATAL
, "Can't remove original package from the database. (%s)", origname
);
567 /* finally put package and script files into place */
569 if (access(ppath
, 0) == 0)
572 if (rename(ppath_tmp
, ppath
) < 0)
574 e_set(E_FATAL
, "Can't finalize package database update. Rename failed %s. You'll need to fix package database by hand. (%s)", ppath_tmp
, strerror(errno
));
581 if (access(spath
, 0) == 0)
584 if (rename(spath_tmp
, spath
) < 0)
586 e_set(E_FATAL
, "Can't finalize package database update. Rename failed %s. You'll need to fix package database by hand. (%s)", spath_tmp
, strerror(errno
));
598 e_set(E_FATAL
, "Can't write into package file %s. (%s)", ppath_tmp
, strerror(errno
));
601 /* just ingore errors here */
610 gint
db_add_pkg(struct db_pkg
* pkg
)
612 return _db_add_pkg(pkg
, NULL
);
615 gint
db_replace_pkg(gchar
* origname
, struct db_pkg
* pkg
)
617 return _db_add_pkg(pkg
, origname
);
620 struct db_pkg
* db_get_pkg(gchar
* name
, db_get_type type
)
624 gchar stream_buf1
[1024*128];
625 gchar stream_buf2
[1024*64];
626 struct db_pkg
* p
= NULL
;
630 e_set(E_BADARG
, "Package name can't be NULL.");
633 if (parse_pkgname(name
, 6) != (gchar
*)-1)
635 e_set(E_ERROR
, "Invalid package name. (%s)", name
);
638 if (type
!= DB_GET_WITHOUT_FILES
&& type
!= DB_GET_FULL
)
640 e_set(E_BADARG
, "Invalid get type value. (must be DB_GET_WITHOUT_FILES or DB_GET_FULL)");
646 /* open package db entries */
647 tmpstr
= g_strdup_printf("%s/%s", _db
.pkgdir
, name
);
648 fp
= fopen(tmpstr
, "r");
649 time_t mtime
= sys_file_mtime(tmpstr
, 1);
651 if (fp
== NULL
) /* main package entry can't be open */
653 e_set(E_ERROR
| (errno
== ENOENT
? DB_NOTEX
: 0), "Can't open package database entry file %s. (%s)", name
, strerror(errno
));
656 if (mtime
== (time_t)-1) /* package time can't be retrieved */
658 e_set(E_ERROR
, "Can't get package installation time for %s. (%s)", name
, strerror(errno
));
661 setvbuf(fp
, stream_buf1
, _IOFBF
, sizeof(stream_buf1
));
663 /*XXX: better checks here (if NOTEX, or other error) */
664 tmpstr
= g_strdup_printf("%s/%s", _db
.scrdir
, name
);
665 fs
= fopen(tmpstr
, "r");
668 setvbuf(fs
, stream_buf2
, _IOFBF
, sizeof(stream_buf2
));
670 p
= db_alloc_pkg(name
);
675 /* parse main package file */
676 gint snl
= strlen(p
->shortname
);
677 gint m
[5] = { 0 }; /* if particular line was matched it can't
678 occur anymore, so we cache info about already matched lines */
683 while ((linelen
= getline(&line
, &size
, fp
)) >= 0)
685 if (linelen
> 0 && line
[linelen
-1] == '\n')
687 line
[linelen
-1] = '\0';
690 if (!m
[0] && LINEMATCH("PACKAGE NAME:"))
692 gchar
* name
= g_strstrip(line
+ LINESIZE("PACKAGE NAME:"));
693 if (strcmp(name
, p
->name
))
695 e_set(E_ERROR
, "Package file name doesn't match with package name. (%s != %s)", p
->name
, name
);
698 /* skip whitespace */
701 else if (!m
[1] && LINEMATCH("COMPRESSED PACKAGE SIZE:"))
703 gchar
* size
= line
+ LINESIZE("COMPRESSED PACKAGE SIZE:");
704 if (sscanf(size
, " %u ", &p
->csize
) != 1)
706 e_set(E_ERROR
, "Can't parse compressed package size. (%s)", size
);
711 else if (!m
[2] && LINEMATCH("UNCOMPRESSED PACKAGE SIZE:"))
713 gchar
* size
= line
+ LINESIZE("UNCOMPRESSED PACKAGE SIZE:");
714 if (sscanf(size
, " %u ", &p
->usize
) != 1)
716 e_set(E_ERROR
, "Can't parse uncompressed package size. (%s)", size
);
721 else if (!m
[3] && LINEMATCH("PACKAGE LOCATION:"))
723 p
->location
= g_strdup(g_strstrip(line
+ LINESIZE("PACKAGE LOCATION:")));
726 else if (!m
[4] && LINEMATCH("PACKAGE DESCRIPTION:"))
730 else if (strncmp(line
, p
->shortname
, snl
) == 0)
732 gchar
* desc
= g_strconcat(p
->desc
? p
->desc
: "", line
, "\n", NULL
);
736 else if (LINEMATCH("FILE LIST:"))
742 e_set(E_ERROR
, "Corrupt package database entry. (%s)", p
->name
);
749 if (type
== DB_GET_WITHOUT_FILES
)
752 while ((linelen
= getline(&line
, &size
, fp
)) >= 0)
755 db_path_type type
= DB_PATH_FILE
;
756 if (linelen
> 0 && line
[linelen
-1] == '\n')
757 line
[linelen
-1] = '\0', linelen
--;
758 if (linelen
> 0 && line
[linelen
-1] == '/')
759 line
[linelen
-1] = '\0', linelen
--, type
= DB_PATH_DIR
;
760 /* check path size limit */
761 if (linelen
>= MAXPATHLEN
)
763 strcpy(line
+100, "...");
764 e_set(E_ERROR
, "Path too long in the package database file %s. (%s)", name
, line
);
767 #if ASSUME_BROKEN_PKGDB == 1
768 gchar
* sane_path
= path_simplify(line
);
769 if (sane_path
[0] == '\0')
771 JSLI(ptype
, p
->paths
, ".");
775 JSLI(ptype
, p
->paths
, sane_path
);
779 JSLI(ptype
, p
->paths
, line
);
787 while ((linelen
= getline(&line
, &size
, fs
)) >= 0)
789 if (linelen
> 0 && line
[linelen
-1] == '\n')
790 line
[linelen
-1] = '\0';
792 gchar
*dir
, *link
, *target
;
793 if (parse_createlink(line
, &dir
, &link
, &target
))
795 gchar
* path
= g_strdup_printf("%s/%s", dir
, link
);
796 gchar
* sane_path
= path_simplify(path
);
801 /* check path size limit */
802 if (strlen(sane_path
) >= MAXPATHLEN
)
804 strcpy(sane_path
+100, "...");
805 e_set(E_ERROR
, "Path too long in the package database script %s. (%s)", name
, sane_path
);
811 JSLI(ptype
, p
->paths
, sane_path
);
812 *ptype
= DB_PATH_SYMLINK
;
817 fseek(fs
, 0, SEEK_END
);
818 guint script_size
= ftell(fs
);
819 if (script_size
> 4*1024*1024)
821 e_set(E_ERROR
, "Script file is too big %s. (%u kB)", p
->name
, script_size
/ 1024);
826 p
->doinst
= g_malloc(script_size
);
827 fseek(fs
, 0, SEEK_SET
);
828 if (fread(p
->doinst
, script_size
, 1, fs
) != 1)
830 e_set(E_ERROR
, "Can't read script file %s. (%s)", p
->name
, strerror(errno
));
849 static gchar
* _get_date()
851 static gchar buf
[100];
852 time_t t
= time(NULL
);
853 struct tm
* ts
= localtime(&t
);
855 strftime(buf
, sizeof(buf
), "%F-%T", ts
);
857 strftime(buf
, sizeof(buf
), "%F,%T", ts
);
862 gint
db_rem_pkg(gchar
* name
)
870 e_set(E_BADARG
, "Package name can't be NULL.");
873 if (parse_pkgname(name
, 6) != (gchar
*)-1)
875 e_set(E_ERROR
, "Invalid package name. (%s)", name
);
881 e_set(E_FATAL
, "Can't remove packages from the database in the readonly mode.");
885 gchar
* p
= g_strdup_printf("%s/%s", _db
.pkgdir
, name
);
886 gchar
* s
= g_strdup_printf("%s/%s", _db
.scrdir
, name
);
887 gchar
* rp
= g_strdup_printf("%s/removed_packages/%s-removed-%s", _db
.topdir
, name
, _get_date());
888 gchar
* rs
= g_strdup_printf("%s/removed_scripts/%s-removed-%s", _db
.topdir
, name
, _get_date());
890 if (sys_file_type(p
, 1) != SYS_REG
)
892 e_set(E_ERROR
|DB_NOTEX
, "Package is not in the database. (%s)", name
);
896 if (access(rp
, 0) == 0)
899 if (rename(p
, rp
) < 0)
901 e_set(E_ERROR
, "Package file removal failed. (%s)", strerror(errno
));
904 if (sys_file_type(s
, 1) == SYS_REG
)
907 if (access(rs
, 0) == 0)
910 if (rename(s
, rs
) < 0)
912 e_set(E_ERROR
, "Script file removal failed. (%s)", strerror(errno
));
927 /* public - generic database package queries
928 ************************************************************************/
930 static gint
_query_compare(gconstpointer a
, gconstpointer b
, gpointer data
)
932 db_query_type type
= (db_query_type
)data
;
933 if (type
== DB_QUERY_PKGS_WITH_FILES
|| type
== DB_QUERY_PKGS_WITHOUT_FILES
)
935 const struct db_pkg
* apkg
= a
;
936 const struct db_pkg
* bpkg
= b
;
937 return strcmp(apkg
->name
, bpkg
->name
);
939 else if (type
== DB_QUERY_NAMES
)
946 GSList
* db_query(db_selector cb
, void* data
, db_query_type type
)
952 if (type
!= DB_QUERY_PKGS_WITH_FILES
&&
953 type
!= DB_QUERY_PKGS_WITHOUT_FILES
&&
954 type
!= DB_QUERY_NAMES
)
956 e_set(E_BADARG
, "Invalid query type.");
960 DIR* d
= opendir(_db
.pkgdir
);
963 e_set(E_FATAL
, "Can't open package database directory. (%s)", strerror(errno
));
968 while ((de
= readdir(d
)) != NULL
)
970 if (de
->d_name
[0] == '.')
973 gchar
* name
= de
->d_name
;
974 if (parse_pkgname(name
, 6) == NULL
)
976 /* if cb == NULL, then package matches */
979 /* otherwise get package from database ask the selector if it
980 likes this package */
981 p
= db_get_pkg(name
, DB_GET_WITHOUT_FILES
);
984 e_set(E_ERROR
, "Can't get package from the database. (%s)", name
);
987 gint rs
= cb(p
, data
);
988 if (rs
!= 0 && rs
!= 1)
991 e_set(E_ERROR
, "Package database query filter returned error. (%s)", name
);
1001 db_get_type get_type
= DB_GET_WITHOUT_FILES
;
1004 case DB_QUERY_PKGS_WITH_FILES
:
1005 get_type
= DB_GET_FULL
;
1006 case DB_QUERY_PKGS_WITHOUT_FILES
:
1007 p
= db_get_pkg(name
, get_type
);
1010 e_set(E_ERROR
, "Can't get package from the database (%s).", name
);
1013 pkgs
= g_slist_prepend(pkgs
, p
);
1015 case DB_QUERY_NAMES
:
1016 pkgs
= g_slist_prepend(pkgs
, g_strdup(name
));
1022 return g_slist_sort_with_data(pkgs
, _query_compare
, (gpointer
)type
);
1024 db_free_query(pkgs
, type
);
1030 void db_free_query(GSList
* pkgs
, db_query_type type
)
1035 void (*data_free_func
)(void*) = g_free
;
1036 if (type
== DB_QUERY_PKGS_WITH_FILES
||
1037 type
== DB_QUERY_PKGS_WITHOUT_FILES
)
1038 data_free_func
= (void (*)(void*))db_free_pkg
;
1040 g_slist_foreach(pkgs
, (GFunc
)data_free_func
, NULL
);
1044 gchar
* db_get_package_name(const gchar
* namespec
)
1046 _db_open_check(NULL
)
1048 if (namespec
== NULL
)
1050 e_set(E_FATAL
, "Namespec can't be NULL.");
1054 gchar
* pkgname
= NULL
;
1055 DIR* d
= opendir(_db
.pkgdir
);
1059 e_set(E_FATAL
, "Can't open package database directory. (%s)", strerror(errno
));
1063 /* first search for exact match if namespec looks like full name */
1064 gchar
* searched_name
= parse_pkgname(namespec
, 5);
1068 while ((de
= readdir(d
)) != NULL
)
1070 if (de
->d_name
[0] == '.')
1072 gchar
* cur_name
= de
->d_name
;
1073 if (parse_pkgname(cur_name
, 6) == NULL
)
1075 if (!strcmp(searched_name
, cur_name
))
1077 pkgname
= searched_name
;
1081 g_free(searched_name
);
1084 /* try to use namespec as shortname */
1086 while ((de
= readdir(d
)) != NULL
)
1088 if (de
->d_name
[0] == '.')
1090 gchar
* cur_name
= de
->d_name
;
1091 gchar
* cur_shortname
= parse_pkgname(cur_name
, 1);
1092 if (cur_shortname
== NULL
)
1094 if (!strcmp(namespec
, cur_shortname
))
1096 pkgname
= g_strdup(cur_name
);
1097 g_free(cur_shortname
);
1100 g_free(cur_shortname
);