refactor: adjust defer remove

pull/237/head
stevenlele 1 year ago
parent 25699b07c5
commit 874359a3db
  1. 2
      browser/chromium/chromium_darwin.go
  2. 2
      browser/chromium/chromium_linux.go
  3. 2
      browser/chromium/chromium_windows.go
  4. 4
      browsingdata/bookmark/bookmark.go
  5. 4
      browsingdata/cookie/cookie.go
  6. 4
      browsingdata/creditcard/creditcard.go
  7. 4
      browsingdata/download/download.go
  8. 5
      browsingdata/history/history.go
  9. 4
      browsingdata/localstorage/localstorage.go
  10. 8
      browsingdata/password/password.go
  11. 4
      browsingdata/sessionstorage/sessionstorage.go

@ -24,7 +24,7 @@ var (
func (c *Chromium) GetMasterKey() ([]byte, error) {
// don't need chromium key file for macOS
defer os.Remove(item.TempChromiumKey)
_ = os.Remove(item.TempChromiumKey)
// Get the master key from the keychain
// $ security find-generic-password -wa 'Chrome'
var (

@ -18,7 +18,7 @@ import (
func (c *Chromium) GetMasterKey() ([]byte, error) {
// what is d-bus @https://dbus.freedesktop.org/
// don't need chromium key file for Linux
defer os.Remove(item.TempChromiumKey)
_ = os.Remove(item.TempChromiumKey)
conn, err := dbus.SessionBus()
if err != nil {

@ -22,7 +22,7 @@ func (c *Chromium) GetMasterKey() ([]byte, error) {
if err != nil {
return nil, err
}
defer os.Remove(item.TempChromiumKey)
_ = os.Remove(item.TempChromiumKey)
encryptedKey := gjson.Get(b, "os_crypt.encrypted_key")
if !encryptedKey.Exists() {

@ -31,7 +31,7 @@ func (c *ChromiumBookmark) Parse(_ []byte) error {
if err != nil {
return err
}
defer os.Remove(item.TempChromiumBookmark)
_ = os.Remove(item.TempChromiumBookmark)
r := gjson.Parse(bookmarks)
if r.Exists() {
roots := r.Get("roots")
@ -94,11 +94,11 @@ const (
)
func (f *FirefoxBookmark) Parse(_ []byte) error {
defer os.Remove(item.TempFirefoxBookmark)
db, err := sql.Open("sqlite3", item.TempFirefoxBookmark)
if err != nil {
return err
}
defer os.Remove(item.TempFirefoxBookmark)
defer db.Close()
_, err = db.Exec(closeJournalMode)
if err != nil {

@ -36,11 +36,11 @@ const (
)
func (c *ChromiumCookie) Parse(masterKey []byte) error {
defer os.Remove(item.TempChromiumCookie)
db, err := sql.Open("sqlite3", item.TempChromiumCookie)
if err != nil {
return err
}
defer os.Remove(item.TempChromiumCookie)
defer db.Close()
rows, err := db.Query(queryChromiumCookie)
if err != nil {
@ -104,11 +104,11 @@ const (
)
func (f *FirefoxCookie) Parse(_ []byte) error {
defer os.Remove(item.TempFirefoxCookie)
db, err := sql.Open("sqlite3", item.TempFirefoxCookie)
if err != nil {
return err
}
defer os.Remove(item.TempFirefoxCookie)
defer db.Close()
rows, err := db.Query(queryFirefoxCookie)

@ -29,11 +29,11 @@ const (
)
func (c *ChromiumCreditCard) Parse(masterKey []byte) error {
defer os.Remove(item.TempChromiumCreditCard)
db, err := sql.Open("sqlite3", item.TempChromiumCreditCard)
if err != nil {
return err
}
defer os.Remove(item.TempChromiumCreditCard)
defer db.Close()
rows, err := db.Query(queryChromiumCredit)
@ -85,11 +85,11 @@ func (c *ChromiumCreditCard) Len() int {
type YandexCreditCard []card
func (c *YandexCreditCard) Parse(masterKey []byte) error {
defer os.Remove(item.TempYandexCreditCard)
db, err := sql.Open("sqlite3", item.TempYandexCreditCard)
if err != nil {
return err
}
defer os.Remove(item.TempYandexCreditCard)
defer db.Close()
rows, err := db.Query(queryChromiumCredit)
if err != nil {

@ -32,11 +32,11 @@ const (
)
func (c *ChromiumDownload) Parse(_ []byte) error {
defer os.Remove(item.TempChromiumDownload)
db, err := sql.Open("sqlite3", item.TempChromiumDownload)
if err != nil {
return err
}
defer os.Remove(item.TempChromiumDownload)
defer db.Close()
rows, err := db.Query(queryChromiumDownload)
if err != nil {
@ -83,11 +83,11 @@ const (
)
func (f *FirefoxDownload) Parse(_ []byte) error {
defer os.Remove(item.TempFirefoxDownload)
db, err := sql.Open("sqlite3", item.TempFirefoxDownload)
if err != nil {
return err
}
defer os.Remove(item.TempFirefoxDownload)
defer db.Close()
_, err = db.Exec(closeJournalMode)

@ -28,11 +28,11 @@ const (
)
func (c *ChromiumHistory) Parse(_ []byte) error {
defer os.Remove(item.TempChromiumHistory)
db, err := sql.Open("sqlite3", item.TempChromiumHistory)
if err != nil {
return err
}
defer os.Remove(item.TempChromiumHistory)
defer db.Close()
rows, err := db.Query(queryChromiumHistory)
@ -79,18 +79,17 @@ const (
)
func (f *FirefoxHistory) Parse(_ []byte) error {
defer os.Remove(item.TempFirefoxHistory)
db, err := sql.Open("sqlite3", item.TempFirefoxHistory)
if err != nil {
return err
}
defer os.Remove(item.TempFirefoxHistory)
defer db.Close()
_, err = db.Exec(closeJournalMode)
if err != nil {
return err
}
defer db.Close()
rows, err := db.Query(queryFirefoxHistory)
if err != nil {
return err

@ -29,11 +29,11 @@ type storage struct {
const maxLocalStorageValueLength = 1024 * 2
func (c *ChromiumLocalStorage) Parse(_ []byte) error {
defer os.RemoveAll(item.TempChromiumLocalStorage)
db, err := leveldb.OpenFile(item.TempChromiumLocalStorage, nil)
if err != nil {
return err
}
defer os.RemoveAll(item.TempChromiumLocalStorage)
defer db.Close()
iter := db.NewIterator(nil, nil)
@ -106,11 +106,11 @@ const (
)
func (f *FirefoxLocalStorage) Parse(_ []byte) error {
defer os.Remove(item.TempFirefoxLocalStorage)
db, err := sql.Open("sqlite3", item.TempFirefoxLocalStorage)
if err != nil {
return err
}
defer os.Remove(item.TempFirefoxLocalStorage)
defer db.Close()
_, err = db.Exec(closeJournalMode)

@ -34,11 +34,11 @@ const (
)
func (c *ChromiumPassword) Parse(masterKey []byte) error {
defer os.Remove(item.TempChromiumPassword)
db, err := sql.Open("sqlite3", item.TempChromiumPassword)
if err != nil {
return err
}
defer os.Remove(item.TempChromiumPassword)
defer db.Close()
rows, err := db.Query(queryChromiumLogin)
@ -101,11 +101,11 @@ const (
)
func (c *YandexPassword) Parse(masterKey []byte) error {
defer os.Remove(item.TempYandexPassword)
db, err := sql.Open("sqlite3", item.TempYandexPassword)
if err != nil {
return err
}
defer os.Remove(item.TempYandexPassword)
defer db.Close()
rows, err := db.Query(queryYandexLogin)
@ -171,6 +171,7 @@ const (
func (f *FirefoxPassword) Parse(masterKey []byte) error {
globalSalt, metaBytes, nssA11, nssA102, err := getFirefoxDecryptKey(item.TempFirefoxKey4)
_ = os.Remove(item.TempFirefoxKey4)
if err != nil {
return err
}
@ -238,7 +239,6 @@ func getFirefoxDecryptKey(key4file string) (item1, item2, a11, a102 []byte, err
if err != nil {
return nil, nil, nil, nil, err
}
defer os.Remove(key4file)
defer keyDB.Close()
if err = keyDB.QueryRow(queryMetaData).Scan(&item1, &item2); err != nil {
@ -256,7 +256,7 @@ func getFirefoxLoginData() ([]loginData, error) {
if err != nil {
return nil, err
}
defer os.Remove(item.TempFirefoxPassword)
_ = os.Remove(item.TempFirefoxPassword)
loginsJSON := gjson.GetBytes(s, "logins")
var logins []loginData
if loginsJSON.Exists() {

@ -29,11 +29,11 @@ type session struct {
const maxLocalStorageValueLength = 1024 * 2
func (c *ChromiumSessionStorage) Parse(_ []byte) error {
defer os.RemoveAll(item.TempChromiumSessionStorage)
db, err := leveldb.OpenFile(item.TempChromiumSessionStorage, nil)
if err != nil {
return err
}
defer os.RemoveAll(item.TempChromiumSessionStorage)
defer db.Close()
iter := db.NewIterator(nil, nil)
@ -114,11 +114,11 @@ const (
)
func (f *FirefoxSessionStorage) Parse(_ []byte) error {
defer os.Remove(item.TempFirefoxSessionStorage)
db, err := sql.Open("sqlite3", item.TempFirefoxSessionStorage)
if err != nil {
return err
}
defer os.Remove(item.TempFirefoxSessionStorage)
defer db.Close()
_, err = db.Exec(closeJournalMode)

Loading…
Cancel
Save