Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd6b4494 authored by ELIYAZ MOMIN (xWF)'s avatar ELIYAZ MOMIN (xWF) Committed by Android (Google) Code Review
Browse files

Merge "Revert "[res] Better modification time resolution in Idmap"" into main

parents 7d6f3bab e2cc267a
Loading
Loading
Loading
Loading
+15 −17
Original line number Diff line number Diff line
@@ -1420,12 +1420,10 @@ void AssetManager::mergeInfoLocked(SortedVector<AssetDir::FileInfo>* pMergedInfo
Mutex AssetManager::SharedZip::gLock;
DefaultKeyedVector<String8, wp<AssetManager::SharedZip> > AssetManager::SharedZip::gOpen;

AssetManager::SharedZip::SharedZip(const String8& path, ModDate modWhen)
    : mPath(path),
      mZipFile(NULL),
      mModWhen(modWhen),
      mResourceTableAsset(NULL),
      mResourceTable(NULL) {
AssetManager::SharedZip::SharedZip(const String8& path, time_t modWhen)
    : mPath(path), mZipFile(NULL), mModWhen(modWhen),
      mResourceTableAsset(NULL), mResourceTable(NULL)
{
    if (kIsDebug) {
        ALOGI("Creating SharedZip %p %s\n", this, mPath.c_str());
    }
@@ -1455,7 +1453,7 @@ sp<AssetManager::SharedZip> AssetManager::SharedZip::get(const String8& path,
        bool createIfNotPresent)
{
    AutoMutex _l(gLock);
    auto modWhen = getFileModDate(path.c_str());
    time_t modWhen = getFileModDate(path.c_str());
    sp<SharedZip> zip = gOpen.valueFor(path).promote();
    if (zip != NULL && zip->mModWhen == modWhen) {
        return zip;
@@ -1522,7 +1520,7 @@ ResTable* AssetManager::SharedZip::setResourceTable(ResTable* res)

bool AssetManager::SharedZip::isUpToDate()
{
  auto modWhen = getFileModDate(mPath.c_str());
    time_t modWhen = getFileModDate(mPath.c_str());
    return mModWhen == modWhen;
}

+11 −11
Original line number Diff line number Diff line
@@ -280,13 +280,13 @@ private:
        ~SharedZip();

    private:
     SharedZip(const String8& path, ModDate modWhen);
        SharedZip(const String8& path, time_t modWhen);
        SharedZip(int fd, const String8& path);
        SharedZip(); // <-- not implemented

        String8 mPath;
        ZipFileRO* mZipFile;
     ModDate mModWhen;
        time_t mModWhen;

        Asset* mResourceTableAsset;
        ResTable* mResourceTable;
+2 −3
Original line number Diff line number Diff line
@@ -25,9 +25,8 @@
#include "android-base/macros.h"
#include "android-base/unique_fd.h"
#include "androidfw/ConfigDescription.h"
#include "androidfw/ResourceTypes.h"
#include "androidfw/StringPiece.h"
#include "androidfw/misc.h"
#include "androidfw/ResourceTypes.h"
#include "utils/ByteOrder.h"

namespace android {
@@ -203,7 +202,7 @@ class LoadedIdmap {
  android::base::unique_fd idmap_fd_;
  std::string_view overlay_apk_path_;
  std::string_view target_apk_path_;
  ModDate idmap_last_mod_time_;
  time_t idmap_last_mod_time_;

 private:
  DISALLOW_COPY_AND_ASSIGN(LoadedIdmap);
+8 −27
Original line number Diff line number Diff line
@@ -13,13 +13,14 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <time.h>
#include <sys/types.h>

//
// Handy utility functions and portability code.
//
#ifndef _LIBS_ANDROID_FW_MISC_H
#define _LIBS_ANDROID_FW_MISC_H

namespace android {

@@ -40,35 +41,15 @@ typedef enum FileType {
} FileType;
/* get the file's type; follows symlinks */
FileType getFileType(const char* fileName);

// MinGW doesn't support nanosecond resolution in stat() modification time, and given
// that it only matters on the device it's ok to keep it at the second level there.
#ifdef _WIN32
using ModDate = time_t;
inline constexpr ModDate kInvalidModDate = ModDate(-1);
inline constexpr unsigned long long kModDateResolutionNs = 1ull * 1000 * 1000 * 1000;
inline time_t toTimeT(ModDate m) {
  return m;
}
#else
using ModDate = timespec;
inline constexpr ModDate kInvalidModDate = {-1, -1};
inline constexpr unsigned long long kModDateResolutionNs = 1;
inline time_t toTimeT(ModDate m) {
  return m.tv_sec;
}
#endif

/* get the file's modification date; returns kInvalidModDate w/errno set on failure */
ModDate getFileModDate(const char* fileName);
/* get the file's modification date; returns -1 w/errno set on failure */
time_t getFileModDate(const char* fileName);
/* same, but also returns -1 if the file has already been deleted */
ModDate getFileModDate(int fd);
time_t getFileModDate(int fd);

// Check if |path| or |fd| resides on a readonly filesystem.
bool isReadonlyFilesystem(const char* path);
bool isReadonlyFilesystem(int fd);

}  // namespace android
}; // namespace android

// Whoever uses getFileModDate() will need this as well
bool operator==(const timespec& l, const timespec& r);
#endif // _LIBS_ANDROID_FW_MISC_H
+22 −33
Original line number Diff line number Diff line
@@ -28,13 +28,11 @@
#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 {

/*
@@ -75,32 +73,27 @@ FileType getFileType(const char* fileName)
    }
}

static ModDate getModDate(const struct stat& st) {
#ifdef _WIN32
  return st.st_mtime;
#else
  return st.st_mtim;
#endif
}

ModDate getFileModDate(const char* fileName) {
/*
 * Get a file's modification date.
 */
time_t getFileModDate(const char* fileName) {
    struct stat sb;
    if (stat(fileName, &sb) < 0) {
    return kInvalidModDate;
        return (time_t)-1;
    }
  return getModDate(sb);
    return sb.st_mtime;
}

ModDate getFileModDate(int fd) {
time_t getFileModDate(int fd) {
    struct stat sb;
    if (fstat(fd, &sb) < 0) {
    return kInvalidModDate;
        return (time_t)-1;
    }
    if (sb.st_nlink <= 0) {
        errno = ENOENT;
    return kInvalidModDate;
        return (time_t)-1;
    }
  return getModDate(sb);
    return sb.st_mtime;
}

#ifndef __linux__
@@ -131,8 +124,4 @@ bool isReadonlyFilesystem(int fd) {
}
#endif  // __linux__

}  // 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);
}
}; // namespace android
Loading