various fixes on path validation
This commit is contained in:
@@ -51,6 +51,12 @@ fs::path Project::resolved_shells_path() const {
|
|||||||
return root / sp;
|
return root / sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract the file path portion before any arguments
|
||||||
|
static std::string extract_path(const std::string& s) {
|
||||||
|
auto pos = s.find(' ');
|
||||||
|
return pos == std::string::npos ? s : s.substr(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
bool Project::check_unit_valid(const Unit& u) {
|
bool Project::check_unit_valid(const Unit& u) {
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@@ -58,12 +64,13 @@ bool Project::check_unit_valid(const Unit& u) {
|
|||||||
report_status("Unit '" + u.name + "': target is not defined");
|
report_status("Unit '" + u.name + "': target is not defined");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!fs::exists(u.target)) {
|
auto target_path = extract_path(u.target);
|
||||||
report_status("Unit '" + u.name + "': target does not exist: " + u.target);
|
if (!fs::exists(target_path)) {
|
||||||
|
report_status("Unit '" + u.name + "': target does not exist: " + target_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (access(u.target.c_str(), X_OK) != 0) {
|
if (access(target_path.c_str(), X_OK) != 0) {
|
||||||
report_status("Unit '" + u.name + "': target is not executable: " + u.target);
|
report_status("Unit '" + u.name + "': target is not executable: " + target_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,12 +101,13 @@ bool Project::check_unit_valid(const Unit& u) {
|
|||||||
report_status("Unit '" + u.name + "': rectifier is not defined");
|
report_status("Unit '" + u.name + "': rectifier is not defined");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!fs::exists(u.rectifier)) {
|
auto rectifier_path = extract_path(u.rectifier);
|
||||||
report_status("Unit '" + u.name + "': rectifier does not exist: " + u.rectifier);
|
if (!fs::exists(rectifier_path)) {
|
||||||
|
report_status("Unit '" + u.name + "': rectifier does not exist: " + rectifier_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (access(u.rectifier.c_str(), X_OK) != 0) {
|
if (access(rectifier_path.c_str(), X_OK) != 0) {
|
||||||
report_status("Unit '" + u.name + "': rectifier is not executable: " + u.rectifier);
|
report_status("Unit '" + u.name + "': rectifier is not executable: " + rectifier_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,8 +117,9 @@ bool Project::check_unit_valid(const Unit& u) {
|
|||||||
report_status("Unit '" + u.name + "': environment file is not defined");
|
report_status("Unit '" + u.name + "': environment file is not defined");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!fs::exists(u.environment)) {
|
auto env_path = extract_path(u.environment);
|
||||||
report_status("Unit '" + u.name + "': environment file does not exist: " + u.environment);
|
if (!fs::exists(env_path)) {
|
||||||
|
report_status("Unit '" + u.name + "': environment file does not exist: " + env_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -365,6 +365,11 @@ static void update_sensitivity(DialogState* s) {
|
|||||||
show(active && s->working_copy.supply_environment, {s->label_environment, s->box_environment});
|
show(active && s->working_copy.supply_environment, {s->label_environment, s->box_environment});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string extract_path(const std::string& s) {
|
||||||
|
auto pos = s.find(' ');
|
||||||
|
return pos == std::string::npos ? s : s.substr(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
static void validate_fields(DialogState* s) {
|
static void validate_fields(DialogState* s) {
|
||||||
if (s->loading) return;
|
if (s->loading) return;
|
||||||
|
|
||||||
@@ -386,12 +391,15 @@ static void validate_fields(DialogState* s) {
|
|||||||
if (u.target.empty()) {
|
if (u.target.empty()) {
|
||||||
valid = false;
|
valid = false;
|
||||||
if (error_msg.empty()) error_msg = "Target is not defined";
|
if (error_msg.empty()) error_msg = "Target is not defined";
|
||||||
} else if (!fs::exists(u.target)) {
|
} else {
|
||||||
valid = false;
|
auto tp = extract_path(u.target);
|
||||||
if (error_msg.empty()) error_msg = "Target does not exist: " + u.target;
|
if (!fs::exists(tp)) {
|
||||||
} else if (access(u.target.c_str(), X_OK) != 0) {
|
valid = false;
|
||||||
valid = false;
|
if (error_msg.empty()) error_msg = "Target does not exist: " + tp;
|
||||||
if (error_msg.empty()) error_msg = "Target is not executable: " + u.target;
|
} else if (access(tp.c_str(), X_OK) != 0) {
|
||||||
|
valid = false;
|
||||||
|
if (error_msg.empty()) error_msg = "Target is not executable: " + tp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set_valid(s->entry_target, valid);
|
set_valid(s->entry_target, valid);
|
||||||
}
|
}
|
||||||
@@ -430,12 +438,15 @@ static void validate_fields(DialogState* s) {
|
|||||||
if (u.rectifier.empty()) {
|
if (u.rectifier.empty()) {
|
||||||
valid = false;
|
valid = false;
|
||||||
if (error_msg.empty()) error_msg = "Rectifier is not defined";
|
if (error_msg.empty()) error_msg = "Rectifier is not defined";
|
||||||
} else if (!fs::exists(u.rectifier)) {
|
} else {
|
||||||
valid = false;
|
auto rp = extract_path(u.rectifier);
|
||||||
if (error_msg.empty()) error_msg = "Rectifier does not exist: " + u.rectifier;
|
if (!fs::exists(rp)) {
|
||||||
} else if (access(u.rectifier.c_str(), X_OK) != 0) {
|
valid = false;
|
||||||
valid = false;
|
if (error_msg.empty()) error_msg = "Rectifier does not exist: " + rp;
|
||||||
if (error_msg.empty()) error_msg = "Rectifier is not executable: " + u.rectifier;
|
} else if (access(rp.c_str(), X_OK) != 0) {
|
||||||
|
valid = false;
|
||||||
|
if (error_msg.empty()) error_msg = "Rectifier is not executable: " + rp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set_valid(s->entry_rectifier, valid);
|
set_valid(s->entry_rectifier, valid);
|
||||||
} else {
|
} else {
|
||||||
@@ -448,9 +459,12 @@ static void validate_fields(DialogState* s) {
|
|||||||
if (u.environment.empty()) {
|
if (u.environment.empty()) {
|
||||||
valid = false;
|
valid = false;
|
||||||
if (error_msg.empty()) error_msg = "Environment file is not defined";
|
if (error_msg.empty()) error_msg = "Environment file is not defined";
|
||||||
} else if (!fs::exists(u.environment)) {
|
} else {
|
||||||
valid = false;
|
auto ep = extract_path(u.environment);
|
||||||
if (error_msg.empty()) error_msg = "Environment file does not exist: " + u.environment;
|
if (!fs::exists(ep)) {
|
||||||
|
valid = false;
|
||||||
|
if (error_msg.empty()) error_msg = "Environment file does not exist: " + ep;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set_valid(s->entry_environment, valid);
|
set_valid(s->entry_environment, valid);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user