blob: 1a0de0567d7fb9b53106624e134728b0fe351cbd (
plain) (
tree)
|
|
package org.openslx.taskmanager.tasks;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.openslx.satserver.util.Util;
import org.openslx.taskmanager.api.AbstractTask;
import com.google.gson.annotations.Expose;
public class DeleteDirectory extends AbstractTask
{
protected static final String[] ALLOWED_DIRS =
{ "/tmp/", "/srv/openslx/www/boot/" };
@Expose
private String path = null;
@Expose
private boolean recursive = false;
private Output status = new Output();
@Override
protected boolean initTask()
{
this.setStatusObject( status );
this.path = FilenameUtils.normalize( this.path );
if ( this.path == null || !Util.startsWith( this.path, ALLOWED_DIRS )
|| Arrays.asList( ALLOWED_DIRS ).contains( this.path ) ) {
status.error = "Directory not in allowed directory";
return false;
}
return true;
}
@Override
protected boolean execute()
{
try {
FileUtils.deleteDirectory( new File( this.path ) );
} catch ( Exception e1 ) {
status.error = e1.toString();
return false;
}
return true;
}
/**
* Output - contains additional status data of this task
*/
@SuppressWarnings( "unused" )
private static class Output
{
protected String error = null;
}
}
|