Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
libs: Fixed #3274
Browse files Browse the repository at this point in the history
Keys with order zero or less are now sorted properly.
  • Loading branch information
bauhaus93 committed Aug 27, 2020
1 parent dfd4e3b commit 67e9c49
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/libs/meta/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,31 +873,38 @@ int keySetCTime (Key * key, time_t ctime)
int elektraKeyCmpOrder (const Key * ka, const Key * kb)
{

if (!ka && !kb) return 0;
if (ka == NULL && kb == NULL)
{
return 0;
}

if (ka && !kb) return 1;
if (ka != NULL && kb == NULL)
{
return 1;
}

if (!ka && kb) return -1;

int aorder = -1;
int border = -1;
if (ka == NULL && kb != NULL)
{
return -1;
}

const Key * kam = keyGetMeta (ka, "order");
const Key * kbm = keyGetMeta (kb, "order");

if (kam) aorder = atoi (keyString (kam));
if (kbm) border = atoi (keyString (kbm));

if (aorder >= 0 && border >= 0) return aorder - border;

if (aorder < 0 && border < 0) return 0;

if (aorder < 0 && border >= 0) return -1;

if (aorder >= 0 && border < 0) return 1;
if (kam == NULL && kbm == NULL)
{
return 0;
}
if (kam != NULL && kbm == NULL)
{
return 1;
}
if (kam == NULL && kbm != NULL)
{
return -1;
}

/* cannot happen anyway */
return 0;
return atoi (keyString (kam)) - atoi (keyString(kbm));
}


Expand Down

0 comments on commit 67e9c49

Please sign in to comment.