From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [OSSTEST PATCH 07/27] memoise: New utility Date: Wed, 16 Sep 2015 14:35:10 +0100 Message-ID: <1442410530-9665-8-git-send-email-ian.jackson@eu.citrix.com> References: <1442410530-9665-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZcCsP-0000nV-I8 for xen-devel@lists.xenproject.org; Wed, 16 Sep 2015 13:35:57 +0000 In-Reply-To: <1442410530-9665-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org Give this a GPLv2+ licence so that we can move it into some other FLOSS package later. Signed-off-by: Ian Jackson --- memoise | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 memoise diff --git a/memoise b/memoise new file mode 100755 index 0000000..ff999d5 --- /dev/null +++ b/memoise @@ -0,0 +1,56 @@ +#!/bin/sh +# +# memoise - a command line output memoisation tool +# +# usage: +# memoise datadir cmd arg arg ... +# +# will create datadir if necessary; delete datadir when you're done +# +# Copyright 2015 Citrix Inc. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# NB that the rest of osstest is AGPLv3+, so when this file is +# distributed together with osstest, the AGPLv3 applies. + +set -e + +case "$#.$1" in +[01].) echo >&2 "memoise: too few args"; exit 127 ;; +*.-) echo >&2 "memoise: unknown option $1"; exit 127 ;; +esac + +datadir=$1; shift + +mkdir -p -- "$datadir" + +id=`for arg in "$@"; do printf '%s\0' "$arg"; done | sha256sum` +id=${id% -} + +f="$datadir/$id" + +if ! [ -f "$f.o" ]; then + with-lock-ex -w "$f.l" sh -ec ' + f=$1; shift + if [ -f "$f.o" ]; then exit 0; fi + exec "$f.t" + "$@" + mv -- "$f.t" "$f.o" + rm "$f.l" + ' x "$f" "$@" +fi + +cat -- "$f.o" -- 1.7.10.4