gosuki/mozilla/firefox_vfs.go

86 lines
2.1 KiB
Go
Raw Normal View History

2019-02-20 17:39:45 +00:00
package mozilla
import (
"errors"
"fmt"
"gomark/utils"
"path"
)
const (
// This option disables the VFS lock on firefox
// Sqlite allows file locking of the database using the local file system VFS.
// Previous versions of FF allowed external processes to access the file.
//
// Since firefox v(63) this has changed. When initializing the database FF checks
// the preference option `storage.multiProcessAccess.enabled` which is not
// documented officially.
//
// Source code:
//- https://dxr.mozilla.org/mozilla-central/source/storage/TelemetryVFS.cpp#884
//- https://dxr.mozilla.org/mozilla-central/source/storage/mozStorageService.cpp#377
//- Change on github: https://github.com/mozilla/gecko-dev/commit/a543f35d4be483b19446304f52e4781d7a4a0a2f
PrefMultiProcessAccess = "storage.multiProcessAccess.enabled"
)
var (
ErrMultiProcessAlreadyEnabled = errors.New("multiProcessAccess already enabled")
)
2019-02-26 10:23:00 +00:00
func CheckVFSLock() error {
2019-02-26 18:41:02 +00:00
log.Debugf("Checking VFS for <%s>", GetBookmarkDir())
2019-02-26 10:23:00 +00:00
return nil
}
func UnlockPlaces() error {
2019-02-26 18:41:02 +00:00
log.Debugf("Unlocking VFS <%s>", path.Join(GetBookmarkDir(), PrefsFile))
2019-02-20 17:39:45 +00:00
2019-02-26 18:41:02 +00:00
prefsPath := path.Join(GetBookmarkDir(), PrefsFile)
2019-02-20 17:39:45 +00:00
// Find if multiProcessAccess option is defined
pref, err := GetPrefBool(prefsPath, PrefMultiProcessAccess)
if err != nil && err != ErrPrefNotFound {
return err
}
// If pref already defined and true raise an error
if pref {
2019-02-26 10:23:00 +00:00
log.Warningf("pref <%s> already defined as <%v>",
2019-02-20 17:39:45 +00:00
PrefMultiProcessAccess, pref)
2019-02-26 10:23:00 +00:00
return nil
2019-02-20 17:39:45 +00:00
// Set the preference
} else {
// Checking if firefox is running
// TODO: #multiprocess add CLI to unlock places.sqlite
2019-02-26 18:41:02 +00:00
pusers, err := utils.FileProcessUsers(path.Join(GetBookmarkDir(), BookmarkFile))
2019-02-20 17:39:45 +00:00
if err != nil {
2019-02-22 18:50:26 +00:00
log.Error(err)
2019-02-20 17:39:45 +00:00
}
for pid, p := range pusers {
pname, err := p.Name()
if err != nil {
2019-02-22 18:50:26 +00:00
log.Error(err)
2019-02-20 17:39:45 +00:00
}
return errors.New(fmt.Sprintf("multiprocess not enabled and %s(%d) is running. Close firefox and disable VFS lock", pname, pid))
}
// End testing
// enable multi process access in firefox
err = SetPrefBool(prefsPath,
PrefMultiProcessAccess,
true)
if err != nil {
return err
}
}
return nil
}