commit 4ecdd2249f95a3f9d01b5b1ab46a2a6069b26653
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Tue, 10 Mar 2015 00:53:52 +0100
initial commit
Diffstat:
9 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,2 @@
+test/*
+workload
diff --git a/glo b/glo
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+glocate -i "$@" | sort
+
diff --git a/glocate b/glocate
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+FILE="/home/files"
+
+# http://stackoverflow.com/a/10836225
+ARGS=$(printf " %q" "$@")
+
+# grep is slower with other locales, especially -i, so LC_ALL
+# use --line-buffered so it's easier to grep the output of this
+parallel -i \
+ bash -c "LC_ALL=C grep $ARGS {}" -- ${FILE}.?
+
diff --git a/old/glocate.gzip b/old/glocate.gzip
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+FILE="/home/files"
+
+# http://stackoverflow.com/a/10836225
+ARGS=$(printf " %q" "$@")
+
+# grep is slower with other locales, especially -i, so LC_ALL
+# use --line-buffered so it's easier to grep the output of this
+parallel -i \
+ bash -c "gunzip -dc {} | LC_ALL=C grep $ARGS" -- ${FILE}.?.gz
+
diff --git a/old/glocate.lz4 b/old/glocate.lz4
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+FILE="/home/files"
+
+# http://stackoverflow.com/a/10836225
+ARGS=$(printf " %q" "$@")
+
+# grep is slower with other locales, especially -i, so LC_ALL
+# use --line-buffered so it's easier to grep the output of this
+parallel -i \
+ bash -c "lz4 -dc {} | LC_ALL=C grep $ARGS" -- ${FILE}.?.lz4
+
diff --git a/old/glocate.pigz b/old/glocate.pigz
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+FILE="/home/files"
+
+# http://stackoverflow.com/a/10836225
+ARGS=$(printf " %q" "$@")
+
+# grep is slower with other locales, especially -i, so LC_ALL
+# use --line-buffered so it's easier to grep the output of this
+parallel -i \
+ bash -c "pigz -dc {} | LC_ALL=C grep $ARGS" -- ${FILE}.?.gz
+
diff --git a/old/read.sh b/old/read.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+
+#
+#FILE="${@: -1}"
+#set -- "${@:1:$(($#-1))}"
+#
+##lz4 -dck $FILE | LC_ALL=C grep "$@" > /dev/null
+#LC_ALL=C grep --line-buffered "$@" "$FILE"
+
diff --git a/old/write.sh b/old/write.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+lz4 2>/dev/null > "$FILE"
+
diff --git a/update b/update
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# adapted from /etc/cron.daily/locate in the Debian locate package
+
+# http://stackoverflow.com/a/19622569
+trap 'exit' ERR
+
+DEST="/home/files"
+NFILES="8" # must be <9 because of split
+
+if which on_ac_power >/dev/null 2>&1; then
+ ON_BATTERY=0
+ on_ac_power >/dev/null 2>&1 || ON_BATTERY=$?
+ if [ "$ON_BATTERY" -eq 1 ]; then
+ exit 0
+ fi
+fi
+
+# See ionice(1)
+if [ -x /usr/bin/ionice ] &&
+ /usr/bin/ionice -c3 true 2>/dev/null; then
+ IONICE="/usr/bin/ionice -c3"
+fi
+
+# http://unix.stackexchange.com/a/4849/
+flock --nonblock /run/glocate.daily.lock $IONICE \
+ find / \( -type d -printf "%p/\n" , -type f -print \) |
+ split -a 1 --numeric-suffixes=1 --additional-suffix=.tmp \
+ - ${DEST}. -nr/$NFILES
+for a in `seq 1 $a`
+do
+ # atomic
+ mv "${DEST}.${a}.tmp" "${DEST}.${a}"
+done
+