'name is too long' (tarfile, python 2.2, Debian Woody)

L

Lars Behrens

Hi, Pythonistas!

I'm quite new to Python and have a problem with a simple backup script.

This code:

tar = tarfile.open('/home/lars/test.tar.gz', 'w:gz')
tar.addfile('/home/lars')

brings up the following error message:

**********************************************************************
/usr/lib/python2.2/site-packages/tarfile.py in addfile(self, tarinfo,
fileobj)
1289
1290 if not prefix or len(name) > LENGTH_NAME:
-> 1291 raise ValueError, "name is too long (>%d)" \
1292 % (LENGTH_NAME)
1293

ValueError: name is too long (>100)
**********************************************************************

Any hints for me?

Thanks in advance
Lars
 
H

Helmut Jarausch

Lars said:
Hi, Pythonistas!

I'm quite new to Python and have a problem with a simple backup script.

This code:

tar = tarfile.open('/home/lars/test.tar.gz', 'w:gz')
tar.addfile('/home/lars')

brings up the following error message:

**********************************************************************
/usr/lib/python2.2/site-packages/tarfile.py in addfile(self, tarinfo,
fileobj)
1289
1290 if not prefix or len(name) > LENGTH_NAME:
-> 1291 raise ValueError, "name is too long (>%d)" \
1292 % (LENGTH_NAME)
1293

ValueError: name is too long (>100)
**********************************************************************

The standard tar format allows only names (i.e. complete path) of 100
characters. So in your '/home/lars' are names (fully expanded) which are
longer.
Please have a look at the documentation of tarfile, there is an option
to store extended path names. Most other tar programs (like gnu-tar)
support these, as well.


--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
 
P

Peter Hansen

Lars said:
I found this in the tarfile doc:

-- snip --
posix=True
If True, create a POSIX 1003.1-1990 compliant archive. GNU extensions
are not used, because they are not part of the POSIX standard. This
limits the length of filenames to at most 256 and linknames to 100
characters. A ValueError is raised, if a pathname exceeds this limit. If
False, create a GNU tar compatible archive. It will not be POSIX
compliant, but can store pathnames of unlimited length.
-- snap --

So, I put this in my script:

tar.posix=True

before

tar.add('bla')

This seems to work. But honestly, I don't quite understand
what I did :-\

Perhaps this is a sign that the problem was really somewhere else. What
you say you did is not likely to have solved the problem given the
documentation above. It says that setting tar.posix to *False* would
allow longer path names, not the other way around. If you think you
just got longer names to work and your problems went away, you
are probably missing something here...

-Peter
 
L

Lars Behrens

Peter said:
Perhaps this is a sign that the problem was really somewhere else. What
you say you did is not likely to have solved the problem given the
documentation above. It says that setting tar.posix to *False* would
allow longer path names, not the other way around. If you think you
just got longer names to work and your problems went away, you
are probably missing something here...

Sorry, a typo, of course I set tar.posix to false.
Mea culpa...

Cheerz Lars
 
L

Lars Gustaebel

So, I put this in my script:

tar.posix=True

before

tar.add('bla')

This seems to work. But honestly, I don't quite understand what I did
:-\

The fact that it worked this time seems pure chance to me, it is likely to
fail in the future. For backup purposes you should definitely set
tar.posix=False to enable long pathnames in your tar file.
I also found out, that I can call tarfile.GNUTYPE_LONGNAME but what can
I do with it or how do I use it?

Any hints for me?

tarfile.GNUTYPE_LONGNAME is a constant for internal use only. You don't
need to handle long pathnames yourself. I admit that setting an attribute
to False to turn on a feature may seem a bit cumbersome, but once you got
used to it it feels okay ;-)
tarfile creates POSIX compliant tar files by default because they are more
portable. If you just want to make backups for your personal use you don't
need to bother, so turn off the POSIX mode.
 

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top