chore: doc and comments

This commit is contained in:
blob42 2023-09-29 21:48:04 +02:00
parent dbe09d671f
commit 57a3b48341
7 changed files with 23 additions and 26 deletions

View File

@ -184,7 +184,7 @@ func (ch *Chrome) setupWatchers() error {
ok, err := modules.SetupWatchers(ch.BrowserConfig, w)
if err != nil {
return fmt.Errorf("could not setup watcher: %s", err)
return fmt.Errorf("could not setup watcher: %w", err)
}
if !ok {
return errors.New("could not setup watcher")

View File

@ -341,7 +341,7 @@ func (f *Firefox) init(ctx *modules.Context) error {
ok, err := modules.SetupWatchersWithReducer(f.BrowserConfig, modules.ReducerChanLen, w)
if err != nil {
return fmt.Errorf("could not setup watcher: %s", err)
return fmt.Errorf("could not setup watcher: %w", err)
}
if !ok {
@ -710,7 +710,7 @@ func (f *Firefox) initPlacesCopy() (mozilla.PlaceCopyJob, error) {
err := utils.CopyFilesToTmpFolder(path.Join(f.BkDir, f.BkFile+"*"), pc.Path())
if err != nil {
return pc, fmt.Errorf("could not copy places.sqlite to tmp folder: %s", err)
return pc, fmt.Errorf("could not copy places.sqlite to tmp folder: %w", err)
}
opts := FFConfig.PlacesDSN

View File

@ -86,7 +86,7 @@ func InitConfigFile() error {
}
if err = os.MkdirAll(configDir, 0755); err != nil {
return fmt.Errorf("could not create config dir: %s", err)
return fmt.Errorf("could not create config dir: %w", err)
}
configFilePath := path.Join(configDir, ConfigFileName)

View File

@ -407,7 +407,8 @@ func registerSqliteHooks() {
// Register the hook
sql.Register(DriverBackupMode,
&sqlite3.SQLiteDriver{
//TODO!: document why ?
//TODO!: document
//add extra connection that are used by the sql.Backup function
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
//log.Debugf("[ConnectHook] registering new connection")
_sql3conns = append(_sql3conns, conn)

View File

@ -18,8 +18,8 @@
//
// You should have received a copy of the GNU Affero General Public License along with
// gosuki. If not, see <http://www.gnu.org/licenses/>.
package database
// TODO: add context to all queries
import (
"fmt"
@ -267,20 +267,17 @@ func StartSyncScheduler() {
go cacheSyncScheduler(syncQueue)
}
// TODO!: add concurrency
// Multiple threads(goroutines) are trying to sync together when running
// with watch all. Use sync.Mutex !!
//TODO: should be centrally managed with a debouncer
func (src *DB) SyncToDisk(dbpath string) error {
log.Debugf("Syncing <%s> to <%s>", src.Name, dbpath)
defer func() {
if err := recover(); err != nil {
log.Critical("Recovered in SyncToDisk", err)
}
}()
mu.Lock()
defer mu.Unlock()
defer func() {
if r := recover(); r != nil {
log.Critical("Recovered in SyncToDisk", r)
}
}()
//log.Debugf("[flush] openeing <%s>", src.path)
srcDB, err := sqlx.Open(DriverBackupMode, src.Path)

View File

@ -70,7 +70,7 @@ func CheckWriteable(dir string) error {
if os.IsPermission(err) {
return fmt.Errorf("%s is not writeable by the current user", dir)
}
return fmt.Errorf("unexpected error while checking writeablility of repo root: %s", err)
return fmt.Errorf("unexpected error while checking writeablility of repo root: %w", err)
}
fi.Close()
return os.Remove(testfile)
@ -82,7 +82,7 @@ func CheckWriteable(dir string) error {
}
if os.IsPermission(err) {
return fmt.Errorf("cannot write to %s, incorrect permissions", err)
return fmt.Errorf("cannot write to %w, incorrect permissions", err)
}
return err

View File

@ -224,12 +224,11 @@ type ProfileInitializer interface {
Init(*Context, *profiles.Profile) error
}
// Every browser is setup once, the following methods are called in order of
// their corresponding interfaces are implemented.
// TODO!: integrate with refactoring
// 0- provision: custom configuration to the browser
// 1- Init : any variable and state initialization
// 2- Load: Does the first loading of data (ex first loading of bookmarks )
// Setup() is called for every browser module. It sets up the browser and calls
// the following methods if they are implemented by the module:
//
// 1. [Initializer].Init() : state initialization
// 2. [Loader].Load(): Do the first loading of data (ex first loading of bookmarks )
func Setup(browser BrowserModule, c *Context, p *profiles.Profile) error {
@ -253,7 +252,7 @@ func Setup(browser BrowserModule, c *Context, p *profiles.Profile) error {
log.Debugf("<%s> custom init", browserID)
//TODO!: missing profile name
if err := initializer.Init(c); err != nil {
return fmt.Errorf("<%s> initialization error: %v", browserID, err)
return fmt.Errorf("<%s> initialization error: %w", browserID, err)
}
}
@ -264,7 +263,7 @@ func Setup(browser BrowserModule, c *Context, p *profiles.Profile) error {
}
if err := pInitializer.Init(c, p); err != nil {
return fmt.Errorf("<%s> initialization error: %v", browserID, err)
return fmt.Errorf("<%s> initialization error: %w", browserID, err)
}
}
@ -314,7 +313,7 @@ func Setup(browser BrowserModule, c *Context, p *profiles.Profile) error {
return nil
}
// Setup a watcher service using the provided []Watch elements
// Sets up a watcher service using the provided []Watch elements
// Returns true if a new watcher was created. false if it was previously craeted
// or if the browser does not need a watcher (UseFileWatcher == false).
func SetupWatchers(browserConf *BrowserConfig, watches ...*watch.Watch) (bool, error) {