This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I want to tar a directory and all it's subs and files using ant. my directory structure looks like this:
A--- bin etc sconf var logs lib tmp
bin, lib and tmp are empty directories. while taring everything I want to set directory modes and file modes too. The problem is when I do that the empty directories are not included in the tar and the unix permission modes are not set.
This is my code:
<?xml version="1.0" encoding="ISO-8859-1"?> <project name="test" basedir="." default="Main"> <description> Build a tar file which includes all the directories and files under "test" </description> <property name="tar_dir_loc" location="tar"/> <property name="tar_file_name" value="ff.tar" />
The unix permissions part worked fine for me using your build.xml.
The way you are using tarfilesets with the prefix it looks like it would not include the directory unless there was something in it.
I made changes to bin and lib to get them included, using an include that specifies the dir rather than the prefix you were using. (If you need to change the name you could do that when you do the copy.) I changed tmp to try another include, but it doesn't include tmp unless there's something in it; it did include an empty subdir in tmp after I created that.
Check tar contents and compare permissions to one of the original files. [code] /u/x/build-stuff/tarcheck/tar> tar tvf ff.tar -rwxrwx--- 0/0 0 Apr 6 08:40 2005 var/var.txt drwxr-x--- 0/0 0 Apr 6 09:17 2005 bin/ drwxr-x--- 0/0 0 Apr 6 09:17 2005 bin/other/ -rwxr-x--- 0/0 0 Apr 6 08:40 2005 etc/etc.txt drwxr-x--- 0/0 0 Apr 6 09:17 2005 lib/ drwxr-x--- 0/0 0 Apr 6 09:17 2005 lib/libother/
(tmp not included unless it has a subdirectory, even an empty subdir): /u/x/build-stuff/tarcheck/tar> mkdir tmp/tmpother (run ant again) /u/x/build-stuff/tarcheck/tar> tar tvf ff.tar -rwxrwx--- 0/0 0 Apr 6 08:40 2005 var/var.txt drwxr-x--- 0/0 0 Apr 6 09:20 2005 tmp/tmpother/ drwxr-x--- 0/0 0 Apr 6 09:17 2005 bin/ drwxr-x--- 0/0 0 Apr 6 09:17 2005 bin/other/ -rwxr-x--- 0/0 0 Apr 6 08:40 2005 etc/etc.txt drwxr-x--- 0/0 0 Apr 6 09:17 2005 lib/ drwxr-x--- 0/0 0 Apr 6 09:17 2005 lib/libother/
/u/x/build-stuff/tarcheck/tar> cd .. /u/x/build-stuff/tarcheck> ls -l var total 16 drwxrwxr-x 2 x users 4096 Apr 6 08:40 ./ drwxrwxr-x 10 x users 4096 Apr 6 09:06 ../ -rw-rw-r-- 1 x users 0 Apr 6 08:40 var.txt /u/x/build-stuff/tarcheck> [code] [ April 06, 2005: Message edited by: Carol Enderlin ]
Joined: Apr 06, 2005
Thanks carol for the reply.
your solution worked I can include empty sub directories too.
I was wondering though what the difference is between <include name="lib/**" /> <include name="lib/**/*" />
The common use of ** is to match any number of directories, as in *.java any number of directories under some.dir:
For the specific example you are asking about, maybe there isn't any difference between those two. I was just trying to get something to work quickly. I've always thought of ** as any number of directories, we pretty much use it in the "middle" of a pattern. At the end of a pattern it seems to mean more than any number of directories,
Quote from URL I included:
org/apache/jakarta/** Matches all files in the org/apache/jakarta directory tree. Matches: org/apache/jakarta/tools/ant/docs/index.html org/apache/jakarta/test.xml
But not: org/apache/xyz.java
(jakarta/ part is missing).
subject: tar a directory (and subdirectories-files) using ant