@@ -327,6 +327,74 @@ xbps_pkgpattern_version(const char *pkg)
327327 return strpbrk (pkg , "><*?[]" );
328328}
329329
330+ ssize_t
331+ xbps_pkg_path (struct xbps_handle * xhp , char * dst , size_t dstsz , xbps_dictionary_t pkgd )
332+ {
333+ const char * pkgver = NULL , * arch = NULL , * repoloc = NULL ;
334+ int l ;
335+
336+ if (!xbps_dictionary_get_cstring_nocopy (pkgd , "pkgver" , & pkgver ) ||
337+ !xbps_dictionary_get_cstring_nocopy (pkgd , "architecture" , & arch ) ||
338+ !xbps_dictionary_get_cstring_nocopy (pkgd , "repository" , & repoloc ))
339+ return - EINVAL ;
340+
341+ if (xbps_repository_is_remote (repoloc ))
342+ repoloc = xhp -> cachedir ;
343+
344+ l = snprintf (dst , dstsz , "%s/%s.%s.xbps" , repoloc , pkgver , arch );
345+ if (l < 0 || (size_t )l >= dstsz )
346+ return - ENOBUFS ;
347+
348+ return l ;
349+ }
350+
351+ ssize_t
352+ xbps_pkg_url (struct xbps_handle * xhp UNUSED , char * dst , size_t dstsz , xbps_dictionary_t pkgd )
353+ {
354+ const char * pkgver = NULL , * arch = NULL , * repoloc = NULL ;
355+ int l ;
356+
357+ if (!xbps_dictionary_get_cstring_nocopy (pkgd , "pkgver" , & pkgver ) ||
358+ !xbps_dictionary_get_cstring_nocopy (pkgd , "architecture" , & arch ) ||
359+ !xbps_dictionary_get_cstring_nocopy (pkgd , "repository" , & repoloc ))
360+ return - EINVAL ;
361+
362+ l = snprintf (dst , dstsz , "%s/%s.%s.xbps" , repoloc , pkgver , arch );
363+ if (l < 0 || (size_t )l >= dstsz )
364+ return - ENOBUFS ;
365+
366+ return l ;
367+ }
368+
369+ ssize_t
370+ xbps_pkg_path_or_url (struct xbps_handle * xhp UNUSED , char * dst , size_t dstsz , xbps_dictionary_t pkgd )
371+ {
372+ const char * pkgver = NULL , * arch = NULL , * repoloc = NULL ;
373+ int l ;
374+
375+ if (!xbps_dictionary_get_cstring_nocopy (pkgd , "pkgver" , & pkgver ) ||
376+ !xbps_dictionary_get_cstring_nocopy (pkgd , "architecture" , & arch ) ||
377+ !xbps_dictionary_get_cstring_nocopy (pkgd , "repository" , & repoloc ))
378+ return - EINVAL ;
379+
380+ if (xbps_repository_is_remote (repoloc )) {
381+ l = snprintf (dst , dstsz , "%s/%s.%s.xbps" , xhp -> cachedir ,
382+ pkgver , arch );
383+ if (l < 0 || (size_t )l >= dstsz )
384+ return - ENOBUFS ;
385+ if (access (dst , R_OK ) == 0 )
386+ return l ;
387+ if (errno != ENOENT )
388+ return - errno ;
389+ }
390+
391+ l = snprintf (dst , dstsz , "%s/%s.%s.xbps" , repoloc , pkgver , arch );
392+ if (l < 0 || (size_t )l >= dstsz )
393+ return - ENOBUFS ;
394+
395+ return l ;
396+ }
397+
330398char *
331399xbps_repository_pkg_path (struct xbps_handle * xhp , xbps_dictionary_t pkg_repod )
332400{
0 commit comments