Skip to content

Commit

Permalink
pkg-clean: fix logic for 'latest version'
Browse files Browse the repository at this point in the history
36dfb48 adjusted the cache logic to use tilde as a separator, which
broke pkg-clean's "latest version" logic. Update pkg-clean to use the
correct separator, but this may be a good candidate for moving to
libpkg.
  • Loading branch information
kevans91 authored and bapt committed Mar 2, 2021
1 parent ff879d6 commit 622b4ca
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/clean.c
Expand Up @@ -180,27 +180,27 @@ populate_sums(struct pkgdb *db)
}

/*
* Extract hash from filename in format <name>-<version>-<hash>.txz
* Extract hash from filename in format <name>-<version>~<hash>.txz
*/
static bool
extract_filename_sum(const char *fname, char sum[])
{
const char *dash_pos, *dot_pos;
const char *tilde_pos, *dot_pos;

dot_pos = strrchr(fname, '.');
if (dot_pos == NULL)
dot_pos = fname + strlen(fname);

dash_pos = strrchr(fname, '-');
if (dash_pos == NULL)
tilde_pos = strrchr(fname, '~');
if (tilde_pos == NULL)
return (false);
else if (dot_pos < dash_pos)
else if (dot_pos < tilde_pos)
dot_pos = fname + strlen(fname);

if (dot_pos - dash_pos != PKG_FILE_CKSUM_CHARS + 1)
if (dot_pos - tilde_pos != PKG_FILE_CKSUM_CHARS + 1)
return (false);

strlcpy(sum, dash_pos + 1, PKG_FILE_CKSUM_CHARS + 1);
strlcpy(sum, tilde_pos + 1, PKG_FILE_CKSUM_CHARS + 1);
return (true);
}

Expand Down

0 comments on commit 622b4ca

Please sign in to comment.