various fixes on path validation

This commit is contained in:
Chris Punches
2026-03-16 23:25:49 -04:00
parent e852b7e182
commit e55da16193
2 changed files with 48 additions and 25 deletions

View File

@@ -51,6 +51,12 @@ fs::path Project::resolved_shells_path() const {
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) {
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");
return false;
}
if (!fs::exists(u.target)) {
report_status("Unit '" + u.name + "': target does not exist: " + u.target);
auto target_path = extract_path(u.target);
if (!fs::exists(target_path)) {
report_status("Unit '" + u.name + "': target does not exist: " + target_path);
return false;
}
if (access(u.target.c_str(), X_OK) != 0) {
report_status("Unit '" + u.name + "': target is not executable: " + u.target);
if (access(target_path.c_str(), X_OK) != 0) {
report_status("Unit '" + u.name + "': target is not executable: " + target_path);
return false;
}
@@ -94,12 +101,13 @@ bool Project::check_unit_valid(const Unit& u) {
report_status("Unit '" + u.name + "': rectifier is not defined");
return false;
}
if (!fs::exists(u.rectifier)) {
report_status("Unit '" + u.name + "': rectifier does not exist: " + u.rectifier);
auto rectifier_path = extract_path(u.rectifier);
if (!fs::exists(rectifier_path)) {
report_status("Unit '" + u.name + "': rectifier does not exist: " + rectifier_path);
return false;
}
if (access(u.rectifier.c_str(), X_OK) != 0) {
report_status("Unit '" + u.name + "': rectifier is not executable: " + u.rectifier);
if (access(rectifier_path.c_str(), X_OK) != 0) {
report_status("Unit '" + u.name + "': rectifier is not executable: " + rectifier_path);
return false;
}
}
@@ -109,8 +117,9 @@ bool Project::check_unit_valid(const Unit& u) {
report_status("Unit '" + u.name + "': environment file is not defined");
return false;
}
if (!fs::exists(u.environment)) {
report_status("Unit '" + u.name + "': environment file does not exist: " + u.environment);
auto env_path = extract_path(u.environment);
if (!fs::exists(env_path)) {
report_status("Unit '" + u.name + "': environment file does not exist: " + env_path);
return false;
}
}

View File

@@ -365,6 +365,11 @@ static void update_sensitivity(DialogState* s) {
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) {
if (s->loading) return;
@@ -386,12 +391,15 @@ static void validate_fields(DialogState* s) {
if (u.target.empty()) {
valid = false;
if (error_msg.empty()) error_msg = "Target is not defined";
} else if (!fs::exists(u.target)) {
valid = false;
if (error_msg.empty()) error_msg = "Target does not exist: " + u.target;
} else if (access(u.target.c_str(), X_OK) != 0) {
valid = false;
if (error_msg.empty()) error_msg = "Target is not executable: " + u.target;
} else {
auto tp = extract_path(u.target);
if (!fs::exists(tp)) {
valid = false;
if (error_msg.empty()) error_msg = "Target does not exist: " + tp;
} 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);
}
@@ -430,12 +438,15 @@ static void validate_fields(DialogState* s) {
if (u.rectifier.empty()) {
valid = false;
if (error_msg.empty()) error_msg = "Rectifier is not defined";
} else if (!fs::exists(u.rectifier)) {
valid = false;
if (error_msg.empty()) error_msg = "Rectifier does not exist: " + u.rectifier;
} else if (access(u.rectifier.c_str(), X_OK) != 0) {
valid = false;
if (error_msg.empty()) error_msg = "Rectifier is not executable: " + u.rectifier;
} else {
auto rp = extract_path(u.rectifier);
if (!fs::exists(rp)) {
valid = false;
if (error_msg.empty()) error_msg = "Rectifier does not exist: " + rp;
} 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);
} else {
@@ -448,9 +459,12 @@ static void validate_fields(DialogState* s) {
if (u.environment.empty()) {
valid = false;
if (error_msg.empty()) error_msg = "Environment file is not defined";
} else if (!fs::exists(u.environment)) {
valid = false;
if (error_msg.empty()) error_msg = "Environment file does not exist: " + u.environment;
} else {
auto ep = extract_path(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);
} else {