fix: prevent stale mutation execution
This commit is contained in:
@@ -312,6 +312,11 @@ String compiler_registry_lock_file_name(Request* context)
|
||||
return(compiler_registry_file_name(context) + ".lock");
|
||||
}
|
||||
|
||||
String compiler_priority_file_name(Request* context)
|
||||
{
|
||||
return(context->server->config["BIN_DIRECTORY"] + "/proactive-priority.txt");
|
||||
}
|
||||
|
||||
int compiler_open_lock_file(String file_name, String purpose, bool nonblocking = false)
|
||||
{
|
||||
(void)purpose;
|
||||
@@ -1015,6 +1020,58 @@ bool compiler_request_can_serve_stale_artifact(Request* context)
|
||||
float_val(context->server->config["PROACTIVE_COMPILE_CHECK_INTERVAL"]) > 0);
|
||||
}
|
||||
|
||||
void compiler_prioritize_unit(Request* context, String file_name)
|
||||
{
|
||||
if(!compiler_request_can_serve_stale_artifact(context))
|
||||
return;
|
||||
file_name = compiler_normalize_unit_path(context, file_name);
|
||||
if(file_name == "" || file_name.find('\n') != String::npos || file_name.find('\r') != String::npos)
|
||||
return;
|
||||
|
||||
String queue_file = compiler_priority_file_name(context);
|
||||
int fd = compiler_open_lock_file(queue_file + ".lock", "proactive-priority");
|
||||
if(fd < 0)
|
||||
return;
|
||||
int queue_fd = open(queue_file.c_str(), O_WRONLY | O_CREAT | O_APPEND, 0666);
|
||||
if(queue_fd >= 0)
|
||||
{
|
||||
String line = file_name + "\n";
|
||||
ssize_t offset = 0;
|
||||
while(offset < (ssize_t)line.size())
|
||||
{
|
||||
ssize_t written = write(queue_fd, line.data() + offset, line.size() - offset);
|
||||
if(written <= 0)
|
||||
break;
|
||||
offset += written;
|
||||
}
|
||||
close(queue_fd);
|
||||
}
|
||||
compiler_close_lock_file(fd);
|
||||
}
|
||||
|
||||
StringList compiler_take_priority_units(Request* context)
|
||||
{
|
||||
StringList result;
|
||||
if(!context || !context->server)
|
||||
return(result);
|
||||
String queue_file = compiler_priority_file_name(context);
|
||||
int fd = compiler_open_lock_file(queue_file + ".lock", "proactive-priority");
|
||||
if(fd < 0)
|
||||
return(result);
|
||||
if(file_exists(queue_file))
|
||||
{
|
||||
for(auto file_name : split(file_get_contents(queue_file), "\n"))
|
||||
{
|
||||
file_name = trim(file_name);
|
||||
if(file_name != "" && std::find(result.begin(), result.end(), file_name) == result.end())
|
||||
result.push_back(file_name);
|
||||
}
|
||||
file_put_contents(queue_file, "");
|
||||
}
|
||||
compiler_close_lock_file(fd);
|
||||
return(result);
|
||||
}
|
||||
|
||||
void unit_render(String file_name)
|
||||
{
|
||||
unit_render(file_name, *context);
|
||||
|
||||
Reference in New Issue
Block a user