Commit 9fb94ca5 authored by Martyn Gigg's avatar Martyn Gigg
Browse files

Merge pull request #13291 from mantidproject/11790_Repository_view_bug_when_upload_file

Fix script repository view when files are uploaded
parents fab72341 d7a77efa
......@@ -161,6 +161,7 @@ private:
void download_directory(const std::string &);
void download_file(const std::string &, RepositoryEntry &);
void updateLocalJson(const std::string &, const RepositoryEntry &);
void updateRepositoryJson(const std::string &, const RepositoryEntry &);
/// flag that indicate a valid repository
bool valid;
......@@ -858,6 +858,18 @@ void ScriptRepositoryImpl::upload(const std::string &file_path,
g_log.information() << "ScriptRepository update local json " << std::endl;
updateLocalJson(file_path, entry); /// FIXME: performance!
// add the entry to the repository.json. The
// repository.json should change at the
// remote repository, and we could just download the new one, but
// we can not rely on the server updating it fast enough.
// So add to the file locally to avoid race condition.
RepositoryEntry &remote_entry =;
if (!published_date.empty())
remote_entry.pub_date = DateAndTime(published_date);
remote_entry.status = BOTH_UNCHANGED;
g_log.debug() << "ScriptRepository updating repository json " << std::endl;
updateRepositoryJson(file_path, remote_entry);
} else
throw ScriptRepoException(info, detail);
......@@ -866,6 +878,53 @@ void ScriptRepositoryImpl::upload(const std::string &file_path,
* Adds an entry to .repository.json
* This is necessary when uploading a file to keep .repository.json and
* .local.json in sync, and thus display correct file status in the GUI.
* Requesting an updated .repository.json from the server is not viable
* at such a time as it would create a race condition.
* @param path: relative path of uploaded file
* @param entry: the entry to add to the json file
void ScriptRepositoryImpl::updateRepositoryJson(const std::string &path,
const RepositoryEntry &entry) {
ptree repository_json;
std::string filename = std::string(local_repository).append(".repository.json");
read_json(filename, repository_json);
ptree::const_assoc_iterator it = repository_json.find(path);
if (it == repository_json.not_found()) {
boost::property_tree::ptree array;
std::string directory =
(const char *)(( ? "true" : "false");
boost::property_tree::basic_ptree<std::string, std::string>>(
path, array));
g_log.debug() << "Update LOCAL JSON FILE" << std::endl;
#if defined(_WIN32) || defined(_WIN64)
// set the .repository.json and .local.json not hidden to be able to edit it
SetFileAttributes(filename.c_str(), FILE_ATTRIBUTE_NORMAL);
write_json(filename, repository_json);
#if defined(_WIN32) || defined(_WIN64)
// set the .repository.json and .local.json hidden
SetFileAttributes(filename.c_str(), FILE_ATTRIBUTE_HIDDEN);
* Delete one file from the local and the central ScriptRepository
* It will send in a POST method, with the file path to find the path :
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment