diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/ScriptRepository.h b/Code/Mantid/Framework/API/inc/MantidAPI/ScriptRepository.h index 8e682b39f2084120bc025edf1e81e39fcf42e6c9..7a16853554c5014d41b1e4832c0e1b0782ab4e52 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/ScriptRepository.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/ScriptRepository.h @@ -412,11 +412,11 @@ They will work as was expected for folders @ref folders-sec. locally. It is allowed to create hidden files that would be necessary for the operation of this class. - At the end, a new folder is created, with the given local_path given. + At the end, a new folder is created (if it does not exists already), with the given local_path given. @param local_path: path where the folder (having the same name given) will be created. - @exception ScriptRepoException: If the local_path may not be created (because is an existing folder not empty). + @exception ScriptRepoException: If the local_path may not be created (Permission issues). */ virtual void install(std::string local_path) = 0; diff --git a/Code/Mantid/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp b/Code/Mantid/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp index 46d1cbe873406bf88867adc349003aa3c978b7cb..2979ebe76a6aab82263218114db9707fed0ef0b4 100644 --- a/Code/Mantid/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp +++ b/Code/Mantid/Framework/ScriptRepository/src/ScriptRepositoryImpl.cpp @@ -218,17 +218,21 @@ namespace API The instalation consists of: - - creation of the folder for the ScriptRepository. + - creation of the folder for the ScriptRepository (if it does not exists). - download of the repository.json file (Make it hidden) - - creation of the local.json file. + - creation of the local.json file. (Make if hidden) The installation will also upate the ScriptLocalRepository setting, if necessary, to match the given path. If it success, it will change the status of the ScriptRepository as valid. - @param path : Path for a folder inside the local machine. It must be a non existing - directory, or an empty directory. + @note Any directory may be given, from existing directories a new directory. + If an existing directory is given, the installation will install the two necessary + files to deal with this folder as a ScriptRepository. + + + @param path : Path for a folder inside the local machine. */ @@ -236,31 +240,31 @@ namespace API using Poco::DirectoryIterator; std::string folder = std::string(path); Poco::File repository_folder(folder); + std::string rep_json_file = std::string(path).append("/.repository.json"); + std::string local_json_file = std::string(path).append("/.local.json"); if (!repository_folder.exists()){ g_log.debug() << "ScriptRepository creating folder " << folder << std::endl; repository_folder.createDirectories(); - }else{ - // FIXME: ensure that the folder is empty! - DirectoryIterator end; - int i = 0; - for (DirectoryIterator it(path); it != end; - it ++){ - if (it->path().find(".") == 0) - continue; // ignore the . and .. files and hidden - i++; + }else{ + + // if the folder already exists, check if it is a ScriptRepository already: + Poco::File rep(rep_json_file); + Poco::File local(local_json_file); + + if (rep.exists() && local.exists()){ + g_log.information() << "ScriptRepository already installed at: " << path << std::endl; + return; } - if (i) - throw ScriptRepoException("The ScriptRepository can not be installed on a non-empty directory"); } + // install the two files inside the given folder + // download the repository json - std::string rep_json_file = std::string(path).append("/.repository.json"); doDownloadFile(std::string(remote_url).append("/repository.json"), rep_json_file); g_log.debug() << "ScriptRepository downloaded repository information" << std::endl; // creation of the instance of local_json file ptree pt; - std::string local_json_file = std::string(path).append("/.local.json"); write_json(local_json_file,pt); g_log.debug() << "ScriptRepository created the local repository information"<<std::endl; diff --git a/Code/Mantid/Framework/ScriptRepository/test/ScriptRepositoryTestImpl.h b/Code/Mantid/Framework/ScriptRepository/test/ScriptRepositoryTestImpl.h index 0a67c640dcba5e35779751df1d34ffedaf16078a..ed73b9e38952c44581cdbafd916e6e79de65afbe 100644 --- a/Code/Mantid/Framework/ScriptRepository/test/ScriptRepositoryTestImpl.h +++ b/Code/Mantid/Framework/ScriptRepository/test/ScriptRepositoryTestImpl.h @@ -270,7 +270,9 @@ class ScriptRepositoryTestImpl : public CxxTest::TestSuite{ } /** - Installation should not install on a non-empty directory. + Installation may install on non-empty directory. If the directory is already a ScriptRepository, + the installation should just return. If it is not, the installation, should install the + two hidden files in that directory. */ void test_installation_do_not_install_on_non_empty_directory(){ // fill the local_rep path with files @@ -284,7 +286,7 @@ class ScriptRepositoryTestImpl : public CxxTest::TestSuite{ // before installing the repository, ScriptRepositoryImpl will be always invalid TSM_ASSERT("Why valid?",!repo->isValid()); // the installation should throw, directory is not empty - TS_ASSERT_THROWS(repo->install(local_rep), Mantid::API::ScriptRepoException); + TS_ASSERT_THROWS_NOTHING(repo->install(local_rep)); }