How to keep directory permissions with cpio ?

C, C++, Python, Perl, Shell, etc.

How to keep directory permissions with cpio ?

Postby olivier » 26 Aug 2009, 15:47

Hi,

Under my NanoBSD system, I need to copy all files and directories (that are differents from a reference).
And because the destinations directories don't exist, I'm using cpio.

Here is an extract of my shell script:

Code: Select all
(
    cd /etc
    for i in "$@" `find * -type f`
    do
        if [ -f /cfg/$i ]
        then
            cmp -s /etc/$i /cfg/$i || cp -pfv /etc/$i /cfg/$i 2>/dev/null
        else
            cmp -s /conf/base/etc/$i /etc/$i || (find $i -print | cpio -dumpv /cfg/ 2>/dev/null)
        fi
    done
)


This script compare the file between /cfg and /etc, or /conf/base/etc and /etc and copy all modified file to /cfg.

The problem is that cpio don't preserve directory permission:
Code: Select all
[root@router]~#ls -alh /conf/base/etc | grep local
drwxr-xr-x   6 root  wheel      512B Aug 25 21:08 local
[root@router]~#ls -alh /cfg | grep local
drwx------   3 root  wheel   512B Aug 26 15:39 local

And I didn't find what cpio parameter to use for keeping permission.
I've tried to add "-depth" option to find (as reported here), but no changes.

Anyone have an idea ?

Thanks
olivier
Junior Member
 
Posts: 38
Joined: 16 Nov 2008, 19:26
Location: France

Postby vivek » 26 Aug 2009, 15:52

Look at -o and -i option.

Permissions of the files will be the same as the permissions associated with the files copied out using cpio -o.
Neither in this world nor elsewhere is there any happiness in store for him who always doubts. If you enjoyed my answer please consider donating some money to FreeBSD foundation @ http://www.freebsdfoundation.org/
User avatar
vivek
Member
 
Posts: 809
Joined: 17 Nov 2008, 08:19
Location: Hyper Space

Postby olivier » 26 Aug 2009, 20:24

I've the problem by replacing this line:
Code: Select all
for i in "$@" `find * -type f`

by:
Code: Select all
for i in "$@" `find * -depth`
olivier
Junior Member
 
Posts: 38
Joined: 16 Nov 2008, 19:26
Location: France


Return to Userland Programming & Scripting

Who is online

Users browsing this forum: No registered users and 0 guests