From: Po Lu Date: Thu, 31 Aug 2023 01:04:32 +0000 (+0800) Subject: Include installation date within asset files X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=21a0caea771eae52c5e6f1fb4857f59bdc18f238;p=emacs.git Include installation date within asset files * src/android.c (setEmacsParams): Set `emacs_installation_time' to the mtime of the class path file, which happens to be the time of Emacs's installation. (emacs_installation_time): New variable. * src/android.h (emacs_installation_time): Export new variable. * src/androidvfs.c (android_afs_stat): If emacs_installation_time is a valid timespec, set st_mtime to it. --- diff --git a/src/android.c b/src/android.c index 1ccb724247d..94aeb726fc6 100644 --- a/src/android.c +++ b/src/android.c @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ #include + #include #include #include @@ -31,12 +32,15 @@ along with GNU Emacs. If not, see . */ #include #include #include +#include #include #include -#include #include #include +#include +#include + /* Old NDK versions lack MIN and MAX. */ #include @@ -47,6 +51,7 @@ along with GNU Emacs. If not, see . */ #include "blockinput.h" #include "coding.h" #include "epaths.h" +#include "systime.h" /* Whether or not Emacs is running inside the application process and Android windowing should be enabled. */ @@ -187,6 +192,10 @@ static struct android_emacs_window window_class; /* Various methods associated with the EmacsCursor class. */ static struct android_emacs_cursor cursor_class; +/* The time at which Emacs was installed, which also supplies the + mtime of asset files. */ +struct timespec emacs_installation_time; + /* The last event serial used. This is a 32 bit value, but it is stored in unsigned long to be consistent with X. */ unsigned int event_serial; @@ -1247,6 +1256,7 @@ NATIVE_NAME (setEmacsParams) (JNIEnv *env, jobject object, int pipefd[2]; pthread_t thread; const char *java_string; + struct stat statb; /* Set the Android API level early, as it is used by `android_vfs_init'. */ @@ -1341,13 +1351,24 @@ NATIVE_NAME (setEmacsParams) (JNIEnv *env, jobject object, android_class_path = strdup ((const char *) java_string); - if (!android_files_dir) + if (!android_class_path) emacs_abort (); (*env)->ReleaseStringUTFChars (env, (jstring) class_path, java_string); } + /* Derive the installation date from the modification time of the + file constitituing the class path. */ + + emacs_installation_time = invalid_timespec (); + + if (class_path) + { + if (!stat (android_class_path, &statb)) + emacs_installation_time = get_stat_mtime (&statb); + } + /* Calculate the site-lisp path. */ android_site_load_path = malloc (PATH_MAX + 1); diff --git a/src/android.h b/src/android.h index e865d7da665..a34469284d5 100644 --- a/src/android.h +++ b/src/android.h @@ -299,6 +299,10 @@ extern jobject emacs_service; /* Various methods associated with the EmacsService. */ extern struct android_emacs_service service_class; +/* The time at which Emacs was installed, which also supplies the + mtime of asset files. */ +extern struct timespec emacs_installation_time; + #define ANDROID_DELETE_LOCAL_REF(ref) \ ((*android_java_env)->DeleteLocalRef (android_java_env, \ (ref))) diff --git a/src/androidvfs.c b/src/androidvfs.c index d6b832d6caf..e8777892bd3 100644 --- a/src/androidvfs.c +++ b/src/androidvfs.c @@ -26,6 +26,7 @@ along with GNU Emacs. If not, see . */ #include #include #include +#include #include #include @@ -2058,7 +2059,7 @@ android_afs_stat (struct android_vnode *vnode, struct stat *statb) /* Concoct a nonexistent device and an inode number. */ statb->st_dev = -1; statb->st_ino = 0; - return 0; + goto set_file_times; } /* AASSET_MODE_STREAMING is fastest here. */ @@ -2083,6 +2084,24 @@ android_afs_stat (struct android_vnode *vnode, struct stat *statb) /* Close the asset. */ AAsset_close (asset_desc); + + set_file_times: + + /* If the installation date can be ascertained, return that as the + file's modification time. */ + + if (timespec_valid_p (emacs_installation_time)) + { +#ifdef STAT_TIMESPEC + STAT_TIMESPEC (statb, st_mtim) = emacs_installation_time; +#else /* !STAT_TIMESPEC */ + /* Headers supplied by the NDK r10b contain a `struct stat' + without POSIX fields for nano-second timestamps. */ + statb->st_mtime = emacs_installation_time.tv_sec; + statb->st_mtime_nsec = emacs_installation_time.tv_nsec; +#endif /* STAT_TIMESPEC */ + } + return 0; }