Thursday, December 8, 2011

cp --preserve doesn't work as expected under ubuntu 11.10

I have been struggling with a very strong issue after upgraded to Ubuntu 11.10 (Oneiric Ocelot), and finally found out this is from a low level error from ubuntu - the root cause is because cp command with the switch of -a when copy a folder doesn't work as expected of "-dR --preserve=all" from cp --help.
    #cp --help
    ...

    Mandatory arguments to long options are mandatory for short options too.
      -a, --archive                same as -dR --preserve=all
           --backup[=CONTROL]       make a backup of each existing destination file
    ...

Under Ubuntu 11.04, when copy folders, all the attributes will be preserved with the --preserve option, but with Ubuntu 11.10, some attributes will be lost.

Here is a simple test procedure.

Note: e-xiao is below to administrator group.
1. Create a folder say test
     #mkdir test
     #ls -all
       drwxr-xr-x   2 e-xiao e-xiao     4096 2011-12-08 23:14 test
2. Trying to cp it with -a.
     #cp -a test test1

Under Ubuntu 11.10,
     #ls -all
       drwx------   2 e-xiao e-xiao     4096 2011-12-08 23:14 test1

Yes, with the  --preserve=all option, you are still losing all attributes not owned by owner.
Not sure if this is from any policy changes from ubuntu, I tried to google the web, but yet found any useful information so far :(

[Workaround]
1. Use "--backup -R" options
2. Use "-dR" only without "--preserve" option