mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 03:32:46 +00:00
add resolve_symlinks parameter to path_resolve_realpath() and cleanup playlist_resolve_path()
This commit is contained in:
parent
7006764c12
commit
6285c05948
@ -53,7 +53,7 @@ bool glslang_read_shader_file(const char *path, vector<string> *output, bool roo
|
||||
include_path[0] = tmp[0] = '\0';
|
||||
|
||||
strlcpy(tmp_path, path, path_size);
|
||||
path_resolve_realpath(tmp_path, path_size);
|
||||
path_resolve_realpath(tmp_path, path_size, false);
|
||||
|
||||
if (!path_is_valid(tmp_path))
|
||||
strlcpy(tmp_path, path, path_size);
|
||||
|
@ -756,7 +756,7 @@ void video_shader_write_conf_preset(config_file_t *conf,
|
||||
strlcpy(tmp_base, preset_path, tmp_size);
|
||||
|
||||
/* ensure we use a clean base like the shader passes and texture paths do */
|
||||
path_resolve_realpath(tmp_base, tmp_size);
|
||||
path_resolve_realpath(tmp_base, tmp_size, false);
|
||||
path_basedir(tmp_base);
|
||||
}
|
||||
|
||||
|
@ -758,6 +758,7 @@ bool path_is_absolute(const char *path)
|
||||
* path_resolve_realpath:
|
||||
* @buf : input and output buffer for path
|
||||
* @size : size of buffer
|
||||
* @resolve_symlinks : whether to resolve symlinks or not
|
||||
*
|
||||
* Resolves use of ".", "..", multiple slashes etc in absolute paths.
|
||||
*
|
||||
@ -765,11 +766,12 @@ bool path_is_absolute(const char *path)
|
||||
*
|
||||
* Returns: @buf if successful, NULL otherwise.
|
||||
* Note: Not implemented on consoles
|
||||
* Note: Symlinks are only resolved on Unix-likes
|
||||
* Note: The current working dir might not be what you expect,
|
||||
* e.g. on Android it is "/"
|
||||
* Use of fill_pathname_resolve_relative() should be prefered
|
||||
**/
|
||||
char *path_resolve_realpath(char *buf, size_t size)
|
||||
char *path_resolve_realpath(char *buf, size_t size, bool resolve_symlinks)
|
||||
{
|
||||
#if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL)
|
||||
char tmp[PATH_MAX_LENGTH];
|
||||
@ -782,10 +784,30 @@ char *path_resolve_realpath(char *buf, size_t size)
|
||||
}
|
||||
return buf;
|
||||
#else
|
||||
size_t t = 0; /* length of output */
|
||||
size_t t;
|
||||
char *p;
|
||||
const char *next;
|
||||
const char *buf_end = buf + strlen(buf);
|
||||
const char *buf_end;
|
||||
|
||||
if (resolve_symlinks)
|
||||
{
|
||||
strlcpy(tmp, buf, sizeof(tmp));
|
||||
|
||||
/* NOTE: realpath() expects at least PATH_MAX_LENGTH bytes in buf.
|
||||
* Technically, PATH_MAX_LENGTH needn't be defined, but we rely on it anyways.
|
||||
* POSIX 2008 can automatically allocate for you,
|
||||
* but don't rely on that. */
|
||||
if (!realpath(tmp, buf))
|
||||
{
|
||||
strlcpy(buf, tmp, size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
t = 0; /* length of output */
|
||||
buf_end = buf + strlen(buf);
|
||||
|
||||
if (!path_is_absolute(buf))
|
||||
{
|
||||
@ -933,7 +955,7 @@ void fill_pathname_resolve_relative(char *out_path,
|
||||
|
||||
fill_pathname_basedir(out_path, in_refpath, size);
|
||||
strlcat(out_path, in_path, size);
|
||||
path_resolve_realpath(out_path, size);
|
||||
path_resolve_realpath(out_path, size, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,6 +149,7 @@ void path_parent_dir(char *path);
|
||||
* path_resolve_realpath:
|
||||
* @buf : input and output buffer for path
|
||||
* @size : size of buffer
|
||||
* @resolve_symlinks : whether to resolve symlinks or not
|
||||
*
|
||||
* Resolves use of ".", "..", multiple slashes etc in absolute paths.
|
||||
*
|
||||
@ -156,11 +157,12 @@ void path_parent_dir(char *path);
|
||||
*
|
||||
* Returns: @buf if successful, NULL otherwise.
|
||||
* Note: Not implemented on consoles
|
||||
* Note: Symlinks are only resolved on Unix-likes
|
||||
* Note: The current working dir might not be what you expect,
|
||||
* e.g. on Android it is "/"
|
||||
* Use of fill_pathname_resolve_relative() should be prefered
|
||||
**/
|
||||
char *path_resolve_realpath(char *buf, size_t size);
|
||||
char *path_resolve_realpath(char *buf, size_t size, bool resolve_symlinks);
|
||||
|
||||
/**
|
||||
* path_relative_to:
|
||||
|
58
playlist.c
58
playlist.c
@ -104,7 +104,7 @@ static bool playlist_path_equal(const char *real_path, const char *entry_path)
|
||||
|
||||
/* Get entry 'real' path */
|
||||
strlcpy(entry_real_path, entry_path, sizeof(entry_real_path));
|
||||
path_resolve_realpath(entry_real_path, sizeof(entry_real_path));
|
||||
path_resolve_realpath(entry_real_path, sizeof(entry_real_path), true);
|
||||
|
||||
if (string_is_empty(entry_real_path))
|
||||
return false;
|
||||
@ -193,7 +193,7 @@ static bool playlist_core_path_equal(const char *real_core_path, const char *ent
|
||||
/* Get entry 'real' core path */
|
||||
strlcpy(entry_real_core_path, entry_core_path, sizeof(entry_real_core_path));
|
||||
if (!string_is_equal(entry_real_core_path, file_path_str(FILE_PATH_DETECT)))
|
||||
path_resolve_realpath(entry_real_core_path, sizeof(entry_real_core_path));
|
||||
path_resolve_realpath(entry_real_core_path, sizeof(entry_real_core_path), true);
|
||||
|
||||
if (string_is_empty(entry_real_core_path))
|
||||
return false;
|
||||
@ -279,7 +279,7 @@ void playlist_get_index_by_path(playlist_t *playlist,
|
||||
|
||||
/* Get 'real' search path */
|
||||
strlcpy(real_search_path, search_path, sizeof(real_search_path));
|
||||
path_resolve_realpath(real_search_path, sizeof(real_search_path));
|
||||
path_resolve_realpath(real_search_path, sizeof(real_search_path), true);
|
||||
|
||||
for (i = 0; i < playlist->size; i++)
|
||||
{
|
||||
@ -306,7 +306,7 @@ bool playlist_entry_exists(playlist_t *playlist,
|
||||
|
||||
/* Get 'real' search path */
|
||||
strlcpy(real_search_path, path, sizeof(real_search_path));
|
||||
path_resolve_realpath(real_search_path, sizeof(real_search_path));
|
||||
path_resolve_realpath(real_search_path, sizeof(real_search_path), true);
|
||||
|
||||
for (i = 0; i < playlist->size; i++)
|
||||
if (playlist_path_equal(real_search_path, playlist->entries[i].path))
|
||||
@ -539,13 +539,13 @@ bool playlist_push_runtime(playlist_t *playlist,
|
||||
if (!string_is_empty(entry->path))
|
||||
{
|
||||
strlcpy(real_path, entry->path, sizeof(real_path));
|
||||
path_resolve_realpath(real_path, sizeof(real_path));
|
||||
path_resolve_realpath(real_path, sizeof(real_path), true);
|
||||
}
|
||||
|
||||
/* Get 'real' core path */
|
||||
strlcpy(real_core_path, entry->core_path, sizeof(real_core_path));
|
||||
if (!string_is_equal(real_core_path, file_path_str(FILE_PATH_DETECT)))
|
||||
path_resolve_realpath(real_core_path, sizeof(real_core_path));
|
||||
path_resolve_realpath(real_core_path, sizeof(real_core_path), true);
|
||||
|
||||
if (string_is_empty(real_core_path))
|
||||
{
|
||||
@ -628,7 +628,7 @@ success:
|
||||
/**
|
||||
* playlist_resolve_path:
|
||||
* @mode : PLAYLIST_LOAD or PLAYLIST_SAVE
|
||||
* @path : The path to be modified
|
||||
* @path : The path to be modified
|
||||
*
|
||||
* Resolves the path of an item, such as the content path or path to the core, to a format
|
||||
* appropriate for saving or loading depending on the @mode parameter
|
||||
@ -640,32 +640,26 @@ success:
|
||||
void playlist_resolve_path(enum playlist_file_mode mode,
|
||||
char *path, size_t size)
|
||||
{
|
||||
char tmp[PATH_MAX_LENGTH];
|
||||
tmp[0] = '\0';
|
||||
#ifdef HAVE_COCOATOUCH
|
||||
char resolved_path[PATH_MAX_LENGTH] = {0};
|
||||
strlcpy(tmp, path, sizeof(tmp));
|
||||
if ( mode == PLAYLIST_LOAD )
|
||||
{
|
||||
strlcpy(resolved_path, tmp, sizeof(resolved_path));
|
||||
fill_pathname_expand_special(tmp, resolved_path, sizeof(tmp));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* iOS needs to call realpath here since the call
|
||||
* above fails due to possibly buffer related issues. */
|
||||
realpath(tmp, resolved_path);
|
||||
fill_pathname_abbreviate_special(tmp, resolved_path, sizeof(tmp));
|
||||
}
|
||||
strlcpy(path, tmp, size);
|
||||
return;
|
||||
#else
|
||||
if ( mode == PLAYLIST_LOAD)
|
||||
return;
|
||||
char tmp[PATH_MAX_LENGTH];
|
||||
|
||||
strlcpy(tmp, path, sizeof(tmp));
|
||||
path_resolve_realpath(tmp, sizeof(tmp));
|
||||
strlcpy(path, tmp, size);
|
||||
if (mode == PLAYLIST_LOAD)
|
||||
{
|
||||
fill_pathname_expand_special(tmp, path, sizeof(tmp));
|
||||
strlcpy(path, tmp, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* iOS needs to call realpath here since the call
|
||||
* above fails due to possibly buffer related issues. */
|
||||
realpath(path, tmp);
|
||||
fill_pathname_abbreviate_special(path, tmp, size);
|
||||
}
|
||||
#else
|
||||
if (mode == PLAYLIST_LOAD)
|
||||
return;
|
||||
|
||||
path_resolve_realpath(path, size, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -787,7 +781,7 @@ bool playlist_push(playlist_t *playlist,
|
||||
if (!string_is_empty(entry->subsystem_roms->elems[j].data))
|
||||
{
|
||||
strlcpy(real_rom_path, entry->subsystem_roms->elems[j].data, sizeof(real_rom_path));
|
||||
path_resolve_realpath(real_rom_path, sizeof(real_rom_path));
|
||||
path_resolve_realpath(real_rom_path, sizeof(real_rom_path), true);
|
||||
}
|
||||
|
||||
if (!playlist_path_equal(real_rom_path, roms->elems[j].data))
|
||||
|
@ -4335,7 +4335,7 @@ static bool load_dynamic_core(const char *path, char *buf, size_t size)
|
||||
/* Need to use absolute path for this setting. It can be
|
||||
* saved to content history, and a relative path would
|
||||
* break in that scenario. */
|
||||
path_resolve_realpath(buf, size);
|
||||
path_resolve_realpath(buf, size, true);
|
||||
if ((lib_handle = dylib_load(path)))
|
||||
return true;
|
||||
return false;
|
||||
|
@ -1325,7 +1325,7 @@ static void task_push_to_history_list(
|
||||
/* Path can be relative here.
|
||||
* Ensure we're pushing absolute path. */
|
||||
if (!launched_from_menu && !string_is_empty(tmp))
|
||||
path_resolve_realpath(tmp, tmp_size);
|
||||
path_resolve_realpath(tmp, tmp_size, true);
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
/* Push quick menu onto menu stack */
|
||||
|
Loading…
x
Reference in New Issue
Block a user