Differences between revisions 1 and 2
Revision 1 as of 2008-05-18 00:26:19
Size: 2481
Editor: JamesWalker
Comment: new page
Revision 2 as of 2008-05-18 02:53:39
Size: 2606
Editor: JamesWalker
Comment: improved shell script
Deletions are marked like this. Additions are marked like this.
Line 23: Line 23:
You can convert pure resource fork files to data fork resource files with the following shell script.  ''Do not'' use this script on true two-fork files. You can convert pure resource fork files to data fork resource files with the following shell script.
Line 28: Line 28:
if [ $# -eq 1 ] ; then 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
Line 33: Line 44:
else
 echo "Usage: RsrcToData srcAndDestFile"
 echo " or"
 echo " RsrcToData srcFile destFile"
 exit 1

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:

  • Files in which both forks are nonempty and important. These include applications and shared libraries in the old pre-Intel-Mac CFM format, and some older document formats.

  • Data files with a few inessential resources. Examples: an image file with a thumbnail icon as a resource, a text file with a resource recording a preferred font, or a document file with a resource recording a preferred application to open it.

  • Resource files with empty data forks. Typically these would be hidden inside an application package, or merged with other resource data by a development build system.

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

HandlingMacResourceFiles (last edited 2021-01-01 20:36:34 by DanVilliomPodlaskiChristiansen)