Bug 746444 - Add native function to force unlock on database file (r=blassey)

This commit is contained in:
Lucas Rocha 2012-04-24 16:34:03 -04:00
parent 2a0a94ea7d
commit eb62535d0d
2 changed files with 34 additions and 1 deletions

View File

@ -227,6 +227,8 @@ public class GeckoAppShell
public static native void schedulePauseComposition();
public static native void scheduleResumeComposition(int width, int height);
public static native void unlockDatabaseFile(String databasePath);
private static class GeckoMediaScannerClient implements MediaScannerConnectionClient {
private String mFile = "";
private String mMimeType = "";

View File

@ -44,7 +44,7 @@
#endif
#include <stdlib.h>
#include <fcntl.h>
extern "C"
__attribute__ ((visibility("default")))
@ -77,3 +77,34 @@ Java_org_mozilla_gecko_GeckoAppShell_freeDirectBuffer(JNIEnv *jenv, jclass, jobj
free(jenv->GetDirectBufferAddress(buf));
}
extern "C"
__attribute__ ((visibility("default")))
void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_unlockDatabaseFile(JNIEnv *jenv, jclass, jstring jDatabasePath)
{
const char *databasePath = jenv->GetStringUTFChars(jDatabasePath, NULL);
int fd = open(databasePath, O_RDWR);
jenv->ReleaseStringUTFChars(jDatabasePath, databasePath);
// File could not be open, do nothing
if (fd < 0) {
return;
}
struct flock lock;
lock.l_type = F_WRLCK;
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 0;
int result = fcntl(fd, F_GETLK, &lock);
// Release any existing lock in the file
if (result != -1 && lock.l_type == F_WRLCK) {
lock.l_type = F_UNLCK;
fcntl(fd, F_SETLK, &lock);
}
close(fd);
}