// OpsServer server = smartGetServer(true);
// Agent agent = server.getAgent();
File filePath = getFilePath();
Md5Hash sourceMd5 = null;
if (!OpsContext.isDelete()) {
sourceMd5 = getSourceMd5(target);
}
Md5Hash remoteMd5;
if (target.isMachineTerminated()) {
remoteMd5 = null;
} else {
remoteMd5 = target.getFileHash(filePath);
}
boolean isUpToDate = Objects.equal(sourceMd5, remoteMd5);
if (OpsContext.isDelete()) {
if (remoteMd5 != null) {
target.rm(filePath);
doDeleteAction(target);
}
}
if (OpsContext.isConfigure()) {
boolean changed = false;
if (mkdirs != null) {
if (remoteMd5 == null) {
File dir = filePath.getParentFile();
if (target.getFilesystemInfoFile(dir) == null) {
// TODO: Can mkdir return true/false to indicate presence?
target.mkdir(dir, mkdirs.mode);
if (mkdirs.owner != null) {
target.chown(dir, mkdirs.owner, mkdirs.group, false, false);
}
}
}
}
boolean doUpload = false;
if (!isUpToDate) {
doUpload = true;
if (isOnlyIfNotExists()) {
if (remoteMd5 != null) {
log.info("File already exists, and file set to create only if not exists: exiting");
doUpload = false;
}
}
}
if (OpsContext.isForce()) {
doUpload = true;
}
if (doUpload) {
File newSymlinkDestination = null;
if (isSymlinkVersions()) {
throw new UnsupportedOperationException();
// newSymlinkDestination = new FilePath(getRemoteFilePath() + "-" +
// OpsSystem.buildSimpleTimeString());
// uploadFile(newSymlinkDestination.asString());
//
// remoteMd5 = agent.getRemoteMd5(newSymlinkDestination);
} else {
uploadFile(target, filePath);
if (remoteMd5 == null) {
newFileWasCreated = true;
}
remoteMd5 = target.getFileHash(filePath);
}
if (!Objects.equal(remoteMd5, sourceMd5)) {
String remote = target.readTextFile(filePath);
Md5Hash debugSourceMd5 = getSourceMd5(target);
debugSourceMd5 = getSourceMd5(target);
log.debug("debugSourceMd5: " + debugSourceMd5 + " vs " + remoteMd5);
throw new IllegalStateException("Uploaded file, but contents did not then match: " + filePath);
}