posix main: only try to generate symlinks if data path argument given

if not given, the dirs are either not needed (eg RPI) or assumed to
exist already
This commit is contained in:
Beat Küng
2016-09-30 13:50:51 +02:00
committed by Julian Oes
parent 98ac60e3fd
commit e061842219
+28 -22
View File
@@ -358,12 +358,16 @@ int main(int argc, char **argv)
return -1; return -1;
} }
bool symlinks_needed = true;
if (positional_arg_count == 1) { //data path is optional if (positional_arg_count == 1) { //data path is optional
commands_file = data_path; commands_file = data_path;
data_path = "."; symlinks_needed = false;
} else {
cout << "data path: " << data_path << endl;
} }
cout << "data path: " << data_path << endl;
cout << "commands file: " << commands_file << endl; cout << "commands file: " << commands_file << endl;
if (commands_file.size() < 1) { if (commands_file.size() < 1) {
@@ -377,32 +381,34 @@ int main(int argc, char **argv)
} }
// create sym-links // create sym-links
vector<string> path_sym_links; if (symlinks_needed) {
path_sym_links.push_back("ROMFS"); vector<string> path_sym_links;
path_sym_links.push_back("posix-configs"); path_sym_links.push_back("ROMFS");
path_sym_links.push_back("test_data"); path_sym_links.push_back("posix-configs");
path_sym_links.push_back("test_data");
for (int i = 0; i < path_sym_links.size(); i++) { for (int i = 0; i < path_sym_links.size(); i++) {
string path_sym_link = path_sym_links[i]; string path_sym_link = path_sym_links[i];
//cout << "path sym link: " << path_sym_link << endl; //cout << "path sym link: " << path_sym_link << endl;
string src_path = data_path + "/" + path_sym_link; string src_path = data_path + "/" + path_sym_link;
string dest_path = pwd() + "/" + path_sym_link; string dest_path = pwd() + "/" + path_sym_link;
PX4_DEBUG("Creating symlink %s -> %s", src_path.c_str(), dest_path.c_str()); PX4_DEBUG("Creating symlink %s -> %s", src_path.c_str(), dest_path.c_str());
if (dirExists(path_sym_link)) { continue; } if (dirExists(path_sym_link)) { continue; }
// create sym-links // create sym-links
int ret = symlink(src_path.c_str(), dest_path.c_str()); int ret = symlink(src_path.c_str(), dest_path.c_str());
if (ret != 0) { if (ret != 0) {
PX4_ERR("Error creating symlink %s -> %s", PX4_ERR("Error creating symlink %s -> %s",
src_path.c_str(), dest_path.c_str()); src_path.c_str(), dest_path.c_str());
return ret; return ret;
} else { } else {
PX4_DEBUG("Successfully created symlink %s -> %s", PX4_DEBUG("Successfully created symlink %s -> %s",
src_path.c_str(), dest_path.c_str()); src_path.c_str(), dest_path.c_str());
}
} }
} }