diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-08-10 13:28:47 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-10 13:28:47 -0300 |
commit | 275e0d5ee4e80d9d3cd124ffa29a691b9aed3e70 (patch) | |
tree | 6cb7e7f8bec4a2d599ecd0dbbc17f651c56fc710 /drivers/unix | |
parent | b9730a695643af15bd97f9b87ae656b735281bba (diff) | |
parent | d315b0fb8aa03ee6ecc7d93d884b606dc19c6ad5 (diff) |
Merge pull request #18914 from notwarp/master
added get_creation_time function for gdscript
Diffstat (limited to 'drivers/unix')
-rw-r--r-- | drivers/unix/dir_access_unix.cpp | 20 | ||||
-rw-r--r-- | drivers/unix/dir_access_unix.h | 1 | ||||
-rw-r--r-- | drivers/unix/file_access_unix.cpp | 16 | ||||
-rw-r--r-- | drivers/unix/file_access_unix.h | 1 |
4 files changed, 38 insertions, 0 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 5a4be6df4f..8b2d05c7e9 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -124,6 +124,26 @@ uint64_t DirAccessUnix::get_modified_time(String p_file) { return 0; }; +// NEW FUNCTION +uint64_t DirAccessUnix::get_creation_time(String p_file) { + + if (p_file.is_rel_path()) + p_file = current_dir.plus_file(p_file); + + p_file = fix_path(p_file); + + struct stat flags; + bool success = (stat(p_file.utf8().get_data(), &flags) == 0); + + if (success) { + return flags.st_ctime; + } else { + + ERR_FAIL_V(0); + }; + return 0; +}; + String DirAccessUnix::get_next() { if (!dir_stream) diff --git a/drivers/unix/dir_access_unix.h b/drivers/unix/dir_access_unix.h index a55acdbd34..815de5239c 100644 --- a/drivers/unix/dir_access_unix.h +++ b/drivers/unix/dir_access_unix.h @@ -75,6 +75,7 @@ public: virtual bool dir_exists(String p_dir); virtual uint64_t get_modified_time(String p_file); + virtual uint64_t get_creation_time(String p_file); // NEW FUNCTION virtual Error rename(String p_path, String p_new_path); virtual Error remove(String p_path); diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index c25d34125d..76b2676c71 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -297,6 +297,22 @@ uint64_t FileAccessUnix::_get_modified_time(const String &p_file) { }; } +// NEW FUNCTION +uint64_t FileAccessUnix::_get_creation_time(const String &p_file) { + + String file = fix_path(p_file); + struct stat flags; + int err = stat(file.utf8().get_data(), &flags); + + if (!err) { + return flags.st_ctime; + } else { + print_line("ERROR IN: " + p_file); + + ERR_FAIL_V(0); + }; +} + Error FileAccessUnix::_chmod(const String &p_path, int p_mod) { int err = chmod(p_path.utf8().get_data(), p_mod); if (!err) { diff --git a/drivers/unix/file_access_unix.h b/drivers/unix/file_access_unix.h index 88bb39fbd1..f81a4847d2 100644 --- a/drivers/unix/file_access_unix.h +++ b/drivers/unix/file_access_unix.h @@ -84,6 +84,7 @@ public: virtual bool file_exists(const String &p_path); ///< return true if a file exists virtual uint64_t _get_modified_time(const String &p_file); + virtual uint64_t _get_creation_time(const String &p_file); // NEW FUNCTION virtual Error _chmod(const String &p_path, int p_mod); |