• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

tar a directory (and subdirectories-files) using ant

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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" />

<target name="Main" depends="usage">

</target>

<target name="usage" depends="-Init">
<echo message="Usage message"/>
</target>

<target name="-Init" depends="-Prep">
<echo message="-Init target starts ..."/>
<tstamp/>
<echo message="Build time is ${TODAY} ${TSTAMP}" />
<echo message="-Init completed."/>
</target>

<target name="-Prep">
<!-- Delete output directory and all its content -->
<delete dir="${tar_dir_loc}"/>
<echo message="${tar_dir_loc} deleted."/>
<!-- Create output directory -->
<mkdir dir="${tar_dir_loc}"/>
<echo message="${tar_dir_loc} created."/>
<echo message="-Prep completed."/>
</target>

<target name="-FixLineFeed">
<!-- create unix line end version of input files -->
<echo message="-FixLineFeed begin"/>
<delete dir="${FixOutDir}"/>
<mkdir dir="${FixOutDir}"/>
<mkdir dir="../dst/tar/"/>
<copy todir="${FixOutDir}">
<fileset dir="${FixSource}"/>
</copy>
<fixcrlf srcDir="${FixOutDir}" eol="lf"/>
<echo message="-FixLineFeed complete"/>
</target>

<target name="ff" depends="-Init">
<property name="FixOutDir" value="../dst/work/ff"/>
<antcall target="-FixLineFeed">
<param name="FixSource" value="."/>
</antcall>
<property name="tarfile" value="../dst/tar/${tar_file_name}"/>
<delete file="${tarfile}"/>
<tar destfile="${tarfile}">

<tarfileset dir="${FixOutDir}/var"
prefix="var" dirmode="770" mode="770">
</tarfileset>
<tarfileset dir="${FixOutDir}/tmp"
prefix="tmp" dirmode="750" mode="750">
</tarfileset>
<tarfileset dir="${FixOutDir}/bin"
prefix="bin" dirmode="750" mode="750">
</tarfileset>
<tarfileset dir="${FixOutDir}/etc"
prefix="etc" dirmode="750" mode="750">
</tarfileset>
<tarfileset dir="${FixOutDir}/lib"
prefix="lib" dirmode="750" mode="750">
</tarfileset>

</tar>
<echo message="A new ${tarfile} has been created."/>
<echo message="Tar completed."/>
</target>

</project>

Never mind the fixlinefeed all it does is change files line feed from windows to unix like.

Thanks in advance
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Dan Marley
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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/**/*" />

thanks,

Dan
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can read about patterns in the ant explanation about directory-based tasks.

The common use of ** is to match any number of directories, as in *.java any number of directories under some.dir:

${some.dir}/**/*.java

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).

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic