Use temp dirs instead of cache dirs for export

Fixes #95897
During CI scenarios $HOME may be set to an invalid value (such as
`/var/empty`).
Using temp dirs fits better with godot's usage of these paths and is
independent from the user's $HOME.
This commit is contained in:
ArchercatNEO 2024-12-07 17:31:22 +00:00
parent aa8d9b83f6
commit 00a791f04e
9 changed files with 36 additions and 36 deletions

View File

@ -214,7 +214,7 @@ bool CodeSignCodeResources::add_nested_file(const String &p_root, const String &
Vector<String> files_to_add;
if (LipO::is_lipo(p_exepath)) {
String tmp_path_name = EditorPaths::get_singleton()->get_cache_dir().path_join("_lipo");
String tmp_path_name = EditorPaths::get_singleton()->get_temp_dir().path_join("_lipo");
Error err = da->make_dir_recursive(tmp_path_name);
ERR_FAIL_COND_V_MSG(err != OK, false, vformat("CodeSign/CodeResources: Failed to create \"%s\" subfolder.", tmp_path_name));
LipO lip;
@ -1248,7 +1248,7 @@ Error CodeSign::_codesign_file(bool p_use_hardened_runtime, bool p_force, const
Vector<String> files_to_sign;
if (LipO::is_lipo(main_exe)) {
print_verbose(vformat("CodeSign: Executable is fat, extracting..."));
String tmp_path_name = EditorPaths::get_singleton()->get_cache_dir().path_join("_lipo");
String tmp_path_name = EditorPaths::get_singleton()->get_temp_dir().path_join("_lipo");
Error err = da->make_dir_recursive(tmp_path_name);
if (err != OK) {
r_error_msg = vformat(TTR("Failed to create \"%s\" subfolder."), tmp_path_name);

View File

@ -1528,7 +1528,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
}
String config_file = "project.binary";
String engine_cfb = EditorPaths::get_singleton()->get_cache_dir().path_join("tmp" + config_file);
String engine_cfb = EditorPaths::get_singleton()->get_temp_dir().path_join("tmp" + config_file);
ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list);
Vector<uint8_t> data = FileAccess::get_file_as_bytes(engine_cfb);
DirAccess::remove_file_or_error(engine_cfb);
@ -1832,9 +1832,9 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
// Create the temporary export directory if it doesn't exist.
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
da->make_dir_recursive(EditorPaths::get_singleton()->get_cache_dir());
da->make_dir_recursive(EditorPaths::get_singleton()->get_temp_dir());
String tmppath = EditorPaths::get_singleton()->get_cache_dir().path_join("packtmp");
String tmppath = EditorPaths::get_singleton()->get_temp_dir().path_join("packtmp");
Ref<FileAccess> ftmp = FileAccess::open(tmppath, FileAccess::WRITE);
if (ftmp.is_null()) {
add_message(EXPORT_MESSAGE_ERROR, TTR("Save PCK"), vformat(TTR("Cannot create file \"%s\"."), tmppath));
@ -2094,7 +2094,7 @@ Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, bo
p_save_func = _save_zip_file;
}
String tmppath = EditorPaths::get_singleton()->get_cache_dir().path_join("packtmp");
String tmppath = EditorPaths::get_singleton()->get_temp_dir().path_join("packtmp");
Ref<FileAccess> io_fa;
zlib_filefunc_def io = zipio_create_io(&io_fa);

View File

@ -2085,7 +2085,7 @@ Error EditorExportPlatformAndroid::run(const Ref<EditorExportPreset> &p_preset,
p_debug_flags.set_flag(DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST);
}
String tmp_export_path = EditorPaths::get_singleton()->get_cache_dir().path_join("tmpexport." + uitos(OS::get_singleton()->get_unix_time()) + ".apk");
String tmp_export_path = EditorPaths::get_singleton()->get_temp_dir().path_join("tmpexport." + uitos(OS::get_singleton()->get_unix_time()) + ".apk");
#define CLEANUP_AND_RETURN(m_err) \
{ \
@ -3445,7 +3445,7 @@ Error EditorExportPlatformAndroid::export_project_helper(const Ref<EditorExportP
Ref<FileAccess> io2_fa;
zlib_filefunc_def io2 = zipio_create_io(&io2_fa);
String tmp_unaligned_path = EditorPaths::get_singleton()->get_cache_dir().path_join("tmpexport-unaligned." + uitos(OS::get_singleton()->get_unix_time()) + ".apk");
String tmp_unaligned_path = EditorPaths::get_singleton()->get_temp_dir().path_join("tmpexport-unaligned." + uitos(OS::get_singleton()->get_unix_time()) + ".apk");
#define CLEANUP_AND_RETURN(m_err) \
{ \

View File

@ -2433,7 +2433,7 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres
if (p_preset->get("application/generate_simulator_library_if_missing").operator bool()) {
String sim_lib_path = dest_dir + String(binary_name + ".xcframework").path_join("ios-arm64_x86_64-simulator").path_join("libgodot.a");
String dev_lib_path = dest_dir + String(binary_name + ".xcframework").path_join("ios-arm64").path_join("libgodot.a");
String tmp_lib_path = EditorPaths::get_singleton()->get_cache_dir().path_join(binary_name + "_lipo_");
String tmp_lib_path = EditorPaths::get_singleton()->get_temp_dir().path_join(binary_name + "_lipo_");
uint32_t cputype = 0;
uint32_t cpusubtype = 0;
if (!_archive_has_arm64(sim_lib_path, &cputype, &cpusubtype) && _archive_has_arm64(dev_lib_path) && FileAccess::exists(dev_lib_path)) {
@ -3111,19 +3111,19 @@ Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int
String id = "tmpexport." + uitos(OS::get_singleton()->get_unix_time());
Ref<DirAccess> filesystem_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + EditorPaths::get_singleton()->get_cache_dir() + "'.");
filesystem_da->make_dir_recursive(EditorPaths::get_singleton()->get_cache_dir().path_join(id));
String tmp_export_path = EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.ipa");
ERR_FAIL_COND_V_MSG(filesystem_da.is_null(), ERR_CANT_CREATE, "Cannot create DirAccess for path '" + EditorPaths::get_singleton()->get_temp_dir() + "'.");
filesystem_da->make_dir_recursive(EditorPaths::get_singleton()->get_temp_dir().path_join(id));
String tmp_export_path = EditorPaths::get_singleton()->get_temp_dir().path_join(id).path_join("export.ipa");
#define CLEANUP_AND_RETURN(m_err) \
{ \
if (filesystem_da->change_dir(EditorPaths::get_singleton()->get_cache_dir().path_join(id)) == OK) { \
filesystem_da->erase_contents_recursive(); \
filesystem_da->change_dir(".."); \
filesystem_da->remove(id); \
} \
return m_err; \
} \
#define CLEANUP_AND_RETURN(m_err) \
{ \
if (filesystem_da->change_dir(EditorPaths::get_singleton()->get_temp_dir().path_join(id)) == OK) { \
filesystem_da->erase_contents_recursive(); \
filesystem_da->change_dir(".."); \
filesystem_da->remove(id); \
} \
return m_err; \
} \
((void)0)
Device dev = devices[p_device];
@ -3193,7 +3193,7 @@ Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int
args.push_back("simctl");
args.push_back("install");
args.push_back(dev.id);
args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
args.push_back(EditorPaths::get_singleton()->get_temp_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
String log;
int ec;
@ -3246,7 +3246,7 @@ Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int
args.push_back(dev.id);
args.push_back("--justlaunch");
args.push_back("--bundle");
args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
args.push_back(EditorPaths::get_singleton()->get_temp_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
String app_args;
for (const String &E : cmd_args_list) {
app_args += E + " ";
@ -3285,7 +3285,7 @@ Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int
args.push_back("app");
args.push_back("-d");
args.push_back(dev.id);
args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
args.push_back(EditorPaths::get_singleton()->get_temp_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app"));
String log;
int ec;

View File

@ -88,7 +88,7 @@ Error EditorExportPlatformLinuxBSD::export_project(const Ref<EditorExportPreset>
// Setup temp folder.
String path = p_path;
String tmp_dir_path = EditorPaths::get_singleton()->get_cache_dir().path_join(pkg_name);
String tmp_dir_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);
Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_dir_path);
if (export_as_zip) {
@ -468,7 +468,7 @@ Error EditorExportPlatformLinuxBSD::run(const Ref<EditorExportPreset> &p_preset,
EditorProgress ep("run", TTR("Running..."), 5);
const String dest = EditorPaths::get_singleton()->get_cache_dir().path_join("linuxbsd");
const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("linuxbsd");
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
if (!da->dir_exists(dest)) {
Error err = da->make_dir_recursive(dest);

View File

@ -1592,7 +1592,7 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
tmp_app_path_name = p_path;
scr_path = p_path.get_basename() + ".command";
} else {
tmp_base_path_name = EditorPaths::get_singleton()->get_cache_dir().path_join(pkg_name);
tmp_base_path_name = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);
tmp_app_path_name = tmp_base_path_name.path_join(tmp_app_dir_name);
scr_path = tmp_base_path_name.path_join(pkg_name + ".command");
}
@ -1987,9 +1987,9 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
bool sandbox = p_preset->get("codesign/entitlements/app_sandbox/enabled");
String ent_path = p_preset->get("codesign/entitlements/custom_file");
String hlp_ent_path = sandbox ? EditorPaths::get_singleton()->get_cache_dir().path_join(pkg_name + "_helper.entitlements") : ent_path;
String hlp_ent_path = sandbox ? EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + "_helper.entitlements") : ent_path;
if (sign_enabled && (ent_path.is_empty())) {
ent_path = EditorPaths::get_singleton()->get_cache_dir().path_join(pkg_name + ".entitlements");
ent_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".entitlements");
Ref<FileAccess> ent_f = FileAccess::open(ent_path, FileAccess::WRITE);
if (ent_f.is_valid()) {
@ -2269,7 +2269,7 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
} else if (export_format == "app" && noto_enabled) {
// Create temporary ZIP.
if (err == OK) {
noto_path = EditorPaths::get_singleton()->get_cache_dir().path_join(pkg_name + ".zip");
noto_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name + ".zip");
if (ep.step(TTR("Making ZIP"), 3)) {
return ERR_SKIP;
@ -2554,7 +2554,7 @@ Error EditorExportPlatformMacOS::run(const Ref<EditorExportPreset> &p_preset, in
EditorProgress ep("run", TTR("Running..."), 5);
const String dest = EditorPaths::get_singleton()->get_cache_dir().path_join("macos");
const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("macos");
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
if (!da->dir_exists(dest)) {
Error err = da->make_dir_recursive(dest);

View File

@ -86,7 +86,7 @@ void EditorHTTPServer::_send_response() {
const String req_file = path.get_file();
const String req_ext = path.get_extension();
const String cache_path = EditorPaths::get_singleton()->get_cache_dir().path_join("web");
const String cache_path = EditorPaths::get_singleton()->get_temp_dir().path_join("web");
const String filepath = cache_path.path_join(req_file);
if (!mimes.has(req_ext) || !FileAccess::exists(filepath)) {

View File

@ -817,7 +817,7 @@ Error EditorExportPlatformWeb::run(const Ref<EditorExportPreset> &p_preset, int
}
Error EditorExportPlatformWeb::_export_project(const Ref<EditorExportPreset> &p_preset, int p_debug_flags) {
const String dest = EditorPaths::get_singleton()->get_cache_dir().path_join("web");
const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("web");
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
if (!da->dir_exists(dest)) {
Error err = da->make_dir_recursive(dest);

View File

@ -257,7 +257,7 @@ Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset>
// Setup temp folder.
String path = p_path;
String tmp_dir_path = EditorPaths::get_singleton()->get_cache_dir().path_join(pkg_name);
String tmp_dir_path = EditorPaths::get_singleton()->get_temp_dir().path_join(pkg_name);
Ref<DirAccess> tmp_app_dir = DirAccess::create_for_path(tmp_dir_path);
if (export_as_zip) {
if (tmp_app_dir.is_null()) {
@ -501,7 +501,7 @@ Error EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset
}
}
String tmp_icon_path = EditorPaths::get_singleton()->get_cache_dir().path_join("_rcedit.ico");
String tmp_icon_path = EditorPaths::get_singleton()->get_temp_dir().path_join("_rcedit.ico");
if (!icon_path.is_empty()) {
if (_process_icon(p_preset, icon_path, tmp_icon_path) != OK) {
add_message(EXPORT_MESSAGE_WARNING, TTR("Resources Modification"), vformat(TTR("Invalid icon file \"%s\"."), icon_path));
@ -1004,7 +1004,7 @@ Error EditorExportPlatformWindows::run(const Ref<EditorExportPreset> &p_preset,
EditorProgress ep("run", TTR("Running..."), 5);
const String dest = EditorPaths::get_singleton()->get_cache_dir().path_join("windows");
const String dest = EditorPaths::get_singleton()->get_temp_dir().path_join("windows");
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
if (!da->dir_exists(dest)) {
Error err = da->make_dir_recursive(dest);