renameExistingFileToOld method
Renames an existing file with .old
Implementation
void renameExistingFileToOld(AFCommandContext context, List<String> projectPath) {
if(!AFProjectPaths.projectFileExists(projectPath)) {
throw AFCommandError(error: "Expected to find file at $projectPath but did not.");
}
final filename = projectPath.last;
final idxSuffix = filename.lastIndexOf('.');
if(idxSuffix < 0) {
throw AFException("Expected $filename to have a . extension");
}
final renamedFilename = StringBuffer(filename.substring(0, idxSuffix));
renamedFilename.write(".old");
final revisedPath = List<String>.from(projectPath);
revisedPath.removeLast();
revisedPath.add(renamedFilename.toString());
if(AFProjectPaths.projectFileExists(revisedPath)) {
throw AFCommandError(error: "Need to rename $projectPath to $revisedPath, but the destination already exists");
}
renamed[projectPath] = revisedPath;
}