mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 746444 - Add native function to force unlock on database file (r=blassey)
This commit is contained in:
parent
2a0a94ea7d
commit
eb62535d0d
@ -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 = "";
|
||||
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user