diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-05-24 15:14:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-24 15:14:02 +0200 |
commit | 65eff1cfddb2ac2a627679f01c8efb90c4d6c34d (patch) | |
tree | 253aa1932415fbf56c71c88c67f907f1131f09ef /drivers/unix/dir_access_unix.cpp | |
parent | 9cf1d034a7f08c37f3c7f4660c50c8784864daa3 (diff) | |
parent | a1cb6f07a1f4c85c6e00e9cdcb18e048846fc706 (diff) |
Merge pull request #46866 from bruvzg/symlinks_and_macos_gdn_framework_export_4
Diffstat (limited to 'drivers/unix/dir_access_unix.cpp')
-rw-r--r-- | drivers/unix/dir_access_unix.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 3323da5db4..5abe5d2c87 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -406,6 +406,53 @@ Error DirAccessUnix::remove(String p_path) { } } +bool DirAccessUnix::is_link(String p_file) { + if (p_file.is_rel_path()) { + p_file = get_current_dir().plus_file(p_file); + } + + p_file = fix_path(p_file); + + struct stat flags; + if ((lstat(p_file.utf8().get_data(), &flags) != 0)) { + return FAILED; + } + + return S_ISLNK(flags.st_mode); +} + +String DirAccessUnix::read_link(String p_file) { + if (p_file.is_rel_path()) { + p_file = get_current_dir().plus_file(p_file); + } + + p_file = fix_path(p_file); + + char buf[256]; + memset(buf, 0, 256); + ssize_t len = readlink(p_file.utf8().get_data(), buf, sizeof(buf)); + String link; + if (len > 0) { + link.parse_utf8(buf, len); + } + return link; +} + +Error DirAccessUnix::create_link(String p_source, String p_target) { + if (p_target.is_rel_path()) { + p_target = get_current_dir().plus_file(p_target); + } + + p_source = fix_path(p_source); + p_target = fix_path(p_target); + + if (symlink(p_source.utf8().get_data(), p_target.utf8().get_data()) == 0) { + return OK; + } else { + return FAILED; + } +} + uint64_t DirAccessUnix::get_space_left() { #ifndef NO_STATVFS struct statvfs vfs; |