Resolve compiler source paths through file descriptors

This commit is contained in:
udo
2026-07-17 22:51:46 +00:00
parent 914cf17f23
commit 37b03eb4d5
2 changed files with 28 additions and 1 deletions
+18 -1
View File
@@ -158,6 +158,23 @@ bool compiler_source_readable(String file_name, const struct stat& info, int* re
return(error == 0);
}
String compiler_source_path_real(String file_name)
{
int fd = open(file_name.c_str(), O_PATH | O_CLOEXEC);
if(fd < 0)
return(path_real(file_name));
String proc_path = "/proc/self/fd/" + std::to_string(fd);
char resolved[PATH_MAX];
ssize_t length = readlink(proc_path.c_str(), resolved, sizeof(resolved));
close(fd);
if(length <= 0 || length >= (ssize_t)sizeof(resolved))
return(path_real(file_name));
String result(resolved, (size_t)length);
if(str_ends_with(result, " (deleted)"))
return(path_real(file_name));
return(result);
}
UnitSourceSignatureEntry compiler_unit_source_entry(String file_name, bool allow_recent_stat)
{
auto checked_at = std::chrono::steady_clock::now();
@@ -204,7 +221,7 @@ void compiler_append_unit_source_signature(String file_name, std::set<String>& v
bool recent = allow_recent_stat && compiler_recent_unit_source_entry(normalized, entry);
if(!recent)
{
normalized = path_real(file_name);
normalized = compiler_source_path_real(file_name);
if(normalized == "")
normalized = file_name;
}