11

I want to chmod recursively in my build.xml and borrowed the following from this post:

<chmod file="${basedir}/foo/**" perm="755" type="both"/>

It's unbelievably slow since that directory is deep and includes a large number of files.

This works much better & faster:

<exec executable="chmod" dir="${basedir}/foo" failonerror="true">
    <arg line="-R 0755 ." />
</exec>
  • Are there any downsides of using exec? Speed is of importance.
  • If yes; am I using chmod incorrectly?
Community
  • 1
  • 1
chelmertz
  • 20,399
  • 5
  • 40
  • 46

1 Answers1

8

Exec is faster because the chmod task is gathering all the files and then chmod'ng them. With exec it is one operation. The only "downside" to using exec is that it ties you to UNIX/Linux. I use quotes because the chmod task doesn't run on Windows anyway so this is a moot point.

You are using both correctly and going with exec makes sense.

Jeanne Boyarsky
  • 12,156
  • 2
  • 49
  • 59
  • I reread the man page again and I have to say that there doesn't seem to be any valid reason to use `chmod` apart from perhaps the easy syntax to exclude files from a fileset -- but that can easily be solved in `exec` as well. Would you use `chmod` for anything? :) – chelmertz Aug 04 '11 at 07:28
  • I would use the chmod task if I was changing permissions on one file or (as you noted) if I wanted to specify a complex (and small fileset). Possibly if that fileset already was referred to for something else in Ant. – Jeanne Boyarsky Aug 05 '11 at 00:01