#!/bin/sh

# Copyright (C) 2016-2019 Junjiro R. Okajima
#
# This program, aufs 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 St, Fifth Floor, Boston, MA  02110-1301  USA

# usage: $0 inum_list dir list|cpup

tmp=/tmp/$$
set -eu
rc=${DebugRc:-/etc/default/aufs}
. $rc

inum=$1
dir=$2
action=$3

# build the grep pattern
sed -e 's/^/^/' $inum > $tmp.inum

Find()
{
	find $dir -xdev -name $AUFS_WH_PLINKDIR -prune \
		-o -printf "%i %p\0" | #2> /dev/null |
	grep -z -w -f $tmp.inum |
	sed -e 's/^[0-9][0-9]* //g' -e 's/\x00[0-9][0-9]* /\x00/g'
}

err=0
case $3 in
list)
	Find |
	tr '\0' '\n'
	;;
cpup)
	Find |
	xargs -r0 touch -ac
	;;
*)
	echo Usage
	err=1
	;;
esac

rm -fr $tmp $tmp.*
exit $err
