FIX:Plugin first fails to install Mac
jira: STUDIO-11242 Change-Id: I9c3484e18c3da75a5dee62523e32ac6ad6c9b207
This commit is contained in:
parent
ed9c29d7a5
commit
d5d4dc4638
|
@ -229,7 +229,7 @@ CopyFileResult copy_file_inner(const std::string &from, const std::string &to, s
|
||||||
// of the source file before renaming.
|
// of the source file before renaming.
|
||||||
// Additional error info is passed in error message.
|
// Additional error info is passed in error message.
|
||||||
extern CopyFileResult copy_file(const std::string &from, const std::string &to, std::string& error_message, const bool with_check = false);
|
extern CopyFileResult copy_file(const std::string &from, const std::string &to, std::string& error_message, const bool with_check = false);
|
||||||
|
extern bool copy_framework(const std::string &from, const std::string &to);
|
||||||
// Compares two files if identical.
|
// Compares two files if identical.
|
||||||
extern CopyFileResult check_copy(const std::string& origin, const std::string& copy);
|
extern CopyFileResult check_copy(const std::string& origin, const std::string& copy);
|
||||||
|
|
||||||
|
|
|
@ -943,6 +943,34 @@ __finished:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool copy_framework(const std::string &from, const std::string &to)
|
||||||
|
{
|
||||||
|
boost::filesystem::path src(from), dst(to);
|
||||||
|
try {
|
||||||
|
if (!boost::filesystem::is_directory(src)) {
|
||||||
|
std::cerr << "Error: Source is not a directory: " << src << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boost::filesystem::create_directories(dst);
|
||||||
|
for (boost::filesystem::directory_iterator it(src); it != boost::filesystem::directory_iterator(); ++it) {
|
||||||
|
const auto &entry = it->path();
|
||||||
|
const auto dest_path = dst / entry.filename();
|
||||||
|
|
||||||
|
if (boost::filesystem::is_symlink(entry)) {
|
||||||
|
boost::filesystem::copy_symlink(entry, dest_path);
|
||||||
|
} else if (boost::filesystem::is_directory(entry)) {
|
||||||
|
copy_framework(it->path().string(), dest_path.string());
|
||||||
|
} else {
|
||||||
|
boost::filesystem::copy(entry, dest_path, boost::filesystem::copy_options::overwrite_existing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (const boost::filesystem::filesystem_error &e) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Filesystem error: " << e.what();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
CopyFileResult check_copy(const std::string &origin, const std::string ©)
|
CopyFileResult check_copy(const std::string &origin, const std::string ©)
|
||||||
{
|
{
|
||||||
boost::nowide::ifstream f1(origin, std::ifstream::in | std::ifstream::binary | std::ifstream::ate);
|
boost::nowide::ifstream f1(origin, std::ifstream::in | std::ifstream::binary | std::ifstream::ate);
|
||||||
|
|
|
@ -1773,7 +1773,11 @@ int GUI_App::install_plugin(std::string name, std::string package_name, InstallP
|
||||||
if (S_ISLNK(stat.m_external_attr >> 16)) {
|
if (S_ISLNK(stat.m_external_attr >> 16)) {
|
||||||
std::string link(stat.m_uncomp_size + 1, 0);
|
std::string link(stat.m_uncomp_size + 1, 0);
|
||||||
res = mz_zip_reader_extract_to_mem(&archive, stat.m_file_index, link.data(), stat.m_uncomp_size, 0);
|
res = mz_zip_reader_extract_to_mem(&archive, stat.m_file_index, link.data(), stat.m_uncomp_size, 0);
|
||||||
boost::filesystem::create_symlink(link, dest_path);
|
try {
|
||||||
|
boost::filesystem::create_symlink(link, dest_path);
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " create_symlink:" << e.what();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
res = mz_zip_reader_extract_to_file(&archive, stat.m_file_index, dest_zip_file.c_str(), 0);
|
res = mz_zip_reader_extract_to_file(&archive, stat.m_file_index, dest_zip_file.c_str(), 0);
|
||||||
|
@ -1794,26 +1798,6 @@ int GUI_App::install_plugin(std::string name, std::string package_name, InstallP
|
||||||
return InstallStatusUnzipFailed;
|
return InstallStatusUnzipFailed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if (pro_fn) {
|
|
||||||
pro_fn(InstallStatusNormal, 50 + i/num_entries, cancel);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
auto backup_path = boost::filesystem::path(backup_folder.string() + "/" + dest_file);
|
|
||||||
if (fs::exists(backup_path))
|
|
||||||
fs::remove(backup_path);
|
|
||||||
std::string error_message;
|
|
||||||
CopyFileResult cfr = copy_file(dest_path.string(), backup_path.string(), error_message, false);
|
|
||||||
if (cfr != CopyFileResult::SUCCESS) {
|
|
||||||
BOOST_LOG_TRIVIAL(error) << "Copying to backup failed(" << cfr << "): " << error_message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const std::exception& e)
|
|
||||||
{
|
|
||||||
BOOST_LOG_TRIVIAL(error) << "Copying to backup failed: " << e.what();
|
|
||||||
//continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
@ -1833,7 +1817,38 @@ int GUI_App::install_plugin(std::string name, std::string package_name, InstallP
|
||||||
}
|
}
|
||||||
|
|
||||||
close_zip_reader(&archive);
|
close_zip_reader(&archive);
|
||||||
|
{
|
||||||
|
fs::path dir_path(plugin_folder);
|
||||||
|
if (fs::exists(dir_path) && fs::is_directory(dir_path)) {
|
||||||
|
int file_count = 0, file_index = 0;
|
||||||
|
for (fs::directory_iterator it(dir_path); it != fs::directory_iterator(); ++it) {
|
||||||
|
if (fs::is_regular_file(it->status())) { ++file_count; }
|
||||||
|
}
|
||||||
|
for (fs::directory_iterator it(dir_path); it != fs::directory_iterator(); ++it) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << " current path:" << it->path().string();
|
||||||
|
if (it->path().string() == backup_folder) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto dest_path = backup_folder.string() + "/" + it->path().filename().string();
|
||||||
|
if (fs::is_regular_file(it->status())) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << " copy file:" << it->path().string() << "," << it->path().filename();
|
||||||
|
try {
|
||||||
|
if (pro_fn) { pro_fn(InstallStatusNormal, 50 + file_index / file_count, cancel); }
|
||||||
|
file_index++;
|
||||||
|
if (fs::exists(dest_path)) { fs::remove(dest_path); }
|
||||||
|
std::string error_message;
|
||||||
|
CopyFileResult cfr = copy_file(it->path().string(), dest_path, error_message, false);
|
||||||
|
if (cfr != CopyFileResult::SUCCESS) { BOOST_LOG_TRIVIAL(error) << "Copying to backup failed(" << cfr << "): " << error_message; }
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "Copying to backup failed: " << e.what();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << " copy framework:" << it->path().string() << "," << it->path().filename();
|
||||||
|
copy_framework(it->path().string(), dest_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (pro_fn)
|
if (pro_fn)
|
||||||
pro_fn(InstallStatusInstallCompleted, 100, cancel);
|
pro_fn(InstallStatusInstallCompleted, 100, cancel);
|
||||||
if (name == "plugins")
|
if (name == "plugins")
|
||||||
|
|
Loading…
Reference in New Issue