detect if multiprocess not set and ff is running
This commit is contained in:
parent
1f6db4c4aa
commit
3513f747c4
18
firefox.go
18
firefox.go
@ -52,8 +52,8 @@ const (
|
||||
)
|
||||
|
||||
var Firefox = BrowserPaths{
|
||||
BookmarkFile: "places.sqlite",
|
||||
BookmarkDir: "/home/spike/.mozilla/firefox/7otsk3vs.test_bookmarks",
|
||||
BookmarkFile: mozilla.BookmarkFile,
|
||||
BookmarkDir: mozilla.BookmarkDir,
|
||||
}
|
||||
|
||||
const (
|
||||
@ -171,7 +171,7 @@ func NewFFBrowser() IBrowser {
|
||||
w := &Watch{
|
||||
Path: expandedBaseDir,
|
||||
EventTypes: []fsnotify.Op{fsnotify.Write},
|
||||
EventNames: []string{path.Join(expandedBaseDir, "places.sqlite-wal")},
|
||||
EventNames: []string{filepath.Join(expandedBaseDir, "places.sqlite-wal")},
|
||||
ResetWatch: false,
|
||||
}
|
||||
|
||||
@ -186,18 +186,6 @@ func NewFFBrowser() IBrowser {
|
||||
|
||||
go utils.ReduceEvents(MozMinJobInterval, browser.eventsChan, browser)
|
||||
|
||||
// Testing
|
||||
pusers, err := utils.FileProcessUsers(browser.GetBookmarksPath())
|
||||
if err != nil {
|
||||
fflog.Error(err)
|
||||
}
|
||||
for _, p := range pusers {
|
||||
pname, err := p.Name()
|
||||
if err != nil {
|
||||
fflog.Error(err)
|
||||
}
|
||||
fflog.Debugf("%s is using bookmark file", pname)
|
||||
}
|
||||
//
|
||||
//
|
||||
//
|
||||
|
2
main.go
2
main.go
@ -44,7 +44,7 @@ func mainLoop() {
|
||||
//_ = cb.Watch()
|
||||
//_ = ff.Watch()
|
||||
|
||||
err := r.Run("127.0.0.1:4242")
|
||||
err := r.Run("127.0.0.1:4243")
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
@ -2,10 +2,19 @@ package mozilla
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gomark/logging"
|
||||
"gomark/utils"
|
||||
"path"
|
||||
)
|
||||
|
||||
var fflog = logging.GetLogger("FF")
|
||||
|
||||
const (
|
||||
BookmarkFile = "places.sqlite"
|
||||
BookmarkDir = "/home/spike/.mozilla/firefox/7otsk3vs.test_bookmarks"
|
||||
)
|
||||
|
||||
const (
|
||||
// This option disables the VFS lock on firefox
|
||||
// Sqlite allows file locking of the database using the local file system VFS.
|
||||
@ -39,7 +48,7 @@ var (
|
||||
// property in prefs.js
|
||||
|
||||
func UnlockPlaces(dir string) error {
|
||||
log.Debug("Unlocking ...")
|
||||
log.Debug("Unlocking places.sqlite ...")
|
||||
|
||||
prefsPath := path.Join(dir, PrefsFile)
|
||||
|
||||
@ -52,13 +61,28 @@ func UnlockPlaces(dir string) error {
|
||||
|
||||
// If pref already defined and true raise an error
|
||||
if pref {
|
||||
log.Criticalf("pref <%s> already defined as <%s>",
|
||||
log.Criticalf("pref <%s> already defined as <%v>",
|
||||
PrefMultiProcessAccess, pref)
|
||||
return ErrMultiProcessAlreadyEnabled
|
||||
|
||||
// Set the preference
|
||||
} else {
|
||||
log.Debug("pref not defined")
|
||||
|
||||
// Checking if firefox is running
|
||||
// TODO: #multiprocess add CLI to unlock places.sqlite
|
||||
pusers, err := utils.FileProcessUsers(path.Join(BookmarkDir, BookmarkFile))
|
||||
if err != nil {
|
||||
fflog.Error(err)
|
||||
}
|
||||
|
||||
for pid, p := range pusers {
|
||||
pname, err := p.Name()
|
||||
if err != nil {
|
||||
fflog.Error(err)
|
||||
}
|
||||
return errors.New(fmt.Sprintf("multiprocess not enabled and %s(%d) is running", pname, pid))
|
||||
}
|
||||
// End testing
|
||||
|
||||
// enable multi process access in firefox
|
||||
err = SetPrefBool(prefsPath,
|
||||
|
@ -2,12 +2,13 @@ package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
psutil "github.com/shirou/gopsutil/process"
|
||||
)
|
||||
|
||||
func FileProcessUsers(path string) ([]*psutil.Process, error) {
|
||||
var fusers []*psutil.Process
|
||||
func FileProcessUsers(path string) (map[int32]*psutil.Process, error) {
|
||||
fusers := make(map[int32]*psutil.Process)
|
||||
|
||||
processes, err := psutil.Processes()
|
||||
if err != nil &&
|
||||
@ -15,21 +16,28 @@ func FileProcessUsers(path string) ([]*psutil.Process, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Eval symlinks
|
||||
relPath, err := filepath.EvalSymlinks(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//log.Debugf("checking against path: %s", relPath)
|
||||
for _, p := range processes {
|
||||
|
||||
files, err := p.OpenFiles()
|
||||
errPath, _ := err.(*os.PathError)
|
||||
_, isPathError := err.(*os.PathError)
|
||||
|
||||
if err != nil &&
|
||||
errPath.Err.Error() != os.ErrPermission.Error() {
|
||||
log.Error(err)
|
||||
return nil, err
|
||||
if err != nil && isPathError {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if path in files
|
||||
|
||||
for _, f := range files {
|
||||
if f.Path == path {
|
||||
fusers = append(fusers, p)
|
||||
//log.Debug(f)
|
||||
if f.Path == relPath {
|
||||
fusers[p.Pid] = p
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user