[Pythonmac-SIG] Adding resource fork support to tarfile.py

David M. Cooke cookedm at physics.mcmaster.ca
Wed Jul 19 00:45:42 CEST 2006


On Jul 18, 2006, at 17:17 , Apple Consultants Network wrote:

> Dear List,
>
> I am new to the list and new to python, so please be kind :)  I've  
> recently started playing with duplicity (http:// 
> duplicity.nongnu.org) and really like the feature set that is  
> offered by the project.  However, I am being stung by the thorn in  
> Apple's side; resource forks.  duplicity uses a copy of tarfile.py  
> to build the tar archives.  And since this file does not call OS  
> X's tar, nor does it have support for resource forks, it will only  
> add data forks to the tar archive.
>
> So, I started looking around and found that OS X has a tarfile.py  
> (System/Library/Frameworks/Python.framework/Versions/2.3/lib/ 
> python2.3/) as part of the standard python install.  This  
> tarfile.py is different from the one distributed by duplicity, and  
> at first I though I would use it in the distribution.  However,  
> using this default install shows that it too does not respect  
> resource forks.  For example, doing a simple:
>
> #!/usr/bin/python
>
> import tarfile
>
> tar = tarfile.open("sample.tar", "w")
> for name in ["Arial"]:
>         tar.add(name)
> tar.close()
>
> produces a tar file with only the data fork.  The resource fork is  
> lost.  In the case of fonts, this is bad.

You've got to explicitly handle the resource fork yourself. The tar  
format (AFAIK) doesn't support any notion of extra metadata or forks  
of a file. Tiger's tar fakes it by saving the resource fork as a  
separate file   with '._' added to the front (e.g., for 'hello.font',  
it stores the data fork as 'hello.font', and the resource fork as  
'._hello.font').

I've attached two scripts I wrote a while ago that handle the  
resource forks in this way.

-- 
|>|\/|<
/------------------------------------------------------------------\
|David M. Cooke              http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca
-------------- next part --------------
A non-text attachment was scrubbed...
Name: maketar.py
Type: text/x-python-script
Size: 1917 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20060718/fe4e208f/attachment-0002.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: extar.py
Type: text/x-python-script
Size: 836 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20060718/fe4e208f/attachment-0003.bin 
-------------- next part --------------



More information about the Pythonmac-SIG mailing list