The native Mac file system, HFS Plus, supports two forks (independent data streams) called the data fork and the resource fork. Mercurial can only handle the data fork, and if you attempt to commit a two-fork file, only the data fork will be recorded. Mac programmers adopting Mercurial must consider how to handle this limitation.

The contents of the resource fork, if any, is structured data that programs read and write using the Resource Manager APIs. However, Resource Manager data is sometimes stored in the data fork. Therefore, while a nonempty resource fork is always a resource file, a resource file is not necessarily a resource fork.

We can roughly group files with resource forks into 3 types:

The first kind, true two-fork files, are the most problematic, but becoming fairly rare. If you wish to preserve such files in a Mercurial archive, you will need to encode them somehow, perhaps in zip archives or using the applesingle command.

In the case of expendable resources, you might choose to just forget about them.

A pure resource fork file can usually be converted to a data fork resource file without any loss of functionality. To find pure resource fork files in the current directory hierarchy, you can use this command:

find . -type f -exec [ -s "{}/..namedfork/rsrc" -a ! -s "{}" ] \; -print

You can convert pure resource fork files to data fork resource files with the following shell script.

if [ $# -eq 0  -o  $# -gt 2 ] ; then
        echo "Usage: RsrcToData srcAndDestFile"
        echo "  or"
        echo "       RsrcToData srcFile destFile"
        exit 1
elif [ ! -s "$1/..namedfork/rsrc" ] ; then
        echo "no resource fork!"
        exit 2
elif [ -s "$1" ] ; then
        echo "nonempty data fork!"
        exit 3
elif [ $# -eq 1 ] ; then
        cat "$1/..namedfork/rsrc" > "$1"
        cat /dev/null > "$1/..namedfork/rsrc"
elif [ $# -eq 2 ] ; then
        cat "$1/..namedfork/rsrc" > "$2"
fi

exit 0


CategoryTipsAndTricks