Issues with the 'find' command and packages

Programming, for all ages and all languages.
Post Reply
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Issues with the 'find' command and packages

Post by Stevo14 »

In order to make "installation" of my OS into a disk image simpler, I've decided to make a little package system. Basically each component creates a tarball of itself which is unpacked in the root of my OS's file system.

I'm having problems building the tarball's so that they exclude .svn dir's. Mainly problems with the 'find' command. In my makefile I have the line:

Code: Select all

PKGFILES  := $(shell cd package && find -mindepth 1 \! \( -name '.svn' -prune \) -print)
which is supposed to find all the files in the package directory excluding anything related to svn. Later I have:

Code: Select all

dist: 
	@tar czf fluidium.pkg.tgz -C package $(PKGFILES) 
Which actually creates the package. The problem is that only the .svn directories in the first level are excluded. .svn directories in the second and third levels remain in the tarball. Would someone mind giving me a clue as to how to get the "\( -name '.svn' -prune \)" to apply to more than just the first level directory?

Also, for some reason this method makes it so that the first directory in the archive is simply ".". This really isn't a problem because it expands properly to "./*" when unpacked but it is an annoyance.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Issues with the 'find' command and packages

Post by JamesM »

Hi,

Haven't checked this solution, but this is what I'd do:

Code: Select all

PKGFILES  := $(shell cd package && find -mindepth 1 -print | grep -v ".svn")
Cheers,

James
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Issues with the 'find' command and packages

Post by Solar »

Your find works mostly as intended, and excludes all .svn directories. (You can easily check this if you execute it stand-alone.)

Your problem is that it also includes directories - and that tar is recursive. Your find lists all files and directories, and tar includes those directories with all their contents - including .svn subdirectories...

You could add "-type f" to your find to exclude directories. Or you could simply:

Code: Select all

dist:
   @tar czf fluidium.pkg.tgz --exclude .svn -C package *
Every good solution is obvious once you've found it.
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Issues with the 'find' command and packages

Post by Stevo14 »

Solar, your second solution did what I wanted. I just realized that the answer was in the tar man pages all along... #-o

Well, thanks anyway for the help. :)
Post Reply