/* Cache file status for DOCUMENTID within TOPLEVEL. Value is the
new cache entry. CURSOR is the cursor from where to retrieve the
file status, in the form of the columns COLUMN_FLAGS,
- COLUMN_SIZE, COLUMN_MIME_TYPE and COLUMN_LAST_MODIFIED. */
+ COLUMN_SIZE, COLUMN_MIME_TYPE and COLUMN_LAST_MODIFIED.
+
+ If NO_CACHE, don't cache the file status; just return the
+ entry. */
private StatCacheEntry
cacheFileStatus (String documentId, CacheToplevel toplevel,
- Cursor cursor)
+ Cursor cursor, boolean no_cache)
{
StatCacheEntry entry;
int flagsIndex, columnIndex, typeIndex;
entry.mtime = cursor.getLong (mtimeIndex);
/* Finally, add this entry to the cache and return. */
- toplevel.statCache.put (documentId, entry);
+ if (!no_cache)
+ toplevel.statCache.put (documentId, entry);
return entry;
}
directory listing is being requested, it's very likely
that a series of calls for file status will follow. */
- cacheFileStatus (id, toplevel, cursor);
+ cacheFileStatus (id, toplevel, cursor, false);
/* If this constituent is a directory, don't cache any
information about it. It cannot be cached without
private long[]
statDocument1 (String uri, String documentId,
- CancellationSignal signal)
+ CancellationSignal signal, boolean noCache)
{
Uri uriObject, tree;
String[] projection;
if (!cursor.moveToFirst ())
return null;
- cache = cacheFileStatus (documentId, toplevel, cursor);
+ cache = cacheFileStatus (documentId, toplevel, cursor,
+ noCache);
}
finally
{
last modification to this file in milliseconds since 00:00,
January 1st, 1970.
+ If NOCACHE, refrain from placing the file status within the
+ status cache.
+
OperationCanceledException and other typical exceptions may be
signaled upon receiving async input or other errors. */
public long[]
- statDocument (final String uri, final String documentId)
+ statDocument (final String uri, final String documentId,
+ final boolean noCache)
{
return (long[]) runObjectFunction (new SafObjectFunction () {
@Override
public Object
runObject (CancellationSignal signal)
{
- return statDocument1 (uri, documentId, signal);
+ return statDocument1 (uri, documentId, signal, noCache);
}
});
}
last modification to this file in milliseconds since 00:00,
January 1st, 1970.
+ If NOCACHE, refrain from placing the file status within the
+ status cache.
+
OperationCanceledException and other typical exceptions may be
signaled upon receiving async input or other errors. */
public long[]
- statDocument (String uri, String documentId)
+ statDocument (String uri, String documentId, boolean noCache)
{
/* Start the thread used to run SAF requests if it isn't already
running. */
storageThread.start ();
}
- return storageThread.statDocument (uri, documentId);
+ return storageThread.statDocument (uri, documentId, noCache);
}
/* Find out whether Emacs has access to the document designated by
"(Ljava/lang/String;Ljava/lang/String;)"
"Ljava/lang/String;");
FIND_METHOD (stat_document, "statDocument",
- "(Ljava/lang/String;Ljava/lang/String;)[J");
+ "(Ljava/lang/String;Ljava/lang/String;Z)[J");
FIND_METHOD (access_document, "accessDocument",
"(Ljava/lang/String;Ljava/lang/String;Z)I");
FIND_METHOD (open_document_directory, "openDocumentDirectory",
/* Return file status for the document designated by ID_NAME within
the document tree identified by URI_NAME.
+ If NO_CACHE, don't cache the resulting file status. Enable this
+ option if the file status is subject to imminent change.
+
If the file status is available, place it within *STATB and return
0. If not, return -1 and set errno to EPERM. */
static int
android_saf_stat (const char *uri_name, const char *id_name,
- struct stat *statb)
+ struct stat *statb, bool no_cache)
{
jmethodID method;
jstring uri, id;
/* Try to retrieve the file status. */
method = service_class.stat_document;
inside_saf_critical_section = true;
- status = (*android_java_env)->CallNonvirtualObjectMethod (android_java_env,
- emacs_service,
- service_class.class,
- method, uri, id);
+ status
+ = (*android_java_env)->CallNonvirtualObjectMethod (android_java_env,
+ emacs_service,
+ service_class.class,
+ method, uri, id,
+ (jboolean) no_cache);
inside_saf_critical_section = false;
/* Check for exceptions and release unneeded local references. */
vp = (struct android_saf_tree_vnode *) vnode;
return android_saf_stat (vp->tree_uri, vp->document_id,
- statb);
+ statb, false);
}
static int
ANDROID_DELETE_LOCAL_REF (descriptor);
/* Try to retrieve the modification time of this file from the
- content provider. */
+ content provider.
+
+ Refrain from introducing the file status into the file status
+ cache if FLAGS & O_RDWR or FLAGS & O_WRONLY: the cached file
+ status will contain a size and modification time inconsistent
+ with the result of any modifications that later transpire. */
if (!android_saf_stat (vp->tree_uri, vp->document_id,
- &statb))
+ &statb, write))
info->mtime = get_stat_mtime (&statb);
else
info->mtime = invalid_timespec ();