You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Tuomo L <tl...@cc.hut.fi> on 2004/03/15 16:10:26 UTC

Deleting original files after ZipArchiveSerialization

Hi,

I'm using the ZipArchiveSerializer to zip up some files. I need to give
the user an option to check a box saying "Delete original files after
compression". I wrote a FileDeleteAction, which uses
org.apache.avalon.excalibur.io.FileUtil.forceDelete method to delete these
files. The action works separately just fine, but when trying to run it
inside the same request where ZipArchiveSerialization happens, I get an
error indicating that the file(s) couldn't  be deleted. It seems that they
are still locked for reading by the serializer.

Could someone please check, that the serializer closes all streams etc.
correctly, or what else might be the problem?

<map:match uri="foobar.zip">
  <map:generate src="some-entries.xml"/>
  <map:serialize type="zip"/>
</map:match>

<map:match uri="compress-and-delete">
  <map:act type="do-something-with-the-zip-file">
    <map:parameter name="src" value="cocoon:/foobar.zip"/>
    <map:act type="file-delete">
      <map:parameter name="src" value="path-to-the-originals"/>
    </map:ac>
  </map:act>
</map:match>


-Tuomo

Re: Deleting original files after ZipArchiveSerialization

Posted by Upayavira <uv...@upaya.co.uk>.
This won't work. Actions are performed whilst the pipeline is built, 
before it is executed. Therefore, you're trying to delete a file before 
it has been used by the pipeline. So whatever your immediate problem is, 
you've got a bigger one! I guess I'd extend the ZipArchiveSerialiser and 
give it the functionality to do a deletion itself, or, better - come up 
with something using flow to handle this particular bit of logic.

Regards, Upayavira

Tuomo L wrote:

>Hi,
>
>I'm using the ZipArchiveSerializer to zip up some files. I need to give
>the user an option to check a box saying "Delete original files after
>compression". I wrote a FileDeleteAction, which uses
>org.apache.avalon.excalibur.io.FileUtil.forceDelete method to delete these
>files. The action works separately just fine, but when trying to run it
>inside the same request where ZipArchiveSerialization happens, I get an
>error indicating that the file(s) couldn't  be deleted. It seems that they
>are still locked for reading by the serializer.
>
>Could someone please check, that the serializer closes all streams etc.
>correctly, or what else might be the problem?
>
><map:match uri="foobar.zip">
>  <map:generate src="some-entries.xml"/>
>  <map:serialize type="zip"/>
></map:match>
>
><map:match uri="compress-and-delete">
>  <map:act type="do-something-with-the-zip-file">
>    <map:parameter name="src" value="cocoon:/foobar.zip"/>
>    <map:act type="file-delete">
>      <map:parameter name="src" value="path-to-the-originals"/>
>    </map:ac>
>  </map:act>
></map:match>
>
>
>-Tuomo
>
>  
>