From 10f907b832188d2d25ae448b05da0bfc022a6df0 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Wed, 31 Jul 2013 21:05:45 +0100 Subject: [PATCH] Issue #31: Added check for and correction of repository URL. --- src/backend/network.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/backend/network.cpp b/src/backend/network.cpp index a69d10fa..c67d8ef4 100644 --- a/src/backend/network.cpp +++ b/src/backend/network.cpp @@ -141,6 +141,19 @@ namespace boss { return revision + " (" + date + ")"; } + //Gets repository URL string. + string GetURL(const std::string& buffer) { + size_t pos1, pos2; + + pos1 = buffer.rfind("Repository Root: "); + if (pos1 == string::npos) + return ""; + + pos2 = buffer.find('\n', pos1); + + return buffer.substr(pos1+17, pos2-pos1-17); + } + std::string UpdateMasterlist(Game& game, std::vector& parsingErrors) { string command, output, revision; @@ -167,6 +180,30 @@ namespace boss { BOOST_LOG_TRIVIAL(error) << "Subversion could not perform a checkout. Details: " << output; throw error(error::subversion_error, "Subversion could not perform a checkout. Details: " + output); } + } else { + //A working copy exists, but we need to make sure that it points to the right repository. + BOOST_LOG_TRIVIAL(trace) << "Comparing working copy repository URL with BOSS's URL"; + + command = g_path_svn.string() + " info \"" + game.MasterlistPath().string() + "\""; + + if (!RunCommand(command, output)) { + BOOST_LOG_TRIVIAL(error) << "Subversion could not get the repository URL. Details: " << output; + throw error(error::subversion_error, "Subversion could not get the repository URL. Details: " + output); + } + + string url = GetURL(output); + + //Now compare URLs. + if (url != game.URL()) { + BOOST_LOG_TRIVIAL(trace) << "URLs do not match: relocating the working copy."; + + command = g_path_svn.string() + " relocate " + game.URL(); + + if (!RunCommand(command, output)) { + BOOST_LOG_TRIVIAL(error) << "Subversion could not relocate the working copy. Details: " << output; + throw error(error::subversion_error, "Subversion could not relocate the working copy. Details: " + output); + } + } } //Now update masterlist.