summaryrefslogtreecommitdiff
path: root/vsvs-extract
blob: d5a167e8f73918a19d62310f60ba480fe2fb66c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
after () { test -z "${2##*$1*}" && echo -n "${2#*$1}"; }
res="$(vsvs-locate "$2" || exit 1)"
path="${res%% *}"
vsvspath=$(after " " "$res")
if test -f "$path"
then
    lockfile="$base/proc/$proc/lock/"
    if test "${path::1}" == "."
    then lockfile="$lockfile$base$path"
    else lockfile="$lockfile$path"
    fi
    mkdir -p -- "${lockfile%/*}"
    echo $proc > $lockfile
    lockpath="$path.lock"
    ln $lockfile $lockpath || exit 1 # Error, cannot lock
    data="$(cat $path)"
    rm $lockpath
    rm $lockfile
    until test -z "$vsvspath"
    do
        data="$(echo "$data" | vsvs-parse "test \"\$key\" == \"${vsvspath%%/*}\" && echo \"\$value\" && exit 0")"
        vsvspath=$(after / "$vsvspath")
    done
    echo "$data" | vsvs-parse "$1"
else
    for key in `ls -a $path`
    do
        test "$key" == "." || test "$key" == ".." && continue
        if test -f "$path/$key"
        then value=$(cat "$path/$key")
        else
            savedpath=$(pwd)
            cd "$path/$key"
            value=$(vsvs-archive)
            cd "$savedpath"
        fi
        eval "$1"
    done
fi