FileUtil.purge(agentBasedir, true); // clear the way for the new upgraded agent
if (!oldAgentDir.renameTo(agentBasedir)) {
FileUtil.copyDirectory(oldAgentDir, agentBasedir);
// we need to retain the execute bits for the executable scripts and libraries
FileVisitor visitor = new FileVisitor() {
@Override
public void visit(File file) {
String filename = file.getName();
if (filename.contains(".so") || filename.contains(".sl") || filename.contains(".dylib")) {
file.setExecutable(true);