<commit_before>confdir="/etc/dockerctl"
. ${confdir}/config
. /usr/share/dockerctl/functions

set -x

function extract_patch_files() {
	sed -nr '/\+{3}/ {s,\+{3} (b/)?([^\t]+).*,\2,g;p}'
} 

function extract_files_from_docker() {
	local container_name=$1
	shift
	shell_container ${container_name} tar cvf - $*
} 

function put_files_to_docker() {
	local container_name=$1
	local prefix=$2
	local source=$3
	(cd ${source} && tar cvf - * ) | shell_container ${container_name} tar -xv --overwrite -f - -C ${prefix} 
} 

# example docker_patch cobbler / patches/hostname.patch patches/another.patch
function do_docker_patch() {
	local container=$1
	local prefix=$2
	shift 2
	local patchs=$*

	list_containers | egrep -q "^${container}$" || {
		echo "Container $container not found" > /dev/stderr
		return
	} 

	for p in $patchs; do
		test -f $p || {
			echo "Patch $p not found" > /dev/stderr
			return
		} 
	done


	patch_dir=$(mktemp -d /tmp/docker_patch.XXXXXXX)


	patch_files=`cat $patchs | extract_patch_files | sed -r "/^[^\/]/ { s ^ ${prefix}/ g }"`
	prefix=`dirname $patch_files`

<commit_msg>Check md5sum for patching files<commit_after>confdir="/etc/dockerctl"
. ${confdir}/config
. /usr/share/dockerctl/functions

set -x

function extract_patch_files() {
	sed -nr '/\+{3}/ {s,\+{3} (b/)?([^\t]+).*,\2,g;p}'
} 

function extract_files_from_docker() {
	local container_name=$1
	shift
	shell_container ${container_name} tar cvf - $*
} 

function compare_files() {
	local container=$1
	local prefix=$2
	local file="/"$3
	local local_md5sum=`md5sum ${prefix}/${file} | cut -d" " -f1`
	local container_md5sum=`dockerctl shell ${container} md5sum ${file} | cut -d" " -f1`
	test "${local_md5sum}" = "${container_md5sum}"
	
	
} 

function put_files_to_docker() {
	local container_name=$1
	local prefix=/
	local source=$3
	local f=""
	(cd ${source} && tar cvf - *) | shell_container ${container_name} tar -xv --overwrite -f - -C ${prefix} 
	for f in `(cd ${source} && find . -type f)`; do
		compare_files ${container_name} ${source} ${f} || {
			echo "${container_name}/${f} invalid md5sum"
			exit 2
		} 
	done
	
} 

# example docker_patch cobbler / patches/hostname.patch patches/another.patch
function do_docker_patch() {
	local container=$1
	local prefix=$2
	shift 2
	local patchs=$*

	list_containers | egrep -q "^${container}$" || {
		echo "Container $container not found" > /dev/stderr
		return
	} 

	for p in $patchs; do
		test -f $p || {
			echo "Patch $p not found" > /dev/stderr
			return
		} 
	done


	patch_dir=$(mktemp -d /tmp/docker_patch.XXXXXXX)


	patch_files=`cat $patchs | extract_patch_files | sed -r "/^[^\/]/ { s ^ ${prefix}/ g }"`
	prefix=`dirname $patch_files`


{'fraction_non_alphanumeric': 0.1713221601489758, 'fraction_numerical': 0.012290502793296089, 'mean_word_length': 3.7964285714285713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4512873', 'n_tokens_mistral': 1068, 'n_tokens_neox': 985, 'n_words': 244}