summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/taskmanager
diff options
context:
space:
mode:
authorSimon Rettberg2019-12-11 18:14:48 +0100
committerSimon Rettberg2019-12-11 18:14:48 +0100
commitcbba66783b85c29261d5eb181413c965a9d9ce39 (patch)
tree381ad3df1eb8ab8a87800571072a00740fed3d51 /src/main/java/org/openslx/taskmanager
parent[Symlink] Rename and refit from LinkConfigTgz (diff)
downloadtmlite-bwlp-cbba66783b85c29261d5eb181413c965a9d9ce39.tar.gz
tmlite-bwlp-cbba66783b85c29261d5eb181413c965a9d9ce39.tar.xz
tmlite-bwlp-cbba66783b85c29261d5eb181413c965a9d9ce39.zip
[CopyDirectory] New task for new minilinux slx-admin module
Diffstat (limited to 'src/main/java/org/openslx/taskmanager')
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/CopyDirectory.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/CopyDirectory.java b/src/main/java/org/openslx/taskmanager/tasks/CopyDirectory.java
new file mode 100644
index 0000000..041c681
--- /dev/null
+++ b/src/main/java/org/openslx/taskmanager/tasks/CopyDirectory.java
@@ -0,0 +1,73 @@
+package org.openslx.taskmanager.tasks;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.log4j.Logger;
+import org.openslx.satserver.util.Util;
+import org.openslx.taskmanager.api.AbstractTask;
+
+import com.google.gson.annotations.Expose;
+
+public class CopyDirectory extends AbstractTask
+{
+ private static final Logger LOG = Logger.getLogger( CopyDirectory.class );
+
+ protected static final String[] ALLOWED_DIRS =
+ { "/tmp/", "/srv/openslx/www/boot/" };
+
+ @Expose
+ private String source = null;
+ @Expose
+ private String destination = null;
+
+ private Output status = new Output();
+
+ @Override
+ protected boolean initTask()
+ {
+ this.source = FilenameUtils.normalize( this.source );
+ if ( this.source == null || !Util.startsWith( this.source, ALLOWED_DIRS ) || this.source.endsWith( "/" ) ) {
+ status.error = "Source not in allowed directory";
+ return false;
+ }
+ this.destination = FilenameUtils.normalize( this.destination );
+ if ( this.destination == null || !Util.startsWith( this.destination, ALLOWED_DIRS ) || this.destination.endsWith( "/" ) ) {
+ status.error = "Destination not in allowed directory";
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ protected boolean execute()
+ {
+ File src = new File( this.source );
+ File dst = new File( this.destination );
+ if ( !src.exists() || !src.isDirectory() ) {
+ status.error = this.source + " is not a directory!";
+ return false;
+ }
+ if ( !src.canRead() ) {
+ status.error = "Cannot read " + this.source;
+ return false;
+ }
+ try {
+ if ( dst.exists() && dst.isDirectory() )
+ FileUtils.deleteDirectory( dst );
+ FileUtils.copyDirectory( src, dst );
+ } catch ( IOException e ) {
+ status.error = e.toString();
+ return false;
+ }
+ return true;
+ }
+
+ private class Output
+ {
+ public String error = null;
+ }
+
+}