boolean srcExecutable = fs.isExecutable(src);
boolean destExecutable = fs.isExecutable(dest);
if (!srcExists && !destExists) {
throw new MoeProblem(
String.format("Neither src nor dests exists. Unreachable code:%n%s%n%s%n%s",
relativeFilename, src, dest));
}
if (!srcExists) {
SvnRepository.runSvnCommand(
ImmutableList.of("rm", relativeFilename), rootDirectory.getAbsolutePath());
// TODO(dbentley): handle newly-empty directories
return;
}
try {
fs.makeDirsForFile(dest);
fs.copyFile(src, dest);
} catch (IOException e) {
throw new MoeProblem(e.getMessage());
}
if (!destExists) {
SvnRepository.runSvnCommand(
ImmutableList.of("add", "--parents", relativeFilename),
rootDirectory.getAbsolutePath());
}
String mimeType = guessMimeType(relativeFilename);
if (mimeType != null) {
try {
SvnRepository.runSvnCommand(
ImmutableList.of("propset", "svn:mime-type", mimeType, relativeFilename),
rootDirectory.getAbsolutePath());
} catch (CommandRunner.CommandException e) {
// If the mime type setting fails, it's not really a big deal.
// Just log it and keep going.
AppContext.RUN.ui.info(
String.format("Error setting mime-type for %s", relativeFilename));
}
}
if (destExecutable != srcExecutable) {
if (srcExecutable) {
SvnRepository.runSvnCommand(
ImmutableList.of("propset", "svn:executable", "*", relativeFilename),
rootDirectory.getAbsolutePath());
} else {
SvnRepository.runSvnCommand(
ImmutableList.of("propdel", "svn:executable", relativeFilename),
rootDirectory.getAbsolutePath());
}
}
} catch (CommandRunner.CommandException e) {
throw new MoeProblem("problem occurred while running svn: " + e.stderr);
}
}