Skip to content
Snippets Groups Projects
Commit f1111fa8 authored by Gesner Passos's avatar Gesner Passos
Browse files

Installation Requirement change

Now, we allow users to install ScriptRepository in an already used directory.
This encourages the users to select the folder that they are already using,
probably helping them to publish afterwards.

re #6175
parent 7d89d547
No related branches found
No related tags found
No related merge requests found
...@@ -412,11 +412,11 @@ They will work as was expected for folders @ref folders-sec. ...@@ -412,11 +412,11 @@ They will work as was expected for folders @ref folders-sec.
locally. locally.
It is allowed to create hidden files that would be necessary for the operation of this class. 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. @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; virtual void install(std::string local_path) = 0;
......
...@@ -218,17 +218,21 @@ namespace API ...@@ -218,17 +218,21 @@ namespace API
The instalation consists of: 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) - 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, The installation will also upate the ScriptLocalRepository setting, if necessary,
to match the given path. to match the given path.
If it success, it will change the status of the ScriptRepository as valid. 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 @note Any directory may be given, from existing directories a new directory.
directory, or an empty 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 ...@@ -236,31 +240,31 @@ namespace API
using Poco::DirectoryIterator; using Poco::DirectoryIterator;
std::string folder = std::string(path); std::string folder = std::string(path);
Poco::File repository_folder(folder); 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()){ if (!repository_folder.exists()){
g_log.debug() << "ScriptRepository creating folder " << folder << std::endl; g_log.debug() << "ScriptRepository creating folder " << folder << std::endl;
repository_folder.createDirectories(); repository_folder.createDirectories();
}else{ }else{
// FIXME: ensure that the folder is empty!
DirectoryIterator end; // if the folder already exists, check if it is a ScriptRepository already:
int i = 0; Poco::File rep(rep_json_file);
for (DirectoryIterator it(path); it != end; Poco::File local(local_json_file);
it ++){
if (it->path().find(".") == 0) if (rep.exists() && local.exists()){
continue; // ignore the . and .. files and hidden g_log.information() << "ScriptRepository already installed at: " << path << std::endl;
i++; 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 // download the repository json
std::string rep_json_file = std::string(path).append("/.repository.json");
doDownloadFile(std::string(remote_url).append("/repository.json"), doDownloadFile(std::string(remote_url).append("/repository.json"),
rep_json_file); rep_json_file);
g_log.debug() << "ScriptRepository downloaded repository information" << std::endl; g_log.debug() << "ScriptRepository downloaded repository information" << std::endl;
// creation of the instance of local_json file // creation of the instance of local_json file
ptree pt; ptree pt;
std::string local_json_file = std::string(path).append("/.local.json");
write_json(local_json_file,pt); write_json(local_json_file,pt);
g_log.debug() << "ScriptRepository created the local repository information"<<std::endl; g_log.debug() << "ScriptRepository created the local repository information"<<std::endl;
......
...@@ -270,7 +270,9 @@ class ScriptRepositoryTestImpl : public CxxTest::TestSuite{ ...@@ -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(){ void test_installation_do_not_install_on_non_empty_directory(){
// fill the local_rep path with files // fill the local_rep path with files
...@@ -284,7 +286,7 @@ class ScriptRepositoryTestImpl : public CxxTest::TestSuite{ ...@@ -284,7 +286,7 @@ class ScriptRepositoryTestImpl : public CxxTest::TestSuite{
// before installing the repository, ScriptRepositoryImpl will be always invalid // before installing the repository, ScriptRepositoryImpl will be always invalid
TSM_ASSERT("Why valid?",!repo->isValid()); TSM_ASSERT("Why valid?",!repo->isValid());
// the installation should throw, directory is not empty // 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));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment