Home » Computing » Programming » Checking for a Mac resource fork

Checking for a Mac resource fork

Following a mishap with a backup some time ago in which I lost the contents of my text clippings, I have started investigating resource fork detection for my rsync pre-processor.

The pre-processor will eventually be python-based, with a couple of extra scripts for platform-specific operations that arise. I need it to be able to backup using rsync or some Windows backup program with equivalent functions, to a FAT32 target, without any data loss.

Pre-processing the backup source directory includes:

  • split files greater than 4 GB into individual chunks – for backing up to FAT32 drives
    • mark chunks for use in restore process
    • use an exclusion for file sizes greater than 4 GB
    • remove chunks post sync
  • OS X specific – detect files with resource forks
    • determine if a child of a grouped directory, if so bubble up to grouped directory and tar-gz
    • else tar-gz the file itself
    • add the original file/directory to rsync exclusion list
    • remove the tar-gz post-sync
  • build a database of current tree state – to “detect” moved files and reduce transfer time
    • build hardlink repository of all files in the source directory
    • replace previous state database with current tree state and remove hardlink repo post-sync

From the restoration side, re-building the chunks and unpacking the tar’d files need to be handled.

For detecting resource forks on Mac, this script should work:

MYFILE="$1/..namedfork/rsrc"
if [ "old"$(sw_vers | grep -Po "10\.[0-6]\.") = "old" ]; then
    MYFILE="$1/rsrc" # different format pre-10.7
fi

FOUNDRES=yes$(ls -l "$MYFILE" | grep -Po "0\s+[0-9]+\s+[a-zA-Z]");
# resource fork found to be zero length - returns string

# FOUNDRES is exactly "yes" if resource is non-zero
if [ "$FOUNDRES" = "yes" ]; then
    echo "RSRC present on $MYFILE"
else
    echo "RSRC absent from $MYFILE"
fi

Use at will.

Posted in Programming

Leave a Reply

Your email address will not be published. Required fields are marked *