Skip to content

Commit

Permalink
backup / restore with added.txt marker file
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit Moussaud committed Dec 9, 2015
1 parent 699fc25 commit 3a2f0bc
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ private ActionBuilder analyze(final OverthereConnection connection) throws Excep
actions.systemOut("Backup modified files done.");
}

if (changeSet.getAdded().size() > 0) {
actions.systemOut("Mark added files...");
for (OverthereFile f : changeSet.getAdded()) {
final String pathPrefix = stringPathPrefix(f, artifactFilePath);
OverthereFile addedFile = remoteTargetPath.getFile(pathPrefix);
actions.systemOut(format("Mark %s as added ", addedFile.getPath()));
actions.markAdded(backupRemoteFolder, addedFile);
}
actions.systemOut("Mark added files done...");

}
return actions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
package ext.deployit.community.extra.steps;


import java.io.InputStream;
import java.util.Properties;

import com.xebialabs.deployit.plugin.api.flow.ExecutionContext;
import com.xebialabs.deployit.plugin.api.flow.StepExitCode;
import com.xebialabs.deployit.plugin.api.rules.RulePostConstruct;
Expand Down Expand Up @@ -68,6 +71,22 @@ private ActionBuilder analyze(final OverthereConnection connection) throws Excep
actions.systemOut("Restore modified files done.");
}

final OverthereFile addedFile = fromTargetPath.getFile("added.txt");
if (addedFile.exists()) {
Properties added = new Properties();
final InputStream inputStream = addedFile.getInputStream();
added.load(inputStream);
inputStream.close();
for (Object key : added.keySet()) {
final OverthereFile file = connection.getFile(key.toString());
if (file.isFile()) {
actions.delete(file);
} else {
actions.deleteRecursively(file);
}
}
}

return actions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ public void delete(final OverthereFile remoteFile) {
}

public void copyTo(final OverthereFile artifactFile, final OverthereFile remoteFile) {
actions.add(new CopyTo(artifactFile,remoteFile));
actions.add(new CopyTo(artifactFile, remoteFile));
}

public void deleteRecursively(final OverthereFile removedFile) {
actions.add(new DeleteRecursively(removedFile));
}

public void markAdded(final OverthereFile backupRemoteFolder, final OverthereFile addedFile) {
actions.add(new Added(backupRemoteFolder, addedFile));
}

public void execute(final ExecutionContext ctx) {
for (Action action : actions) {
action.execute(ctx);
Expand All @@ -52,4 +56,6 @@ public Preview preview() {
}
return Preview.withContents(sb.toString());
}


}
46 changes: 46 additions & 0 deletions src/main/java/ext/deployit/community/extra/steps/action/Added.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
* FOR A PARTICULAR PURPOSE. THIS CODE AND INFORMATION ARE NOT SUPPORTED BY XEBIALABS.
*/
package ext.deployit.community.extra.steps.action;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.xebialabs.deployit.plugin.api.flow.ExecutionContext;
import com.xebialabs.overthere.OverthereFile;


public class Added extends BaseAction {

private final OverthereFile artifactFile;
private final OverthereFile directory;

public Added(final OverthereFile directory, final OverthereFile artifactFile) {
this.directory = directory;
this.artifactFile = artifactFile;
}

@Override
public void execute(final ExecutionContext ctx) {
Properties added = new Properties();
try {
final OverthereFile addedFile = getAddedFile();
if (addedFile.exists()) {
final InputStream inputStream = addedFile.getInputStream();
added.load(inputStream);
inputStream.close();
}
added.setProperty(artifactFile.getPath(), "ADD");
added.store(addedFile.getOutputStream(), "");
} catch (IOException e) {
e.printStackTrace();
}
}

private OverthereFile getAddedFile() {
return directory.getFile("added.txt");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public Delete(final OverthereFile remoteTargetPath) {

@Override
public void execute(final ExecutionContext ctx) {
ctx.logOutput("Delete "+remoteTargetPath.getPath());
remoteTargetPath.delete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public DeleteRecursively(final OverthereFile remoteTargetPath) {

@Override
public void execute(final ExecutionContext ctx) {
ctx.logOutput("Delete recursively "+remoteTargetPath.getPath());
remoteTargetPath.deleteRecursively();
}
}

0 comments on commit 3a2f0bc

Please sign in to comment.