ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Hatcher" <jakarta-...@ehatchersolutions.com>
Subject Re: chmod on windows
Date Tue, 04 Jun 2002 12:26:25 GMT
Here is how I did set the read-only flag that worked on both Unix and
Windows.  Not pretty, but it works.  (and even shows off the
ReadOnlySelector I created!)

<?xml version="1.0" ?>
<project name="selectors" default="main">

  <property name="build.dir" location="build"/>
  <property name="temp.dir" location="${build.dir}/temp"/>
  <property name="src.dir" location="src"/>
  <property name="data.dir" location="data"/>

  <target name="init">
    <mkdir dir="${build.dir}"/>

    <condition property="is.windows">
      <os family="windows"/>
    </condition>
  </target>

  <target name="clean">
    <delete dir="${build.dir}"/>
  </target>

  <target name="compile" depends="init">
    <javac srcdir="${src.dir}" destdir="${build.dir}"/>
  </target>

  <target name="setup-test-init">
    <delete dir="${temp.dir}"/>
    <mkdir dir="${temp.dir}"/>

    <delete dir="${data.dir}"/>
    <mkdir dir="${data.dir}"/>

    <echo file="${data.dir}/writable.dat">writable</echo>
    <echo file="${data.dir}/nonwritable.dat">nonwritable</echo>
  </target>

  <target name="setup-test-windows" if="is.windows">
    <exec executable="cmd.exe">
      <arg line="/c attrib +R"/>
      <arg file="${data.dir}/nonwritable.dat"/>
    </exec>
    <exec executable="cmd.exe">
      <arg line="/c attrib -R"/>
      <arg file="${data.dir}/writable.dat"/>
    </exec>
  </target>

  <target name="setup-test" depends="setup-test-init,setup-test-windows">
    <chmod file="${data.dir}/nonwritable.dat" perm="u-r"/>
    <chmod file="${data.dir}/writable.dat" perm="u+r"/>
  </target>

  <target name="test" depends="compile,setup-test">

    <selector id="selector">
      <custom classname="org.example.antbook.ReadOnlySelector"
classpath="${build.dir}"/>
    </selector>

    <copy todir="${temp.dir}">
      <fileset dir="${data.dir}">
        <selector refid="selector"/>
      </fileset>
    </copy>

    <available file="${temp.dir}/writable.dat" property="test.failed"/>
    <fail if="test.failed">Failed!  Writable file copied!</fail>
    <echo>Test passed</echo>
  </target>

  <target name="main" depends="test"/>

</project>



----- Original Message -----
From: "Rum Pel" <rum_pel@hotmail.com>
To: "Sebastien Diot" <s.diot@eurodata.de>
Cc: "Ant Users List" <ant-user@jakarta.apache.org>
Sent: Tuesday, June 04, 2002 6:01 AM
Subject: Re: chmod on windows


>
> -----
>
> > I meant that you can change read-only (and maybe some other) attributes
> > with "attrib", but that you can't change the "executable" attribute,
> > because it just doesn't exists under Windows.
> >
>
> You are right, and I am not bothered about the executable attribute but
> the "read attribute" which windows supports.
> I just want to make a file read-only(and vice-versa), is there a platform
> independant
> way to do this?
>
> --rp
>
> --
> To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message