diff options
author | Simon Rettberg | 2014-06-03 16:47:36 +0200 |
---|---|---|
committer | Simon Rettberg | 2014-06-03 16:47:36 +0200 |
commit | 32dc5354e2916387a2c62eadae0a4568023f1151 (patch) | |
tree | 7fd9a0173d6073e86d1d48e545646b1bc8c1a5eb /src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java | |
download | tmlite-bwlp-32dc5354e2916387a2c62eadae0a4568023f1151.tar.gz tmlite-bwlp-32dc5354e2916387a2c62eadae0a4568023f1151.tar.xz tmlite-bwlp-32dc5354e2916387a2c62eadae0a4568023f1151.zip |
Initial commit
Diffstat (limited to 'src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java')
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java b/src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java new file mode 100644 index 0000000..8c0f9a1 --- /dev/null +++ b/src/main/java/org/openslx/taskmanager/tasks/DeleteFile.java @@ -0,0 +1,57 @@ +package org.openslx.taskmanager.tasks; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +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 DeleteFile extends AbstractTask +{ + + protected static final String[] ALLOWED_DIRS = + { "/tmp/", "/opt/openslx/configs/" }; + + @Expose + private String file = null; + + private Output status = new Output(); + + @Override + protected boolean initTask() + { + this.setStatusObject( status ); + this.file = FilenameUtils.normalize( this.file ); + if ( this.file == null || !Util.startsWith( this.file, ALLOWED_DIRS ) ) { + status.error = "File not in allowed directory"; + return false; + } + return true; + } + + @Override + protected boolean execute() + { + try { + Files.deleteIfExists( Paths.get( this.file ) ); + } catch ( IOException 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; + } + +} |