Tuesday, 4 January 2011

Doh!, Error "tar: .: Cannot utime: Operation not permitted" seen when expanding an archive

I saw this exception: -

tar: .: Cannot utime: Operation not permitted
tar: Exiting with failure status due to previous errors

earlier when expanding a TAR file ( DB2  9.7 as a matter of fact ) into the /tmp directory of my Ubuntu 10.10 boxen: -

cd /tmp
tar xvf /media/LenovoExternal/Products/DB297/db297linux32.tar

Googling about the exception is actually telling me that TAR cannot update the access and modification times of the files within the archive.

I was running this as a non-root user.

You can guess the rest ...

When I checked the permissions of /tmp, I saw: -

drwxrwxrwt  19 root   root     4096 2011-01-04 18:22 tmp/

which suggests, to my simple mind, that I have all the right permissions, although the directory is owned by root.

Needless to say, when I ran the command "as root": -

cd /tmp
sudo tar xvf /media/LenovoExternal/Products/DB297/db297linux32.tar

all was well.

I reproduced this in my home directory: -

mkdir ~/foo
chown root:root ~/foo
chmod a+w ~/foo
cd ~/foo
tar xvf /media/LenovoExternal/Products/DB297/db297linux32.tar

This suggests to me that, despite the global RWX permissions: -

drwxrwxrwx  6 root root 4096 2011-01-04 18:34 foo/

the TAR command barfs if it's asked to update the utime of files within a directory that the user does not own.

Interesting, que ?

7 comments:

Jeremy said...

You mentioned it can not updated the times "within the archive" ... whats the permissions on the archive? ie does your user or group have write permissions to the file, or only read?

Dave Hay said...

@Jeremy - sorry, my comment was poorly phrased. What I was trying to say was, as far as I can gather, the TAR command is trying to update the times on the directory into which I'm extracting the archive.

Setting a+w permissions to the archive itself ( which my user/group owns ) made no difference.

Changing the ownership of the directory into which I'm extracting "fixed" the problem.

Therefore, it's my assumption that TAR is trying to write something to the directory in terms of access/modification date/time, and is unable to do so because my user does not own the directory ( although it does have global rwx permissions to it ).

Clear as mud :-)

Erik Sorensen said...

seems like whenever I hit an error - your blog is on page 1 of google results :)

thanks for documenting it all - it is very helpful

olemoro said...

The -m option to tar removes the problem. File dates will be wrong though.

Nivedita said...

Thank you. This helped me resolve the issue.

Markus Wiegand said...

I just faced the same problem and fixed it by using a temp-dir for unpacking in the following mini-script:

cd /tmp
rm -rf .unpack
mkdir .unpack
tar -C .unpack -xf mytar.tar
mv .unpack/.* .unpack/* .
rm -rf .unpack


Since the new directory that is untared-to will belong to the current user, tar does not complaint about missing permissions for utime. Moving the files afterwards preserves mtime without needing extra permissions.

Dave Hay said...

@Markus - excellent, many thanks for sharing