static bool need_emulate(std::string const &path) { //RHO_LOG("need_emulate: %s", path.c_str()); std::string fpath = make_full_path(path); //RHO_LOG("need_emulate: (1): %s", fpath.c_str()); std::string const &root_path = rho_root_path(); if (::strncmp(fpath.c_str(), root_path.c_str(), root_path.size()) == 0) { //RHO_LOG("need_emulate: (2)"); struct stat st; if (real_stat(fpath.c_str(), &st) == -1) { //RHO_LOG("need_emulate: (3)"); if (errno == ENOENT) { //RHO_LOG("No such file or directory: %s, need to read it from Android package", fpath.substr(root_path.size()).c_str()); rho_stat_t *rst = rho_stat(fpath); return rst != NULL; } } else if (S_ISREG(st.st_mode)) { //RHO_LOG("need_emulate: (4)"); rho_stat_t *rst = rho_stat(fpath); //RHO_LOG("need_emulate: (5)"); if (rst && rst->mtime > st.st_mtime) { //RHO_LOG("need_emulate: %s, st.st_mtime: %lu", fpath.c_str(), st.st_mtime); //RHO_LOG("need_emulate: %s, rst->mtime: %lu", fpath.c_str(), rst ? rst->mtime : -1); //RHO_LOG("need_emulate: file %s in Android package is newer than one located on FS, unlink FS one", fpath.c_str()); real_unlink(fpath.c_str()); return true; } } } //RHO_LOG("need_emulate: return false"); return false; }
static rho_stat_t *rho_stat(int fd) { if (fd < RHO_FD_BASE) return NULL; scoped_lock_t guard(rho_fd_mtx); rho_fd_map_t::iterator it = rho_fd_map.find(fd); if (it == rho_fd_map.end()) return NULL; return rho_stat(make_rel_path(it->second.fpath)); }
static bool need_emulate(std::string const &path) { if (rho_fs_mode != RHO_FS_TRANSPARRENT) return false; std::string fpath = make_full_path(path); std::string const &root_path = rho_root_path(); if (::strncmp(fpath.c_str(), root_path.c_str(), root_path.size()) == 0) { struct stat st; if (real_stat(fpath.c_str(), &st) == -1) { if (errno == ENOENT) { rho_stat_t *rst = rho_stat(fpath); return rst != NULL; } } } return false; }
static rho_stat_t *rho_stat(std::string const &path) { return rho_stat(path.c_str()); }