about summary refs log tree commit diff
path: root/pkgs/stdenv/freebsd/unpack-source.sh
blob: aa5e89f05c2dbd616e2fa66619a78a230a97c674 (plain) (blame)
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
41
unpackCmdHooks+=(_FreeBSDUnpackSource)

_FreeBSDUnpackSource() {
    local fn="$1"
    local destination

    if [ -d "$fn" ]; then

        destination="$(stripHash "$fn")"

        if [ -e "$destination" ]; then
            echo "Cannot copy $fn to $destination: destination already exists!"
            echo "Did you specify two \"srcs\" with the same \"name\"?"
            return 1
        fi

        # We can't preserve hardlinks because they may have been
        # introduced by store optimization, which might break things
        # in the build.
        bsdcp -a -- "$fn" "$destination"
        chmod -R +w "$destination"

    else

        case "$fn" in
            *.tar.xz | *.tar.lzma | *.txz)
                # Don't rely on tar knowing about .xz.
                xz -d < "$fn" | tar xf - --warning=no-timestamp
                ;;
            *.tar | *.tar.* | *.tgz | *.tbz2 | *.tbz)
                # GNU tar can automatically select the decompression method
                # (info "(tar) gzip").
                tar xf "$fn" --warning=no-timestamp
                ;;
            *)
                return 1
                ;;
        esac

    fi
}