<commit_before>#!/bin/bash -e

# Remove all temp files
function clean {
    `rm -f *.actual`
    `rm -f *.cdb`
}

# Compare file $1 to $2 and display diff if different
function compare {
    f=`diff -u "$1" "$2"`
    if [ $? != 0 ] ; then
        echo "$1 and $2 differ!"
        echo "$f"
        clean
        exit 128
    fi
}

# Query the database $1 using the cdb tool and echo results to $1.actual
function querydb {
    cdb -q "cache.cdb" "$1" > "$2.actual"
}

# Check the keys in the existing cache.cdb database
function dotest {
    querydb "KEYS" "KEYS"
    compare "KEYS.expected" "KEYS.actual"

    querydb "PROVIDERS" "PROVIDERS"
    compare "PROVIDERS.expected" "PROVIDERS.actual"

    querydb "org.freedesktop.ContextKit.contextd1:KEYS" "org.freedesktop.ContextKit.contextd1_KEYS"
    compare "org.freedesktop.ContextKit.contextd1_KEYS.expected" "org.freedesktop.ContextKit.contextd1_KEYS.actual"

    querydb "org.freedesktop.ContextKit.contextd2:KEYS" "org.freedesktop.ContextKit.contextd2_KEYS"
    compare "org.freedesktop.ContextKit.contextd2_KEYS.expected" "org.freedesktop.ContextKit.contextd2_KEYS.actual"

    querydb "Battery.Charging:KEYTYPE" "Battery.Charging_KEYTYPE"
    compare "Battery.Charging_KEYTYPE.expected" "Battery.Charging_KEYTYPE.actual"

    querydb "Battery.Charging:KEYDOC" "Battery.Charging_KEYDOC"
    compare "Battery.Charging_KEYDOC.expected" "Battery.Charging_KEYDOC.actual"

    querydb "Battery.Charging:KEYPROVIDER" "Battery.Charging_KEYPROVIDER"
    compare "Battery.Charging_KEYPROVIDER.expected" "Battery.Charging_KEYPROVIDER.actual"

    querydb "Battery.Charging:KEYBUS" "Battery.Charging_KEYBUS"
    compare "Battery.Charging_KEYBUS.expected" "Battery.Charging_KEYBUS.actual"
}

BASEDIR=`dirname $0`

# Test using command line param
../../update-contextkit-providers/update-contextkit-providers "./"
dotest
clean

# Test using env var 
export CONTEXT_PROVIDERS="./"
../../update-contextkit-providers/update-contextkit-providers
dotest
clean

echo "All ok!"
exit 0<commit_msg>A test for a recent bugfix in cache.cdb permissions.<commit_after>#!/bin/bash -e

# Remove all temp files
function clean {
    `rm -f *.actual`
    `rm -f *.cdb`
}

# Compare file $1 to $2 and display diff if different
function compare {
    f=`diff -u "$1" "$2"`
    if [ $? != 0 ] ; then
        echo "$1 and $2 differ!"
        echo "$f"
        clean
        exit 128
    fi
}

# Query the database $1 using the cdb tool and echo results to $1.actual
function querydb {
    cdb -q "cache.cdb" "$1" > "$2.actual"
}

# Check the keys in the existing cache.cdb database
function dotest {
    querydb "KEYS" "KEYS"
    compare "KEYS.expected" "KEYS.actual"

    querydb "PROVIDERS" "PROVIDERS"
    compare "PROVIDERS.expected" "PROVIDERS.actual"

    querydb "org.freedesktop.ContextKit.contextd1:KEYS" "org.freedesktop.ContextKit.contextd1_KEYS"
    compare "org.freedesktop.ContextKit.contextd1_KEYS.expected" "org.freedesktop.ContextKit.contextd1_KEYS.actual"

    querydb "org.freedesktop.ContextKit.contextd2:KEYS" "org.freedesktop.ContextKit.contextd2_KEYS"
    compare "org.freedesktop.ContextKit.contextd2_KEYS.expected" "org.freedesktop.ContextKit.contextd2_KEYS.actual"

    querydb "Battery.Charging:KEYTYPE" "Battery.Charging_KEYTYPE"
    compare "Battery.Charging_KEYTYPE.expected" "Battery.Charging_KEYTYPE.actual"

    querydb "Battery.Charging:KEYDOC" "Battery.Charging_KEYDOC"
    compare "Battery.Charging_KEYDOC.expected" "Battery.Charging_KEYDOC.actual"

    querydb "Battery.Charging:KEYPROVIDER" "Battery.Charging_KEYPROVIDER"
    compare "Battery.Charging_KEYPROVIDER.expected" "Battery.Charging_KEYPROVIDER.actual"

    querydb "Battery.Charging:KEYBUS" "Battery.Charging_KEYBUS"
    compare "Battery.Charging_KEYBUS.expected" "Battery.Charging_KEYBUS.actual"
}

# Ensure that the cache file permissions are ok
function checkperm {
    perms=`stat -c %a cache.cdb`
    if [ "$perms" != "644" ] ; then
        echo "Permissions of cache.db are not 644!"
        clean
        exit 128
    fi
}

BASEDIR=`dirname $0`

# Test using command line param
../../update-contextkit-providers/update-contextkit-providers "./"
dotest
checkperm
clean

# Test using env var 
export CONTEXT_PROVIDERS="./"
../../update-contextkit-providers/update-contextkit-providers
dotest
checkperm
clean

echo "All ok!"
exit 0
{'fraction_non_alphanumeric': 0.11552595314653193, 'fraction_numerical': 0.013091410197519523, 'mean_word_length': 3.9320498301245754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6440972', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1542, 'n_words': 330}