Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
22d21ebe
Commit
22d21ebe
authored
Aug 17, 2017
by
Rémi Verschelde
Committed by
GitHub
Aug 17, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8144 from supagu/symlink
Reworked change_dir to support symlinks
parents
e2c1792d
d3b7d427
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
22 deletions
+23
-22
dir_access_unix.cpp
drivers/unix/dir_access_unix.cpp
+23
-22
No files found.
drivers/unix/dir_access_unix.cpp
View file @
22d21ebe
...
...
@@ -223,36 +223,37 @@ Error DirAccessUnix::make_dir(String p_dir) {
Error
DirAccessUnix
::
change_dir
(
String
p_dir
)
{
GLOBAL_LOCK_FUNCTION
p_dir
=
fix_path
(
p_dir
);
char
real_current_dir_name
[
2048
];
getcwd
(
real_current_dir_name
,
2048
);
String
prev_dir
;
if
(
prev_dir
.
parse_utf8
(
real_current_dir_name
))
prev_dir
=
real_current_dir_name
;
//no utf8, maybe latin?
// make sure current_dir is valid absolute path
if
(
current_dir
==
"."
||
current_dir
==
""
)
{
char
real_current_dir_name
[
2048
];
getcwd
(
real_current_dir_name
,
2048
);
current_dir
.
parse_utf8
(
real_current_dir_name
);
}
chdir
(
current_dir
.
utf8
().
get_data
());
//ascii since this may be unicode or wathever the host os wants
bool
worked
=
(
chdir
(
p_dir
.
utf8
().
get_data
())
==
0
);
// we can only give this utf8
if
(
p_dir
==
"."
)
{
return
OK
;
}
String
base
=
_get_root_path
();
if
(
base
!=
""
)
{
p_dir
=
fix_path
(
p_dir
);
getcwd
(
real_current_dir_name
,
2048
);
String
new_dir
;
new_dir
.
parse_utf8
(
real_current_dir_name
);
if
(
!
new_dir
.
begins_with
(
base
))
worked
=
false
;
}
String
prev_dir
=
current_dir
;
if
(
worked
)
{
if
(
p_dir
.
is_rel_path
())
{
String
next_dir
=
current_dir
+
"/"
+
p_dir
;
next_dir
=
next_dir
.
simplify_path
();
current_dir
=
next_dir
;
}
else
{
current_dir
=
p_dir
;
}
getcwd
(
real_current_dir_name
,
2048
);
if
(
current_dir
.
parse_utf8
(
real_current_dir_name
))
current_dir
=
real_current_dir_name
;
//no utf8, maybe latin?
bool
worked
=
(
chdir
(
current_dir
.
utf8
().
get_data
())
==
0
);
// we can only give this utf8
if
(
!
worked
)
{
current_dir
=
prev_dir
;
return
ERR_INVALID_PARAMETER
;
}
chdir
(
prev_dir
.
utf8
().
get_data
());
return
worked
?
OK
:
ERR_INVALID_PARAMETER
;
return
OK
;
}
String
DirAccessUnix
::
get_current_dir
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment