}
ResourceIterator iter = getResources();
if ( !iter.hasNext() && !hasVirtualFiles() )
{
throw new ArchiverException( "You must set at least one file." );
}
zipFile = getDestFile();
if ( zipFile == null )
{
throw new ArchiverException( "You must set the destination " + archiveType + "file." );
}
if ( zipFile.exists() && !zipFile.isFile() )
{
throw new ArchiverException( zipFile + " isn't a file." );
}
if ( zipFile.exists() && !zipFile.canWrite() )
{
throw new ArchiverException( zipFile + " is read-only." );
}
// Whether or not an actual update is required -
// we don't need to update if the original file doesn't exist
addingNewFiles = true;
if ( doUpdate && !zipFile.exists() )
{
doUpdate = false;
getLogger().debug( "ignoring update attribute as " + archiveType + " doesn't exist." );
}
success = false;
if ( doUpdate )
{
renamedFile = FileUtils.createTempFile( "zip", ".tmp", zipFile.getParentFile() );
renamedFile.deleteOnExit();
try
{
FileUtils.rename( zipFile, renamedFile );
}
catch ( SecurityException e )
{
getLogger().debug( e.toString() );
throw new ArchiverException( "Not allowed to rename old file (" + zipFile.getAbsolutePath()
+ ") to temporary file", e );
}
catch ( IOException e )
{
getLogger().debug( e.toString() );
throw new ArchiverException( "Unable to rename old file (" + zipFile.getAbsolutePath()
+ ") to temporary file", e );
}
}
String action = doUpdate ? "Updating " : "Building ";