diff options
author | 2024-08-30 16:54:55 -0700 | |
---|---|---|
committer | 2024-09-06 16:32:50 -0700 | |
commit | fff1d48f432741160019a9266728097f10bd2189 (patch) | |
tree | 9aed65430929dcc93c27c27809c92bd5c3e1de9b /libs/androidfw/misc.cpp | |
parent | 7e33e3ae936397061a7b978047bbe454c1b27448 (diff) |
[res] Better modification time resolution in Idmap
We used to track the modification time in seconds, which is both
imprecise (an apk installation + idmap generation can easily
take less time) and forces us to wait for >1s in the tests to
just check if up-to-date checks work.
This change updates the time to nanosecond resolution where
supported (hm, MinGW for Windows, hm), as the underlying
OS API provides
Test: build + atest libandroidfw_tests idmap2_tests + boot
Flag: EXEMPT minor change
Change-Id: I37635e6f3b62aff3b4794912ac585a9ef5ea7a1e
Diffstat (limited to 'libs/androidfw/misc.cpp')
-rw-r--r-- | libs/androidfw/misc.cpp | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/libs/androidfw/misc.cpp b/libs/androidfw/misc.cpp index 93dcaf549a90..9bdaf18a116a 100644 --- a/libs/androidfw/misc.cpp +++ b/libs/androidfw/misc.cpp @@ -28,11 +28,13 @@ #include <sys/vfs.h> #endif // __linux__ -#include <cstring> -#include <cstdio> #include <errno.h> #include <sys/stat.h> +#include <cstdio> +#include <cstring> +#include <tuple> + namespace android { /* @@ -73,27 +75,32 @@ FileType getFileType(const char* fileName) } } -/* - * Get a file's modification date. - */ -time_t getFileModDate(const char* fileName) { - struct stat sb; - if (stat(fileName, &sb) < 0) { - return (time_t)-1; - } - return sb.st_mtime; +static ModDate getModDate(const struct stat& st) { +#ifdef _WIN32 + return st.st_mtime; +#else + return st.st_mtim; +#endif } -time_t getFileModDate(int fd) { - struct stat sb; - if (fstat(fd, &sb) < 0) { - return (time_t)-1; - } - if (sb.st_nlink <= 0) { - errno = ENOENT; - return (time_t)-1; - } - return sb.st_mtime; +ModDate getFileModDate(const char* fileName) { + struct stat sb; + if (stat(fileName, &sb) < 0) { + return kInvalidModDate; + } + return getModDate(sb); +} + +ModDate getFileModDate(int fd) { + struct stat sb; + if (fstat(fd, &sb) < 0) { + return kInvalidModDate; + } + if (sb.st_nlink <= 0) { + errno = ENOENT; + return kInvalidModDate; + } + return getModDate(sb); } #ifndef __linux__ @@ -124,4 +131,8 @@ bool isReadonlyFilesystem(int fd) { } #endif // __linux__ -}; // namespace android +} // namespace android + +bool operator==(const timespec& l, const timespec& r) { + return std::tie(l.tv_sec, l.tv_nsec) == std::tie(r.tv_sec, l.tv_nsec); +} |