mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-21 17:46:48 +00:00
Other: Update golangci-lint to v1.50.0
This commit is contained in:
@ -18,7 +18,7 @@
|
||||
// Package api provides HTTP API of the Bridge.
|
||||
//
|
||||
// API endpoints:
|
||||
// * /focus, see focusHandler
|
||||
// - /focus, see focusHandler
|
||||
package api
|
||||
|
||||
import (
|
||||
|
||||
@ -23,7 +23,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -33,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
MaxAttachmentSize = 7 * 1024 * 1024 // 7 MB total limit
|
||||
MaxAttachmentSize = 7 * 1024 * 1024 // MaxAttachmentSize 7 MB total limit
|
||||
MaxCompressedFilesCount = 6
|
||||
)
|
||||
|
||||
@ -106,7 +105,7 @@ func (b *Bridge) getMatchingLogs(filenameMatchFunc func(string) bool) (filenames
|
||||
return nil, err
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(logsPath)
|
||||
files, err := os.ReadDir(logsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package clientconfig
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@ -89,7 +88,7 @@ func prepareMobileConfig(
|
||||
}
|
||||
|
||||
func saveConfigTemporarily(mc *mobileconfig.Config) (fname string, err error) {
|
||||
dir, err := ioutil.TempDir("", "protonmail-autoconfig")
|
||||
dir, err := os.MkdirTemp("", "protonmail-autoconfig")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
3
internal/config/cache/cache_test.go
vendored
3
internal/config/cache/cache_test.go
vendored
@ -18,7 +18,6 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -28,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
func TestRemoveOldVersions(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "test-cache")
|
||||
dir, err := os.MkdirTemp("", "test-cache")
|
||||
require.NoError(t, err)
|
||||
|
||||
cache, err := New(dir, "c4")
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
@ -79,7 +78,7 @@ func (p *keyValueStore) save() error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(p.path, b, 0o600)
|
||||
return os.WriteFile(p.path, b, 0o600)
|
||||
}
|
||||
|
||||
func (p *keyValueStore) setDefault(key Key, value string) {
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package settings
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@ -38,7 +37,7 @@ func TestLoadBadKeyValueStore(t *testing.T) {
|
||||
path, clean := newTmpFile(r)
|
||||
defer clean()
|
||||
|
||||
r.NoError(ioutil.WriteFile(path, []byte("{\"key\":\"MISSING_QUOTES"), 0o700))
|
||||
r.NoError(os.WriteFile(path, []byte("{\"key\":\"MISSING_QUOTES"), 0o700))
|
||||
pref := newKeyValueStore(path)
|
||||
r.Equal("", pref.Get("key"))
|
||||
}
|
||||
@ -115,7 +114,7 @@ func TestKeyValueStoreSetBool(t *testing.T) {
|
||||
}
|
||||
|
||||
func newTmpFile(r *require.Assertions) (path string, clean func()) {
|
||||
tmpfile, err := ioutil.TempFile("", "pref.*.json")
|
||||
tmpfile, err := os.CreateTemp("", "pref.*.json")
|
||||
r.NoError(err)
|
||||
defer r.NoError(tmpfile.Close())
|
||||
|
||||
@ -131,12 +130,12 @@ func newTestEmptyKeyValueStore(r *require.Assertions) (*keyValueStore, func()) {
|
||||
|
||||
func newTestKeyValueStore(r *require.Assertions) (*keyValueStore, func()) {
|
||||
path, clean := newTmpFile(r)
|
||||
r.NoError(ioutil.WriteFile(path, []byte("{\"str\":\"value\",\"int\":\"42\",\"bool\":\"true\",\"falseBool\":\"t\"}"), 0o700))
|
||||
r.NoError(os.WriteFile(path, []byte("{\"str\":\"value\",\"int\":\"42\",\"bool\":\"true\",\"falseBool\":\"t\"}"), 0o700))
|
||||
return newKeyValueStore(path), clean
|
||||
}
|
||||
|
||||
func checkSavedKeyValueStore(r *require.Assertions, path, expected string) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
r.NoError(err)
|
||||
r.Equal(expected, string(data))
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
package tls
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetOldConfig(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "test-tls")
|
||||
dir, err := os.MkdirTemp("", "test-tls")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create new tls object.
|
||||
@ -49,7 +49,7 @@ func TestGetOldConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetValidConfig(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "test-tls")
|
||||
dir, err := os.MkdirTemp("", "test-tls")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create new tls object.
|
||||
|
||||
@ -18,9 +18,9 @@
|
||||
package cookies
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -170,7 +170,7 @@ func getTestServer(t *testing.T, wantCookies []testCookie) *httptest.Server {
|
||||
|
||||
// newFakeSettings creates a temporary folder for files.
|
||||
func newFakeSettings() *settings.Settings {
|
||||
dir, err := ioutil.TempDir("", "test-settings")
|
||||
dir, err := os.MkdirTemp("", "test-settings")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -24,10 +24,11 @@
|
||||
// When IMAP clients request message literals (or parts thereof), we sometimes need to build RFC822 message literals.
|
||||
// To do this, we pass build jobs to the message builder, which internally manages its own parallelism.
|
||||
// Summary:
|
||||
// - each IMAP fetch request is handled in parallel,
|
||||
// - within each IMAP fetch request, individual items are handled by a pool of `fetchWorkers` workers,
|
||||
// - within each worker, build jobs are posted to the message builder,
|
||||
// - the message builder handles build jobs using its own, independent worker pool,
|
||||
// - each IMAP fetch request is handled in parallel,
|
||||
// - within each IMAP fetch request, individual items are handled by a pool of `fetchWorkers` workers,
|
||||
// - within each worker, build jobs are posted to the message builder,
|
||||
// - the message builder handles build jobs using its own, independent worker pool,
|
||||
//
|
||||
// The builder will handle jobs in parallel up to its own internal limit. This prevents it from overwhelming API.
|
||||
package imap
|
||||
|
||||
|
||||
@ -31,15 +31,16 @@ const (
|
||||
|
||||
// addToCache adds item to existing item list.
|
||||
// Starting from following structure:
|
||||
// {
|
||||
// "username": {"label": "item1;item2"}
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// "username": {"label": "item1;item2"}
|
||||
// }
|
||||
//
|
||||
// After calling addToCache("username", "label", "newItem") we get:
|
||||
// {
|
||||
// "username": {"label": "item1;item2;newItem"}
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// "username": {"label": "item1;item2;newItem"}
|
||||
// }
|
||||
func (ib *imapBackend) addToCache(userID, label, toAdd string) {
|
||||
list := ib.getCacheList(userID, label)
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/mail"
|
||||
"strings"
|
||||
"time"
|
||||
@ -55,7 +55,7 @@ func (im *imapMailbox) createMessage(imapFlags []string, date time.Time, r imap.
|
||||
im.user.appendExpungeLock.Lock()
|
||||
defer im.user.appendExpungeLock.Unlock()
|
||||
|
||||
body, err := ioutil.ReadAll(r)
|
||||
body, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -30,11 +30,11 @@ import (
|
||||
// The purpose of this mailbox is to see "Folders" and "Labels"
|
||||
// at the root of the mailbox tree, e.g.:
|
||||
//
|
||||
// Folders << this
|
||||
// Folders/Family
|
||||
// Folders << this
|
||||
// Folders/Family
|
||||
//
|
||||
// Labels << this
|
||||
// Labels/Security
|
||||
// Labels << this
|
||||
// Labels/Security
|
||||
//
|
||||
// This mailbox cannot be modified or read in any way.
|
||||
type imapRootMailbox struct {
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
// Package uidplus DOES NOT implement full RFC4315!
|
||||
//
|
||||
// Excluded parts are:
|
||||
// * Response `UIDNOTSTICKY`: All mailboxes of Bridge support stable
|
||||
// UIDVALIDITY so it would never return this response
|
||||
// - Response `UIDNOTSTICKY`: All mailboxes of Bridge support stable
|
||||
// UIDVALIDITY so it would never return this response
|
||||
//
|
||||
// Otherwise the standard RFC4315 is followed.
|
||||
package uidplus
|
||||
@ -48,9 +48,10 @@ const (
|
||||
// ranges or out of the bound ranges are possible.
|
||||
//
|
||||
// NOTE: potential issue with response length
|
||||
// * the user selects large number of messages to be copied and the
|
||||
// response line will be long,
|
||||
// * list of UIDs which high values
|
||||
// - the user selects large number of messages to be copied and the
|
||||
// response line will be long,
|
||||
// - list of UIDs which high values
|
||||
//
|
||||
// which can create long response line. We didn't find a maximum length of one
|
||||
// IMAP response line or maximum length of IMAP "response code" with parameters.
|
||||
type OrderedSeq []uint32
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package locations
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -118,10 +117,10 @@ func TestCleanRemovesUnexpectedFilesAndFolders(t *testing.T) {
|
||||
}
|
||||
|
||||
func newFakeAppDirs(t *testing.T) *fakeAppDirs {
|
||||
configDir, err := ioutil.TempDir("", "test-locations-config")
|
||||
configDir, err := os.MkdirTemp("", "test-locations-config")
|
||||
require.NoError(t, err)
|
||||
|
||||
cacheDir, err := ioutil.TempDir("", "test-locations-cache")
|
||||
cacheDir, err := os.MkdirTemp("", "test-locations-cache")
|
||||
require.NoError(t, err)
|
||||
|
||||
return &fakeAppDirs{
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -27,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
func clearLogs(logDir string, maxLogs int, maxCrashes int) error {
|
||||
files, err := ioutil.ReadDir(logDir)
|
||||
files, err := os.ReadDir(logDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -27,14 +27,14 @@ import (
|
||||
|
||||
// TestClearLogs tests that cearLogs removes only bridge old log files keeping last three of them.
|
||||
func TestClearLogs(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "clear-logs-test")
|
||||
dir, err := os.MkdirTemp("", "clear-logs-test")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "other.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "v1_10.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "v1_11.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "v2_12.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, ioutil.WriteFile(filepath.Join(dir, "v2_13.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "other.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "v1_10.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "v1_11.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "v2_12.log"), []byte("Hello"), 0o755))
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "v2_13.log"), []byte("Hello"), 0o755))
|
||||
|
||||
require.NoError(t, clearLogs(dir, 3, 0))
|
||||
checkFileNames(t, dir, []string{
|
||||
@ -51,7 +51,7 @@ func checkFileNames(t *testing.T, dir string, expectedFileNames []string) {
|
||||
}
|
||||
|
||||
func getFileNames(t *testing.T, dir string) []string {
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
files, err := os.ReadDir(dir)
|
||||
require.NoError(t, err)
|
||||
|
||||
fileNames := []string{}
|
||||
|
||||
@ -20,7 +20,6 @@ package logging
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@ -77,7 +76,7 @@ func TestRotator(t *testing.T) {
|
||||
}
|
||||
|
||||
func BenchmarkRotateRAMFile(b *testing.B) {
|
||||
dir, err := ioutil.TempDir("", "rotate-benchmark")
|
||||
dir, err := os.MkdirTemp("", "rotate-benchmark")
|
||||
require.NoError(b, err)
|
||||
defer os.RemoveAll(dir) //nolint:errcheck
|
||||
|
||||
@ -88,7 +87,7 @@ func BenchmarkRotateDiskFile(b *testing.B) {
|
||||
cache, err := os.UserCacheDir()
|
||||
require.NoError(b, err)
|
||||
|
||||
dir, err := ioutil.TempDir(cache, "rotate-benchmark")
|
||||
dir, err := os.MkdirTemp(cache, "rotate-benchmark")
|
||||
require.NoError(b, err)
|
||||
defer os.RemoveAll(dir) //nolint:errcheck
|
||||
|
||||
@ -113,7 +112,7 @@ func getTestFile(b *testing.B, dir string, length int) func() (io.WriteCloser, e
|
||||
b.StopTimer()
|
||||
defer b.StartTimer()
|
||||
|
||||
f, err := ioutil.TempFile(dir, "log")
|
||||
f, err := os.CreateTemp(dir, "log")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -22,7 +22,6 @@ package smtp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@ -48,7 +47,7 @@ func dumpMessageData(b []byte, subject string) {
|
||||
subject = subject[:16]
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(
|
||||
if err := os.WriteFile(
|
||||
filepath.Join(path, fmt.Sprintf("%v-%v.eml", subject, time.Now().Unix())),
|
||||
b,
|
||||
0o600,
|
||||
|
||||
@ -163,17 +163,18 @@ func (b *sendPreferencesBuilder) withPublicKey(v *crypto.KeyRing) {
|
||||
// preferences. Notice that the composer allows to select a sign preference,
|
||||
// an email format preference and an encrypt-to-outside preference. The
|
||||
// object we extract has the following possible value types:
|
||||
// {
|
||||
// encrypt: true | false,
|
||||
// sign: true | false,
|
||||
// pgpScheme: 1 (protonmail custom scheme)
|
||||
// | 2 (Protonmail scheme for encrypted-to-outside email)
|
||||
// | 4 (no cryptographic scheme)
|
||||
// | 8 (PGP/INLINE)
|
||||
// | 16 (PGP/MIME),
|
||||
// mimeType: 'text/html' | 'text/plain' | 'multipart/mixed',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }.
|
||||
//
|
||||
// {
|
||||
// encrypt: true | false,
|
||||
// sign: true | false,
|
||||
// pgpScheme: 1 (protonmail custom scheme)
|
||||
// | 2 (Protonmail scheme for encrypted-to-outside email)
|
||||
// | 4 (no cryptographic scheme)
|
||||
// | 8 (PGP/INLINE)
|
||||
// | 16 (PGP/MIME),
|
||||
// mimeType: 'text/html' | 'text/plain' | 'multipart/mixed',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }.
|
||||
func (b *sendPreferencesBuilder) build() (p SendPreferences) {
|
||||
p.Encrypt = b.shouldEncrypt()
|
||||
p.Sign = b.shouldSign()
|
||||
@ -207,13 +208,13 @@ func (b *sendPreferencesBuilder) build() (p SendPreferences) {
|
||||
|
||||
// setPGPSettings returns a SendPreferences with the following possible values:
|
||||
//
|
||||
// {
|
||||
// encrypt: true | false | undefined/null/'',
|
||||
// sign: true | false | undefined/null/'',
|
||||
// pgpScheme: 'pgp-mime' | 'pgp-inline' | undefined/null/'',
|
||||
// mimeType: 'text/html' | 'text/plain' | undefined/null/'',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }
|
||||
// {
|
||||
// encrypt: true | false | undefined/null/'',
|
||||
// sign: true | false | undefined/null/'',
|
||||
// pgpScheme: 'pgp-mime' | 'pgp-inline' | undefined/null/'',
|
||||
// mimeType: 'text/html' | 'text/plain' | undefined/null/'',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }
|
||||
//
|
||||
// These settings are simply a reflection of the vCard content plus the public
|
||||
// key info retrieved from the API via the GET KEYS route.
|
||||
@ -285,17 +286,17 @@ func (b *sendPreferencesBuilder) setInternalPGPSettings(
|
||||
// pickSendingKey tries to determine which key to use to encrypt outgoing mail.
|
||||
// It returns a keyring containing the chosen key or an error.
|
||||
//
|
||||
// 1. If there are pinned keys in the vCard, those should be given preference
|
||||
// (assuming the fingerprint matches one of the keys served by the API).
|
||||
// 2. If there are pinned keys in the vCard but no matching keys were served
|
||||
// by the API, we use one of the API keys but first show a modal to the
|
||||
// user to ask them to confirm that they trust the API key.
|
||||
// (Use case: user doesn't trust server, pins the only keys they trust to
|
||||
// the contact, rogue server sends unknown keys, user should have option
|
||||
// to say they don't recognise these keys and abort the mail send.)
|
||||
// 3. If there are no pinned keys, then the client should encrypt with the
|
||||
// first valid key served by the API (in principle the server already
|
||||
// validates the keys and the first one provided should be valid).
|
||||
// 1. If there are pinned keys in the vCard, those should be given preference
|
||||
// (assuming the fingerprint matches one of the keys served by the API).
|
||||
// 2. If there are pinned keys in the vCard but no matching keys were served
|
||||
// by the API, we use one of the API keys but first show a modal to the
|
||||
// user to ask them to confirm that they trust the API key.
|
||||
// (Use case: user doesn't trust server, pins the only keys they trust to
|
||||
// the contact, rogue server sends unknown keys, user should have option
|
||||
// to say they don't recognise these keys and abort the mail send.)
|
||||
// 3. If there are no pinned keys, then the client should encrypt with the
|
||||
// first valid key served by the API (in principle the server already
|
||||
// validates the keys and the first one provided should be valid).
|
||||
func pickSendingKey(vCardData *ContactMetadata, rawAPIKeys []pmapi.PublicKey) (kr *crypto.KeyRing, err error) {
|
||||
contactKeys := make([]*crypto.Key, len(vCardData.Keys))
|
||||
apiKeys := make([]*crypto.Key, len(rawAPIKeys))
|
||||
@ -457,13 +458,13 @@ func (b *sendPreferencesBuilder) setExternalPGPSettingsWithoutWKDKeys(
|
||||
// determined thus far using using the (global) user mail settings.
|
||||
// The object we extract has the following possible value types:
|
||||
//
|
||||
// {
|
||||
// encrypt: true | false,
|
||||
// sign: true | false,
|
||||
// pgpScheme: 'pgp-mime' | 'pgp-inline',
|
||||
// mimeType: 'text/html' | 'text/plain',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }
|
||||
// {
|
||||
// encrypt: true | false,
|
||||
// sign: true | false,
|
||||
// pgpScheme: 'pgp-mime' | 'pgp-inline',
|
||||
// mimeType: 'text/html' | 'text/plain',
|
||||
// publicKey: OpenPGPKey | undefined/null
|
||||
// }
|
||||
//
|
||||
// The public key can still be undefined as we do not need it if the outgoing
|
||||
// email is not encrypted.
|
||||
|
||||
7
internal/store/cache/disk.go
vendored
7
internal/store/cache/disk.go
vendored
@ -23,7 +23,6 @@ import (
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
@ -64,7 +63,7 @@ func NewOnDiskCache(path string, cmp Compressor, opts Options) (Cache, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file, err := ioutil.TempFile(path, "tmp")
|
||||
file, err := os.CreateTemp(path, "tmp")
|
||||
defer func() {
|
||||
file.Close() //nolint:errcheck,gosec
|
||||
os.Remove(file.Name()) //nolint:errcheck,gosec
|
||||
@ -210,7 +209,7 @@ func (c *onDiskCache) readFile(path string) ([]byte, error) {
|
||||
// Wait before reading in case the file is currently being written.
|
||||
c.pending.wait(path)
|
||||
|
||||
return ioutil.ReadFile(filepath.Clean(path))
|
||||
return os.ReadFile(filepath.Clean(path))
|
||||
}
|
||||
|
||||
func (c *onDiskCache) writeFile(path string, b []byte) error {
|
||||
@ -235,7 +234,7 @@ func (c *onDiskCache) writeFile(path string, b []byte) error {
|
||||
defer c.update()
|
||||
|
||||
// NOTE(GODT-1158): What happens when this fails? Should be fixed eventually.
|
||||
return ioutil.WriteFile(filepath.Clean(path), b, 0o600)
|
||||
return os.WriteFile(filepath.Clean(path), b, 0o600)
|
||||
}
|
||||
|
||||
func (c *onDiskCache) hasSpace(size int) bool {
|
||||
|
||||
@ -20,7 +20,6 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@ -162,7 +161,7 @@ func initMocks(tb testing.TB) (*mocksForStore, func()) {
|
||||
mocks.panicHandler.EXPECT().HandlePanic().AnyTimes()
|
||||
|
||||
var err error
|
||||
mocks.tmpDir, err = ioutil.TempDir("", "store-test")
|
||||
mocks.tmpDir, err = os.MkdirTemp("", "store-test")
|
||||
require.NoError(tb, err)
|
||||
|
||||
cacheFile := filepath.Join(mocks.tmpDir, "cache.json")
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/mail"
|
||||
"net/textproto"
|
||||
"strings"
|
||||
@ -126,7 +125,7 @@ func encryptDraft(kr *crypto.KeyRing, message *pmapi.Message, attachments []*dra
|
||||
|
||||
for _, att := range attachments {
|
||||
attachment := att.attachment
|
||||
attachmentBody, err := ioutil.ReadAll(att.reader)
|
||||
attachmentBody, err := io.ReadAll(att.reader)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read attachment")
|
||||
}
|
||||
@ -158,7 +157,7 @@ func (store *Store) checkDraftTotalSize(message *pmapi.Message, attachments []*d
|
||||
|
||||
var attSize int64
|
||||
for _, att := range attachments {
|
||||
b, err := ioutil.ReadAll(att.encReader)
|
||||
b, err := io.ReadAll(att.encReader)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@ -111,13 +111,13 @@ func (store *Store) isSynced(countsOnAPI []*pmapi.MessagesCount) (bool, error) {
|
||||
// All Mail mailbox contains all messages, so we download all meta data needed
|
||||
// to generate any address/mailbox IMAP UIDs.
|
||||
// Sync state can be in three states:
|
||||
// * Nothing in database. For example when user logs in for the first time.
|
||||
// `triggerSync` will start full sync.
|
||||
// * Database has syncIDRangesKey and syncIDsToBeDeletedKey keys with data.
|
||||
// Sync is in progress or was interrupted. In later case when, `triggerSync`
|
||||
// will continue where it left off.
|
||||
// * Database has only syncStateKey with time when database was last synced.
|
||||
// `triggerSync` will reset it and start full sync again.
|
||||
// - Nothing in database. For example when user logs in for the first time.
|
||||
// `triggerSync` will start full sync.
|
||||
// - Database has syncIDRangesKey and syncIDsToBeDeletedKey keys with data.
|
||||
// Sync is in progress or was interrupted. In later case when, `triggerSync`
|
||||
// will continue where it left off.
|
||||
// - Database has only syncStateKey with time when database was last synced.
|
||||
// `triggerSync` will reset it and start full sync again.
|
||||
func (store *Store) triggerSync() {
|
||||
syncState := store.loadSyncState()
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ package updater
|
||||
import (
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -43,7 +42,7 @@ func (i *InstallerDarwin) InstallUpdate(_ *semver.Version, r io.Reader) error {
|
||||
}
|
||||
defer func() { _ = gr.Close() }()
|
||||
|
||||
tempDir, err := ioutil.TempDir("", "proton-update-source")
|
||||
tempDir, err := os.MkdirTemp("", "proton-update-source")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get temporary update directory")
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package updater
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -104,10 +103,10 @@ func checkThatFilesAreSame(r *require.Assertions, src, dst string) {
|
||||
|
||||
r.Equal(srcLnk, dstLnk)
|
||||
} else {
|
||||
srcContent, err := ioutil.ReadFile(srcPath)
|
||||
srcContent, err := os.ReadFile(srcPath)
|
||||
r.NoError(err)
|
||||
|
||||
dstContent, err := ioutil.ReadFile(dstPath)
|
||||
dstContent, err := os.ReadFile(dstPath)
|
||||
r.NoError(err)
|
||||
|
||||
r.Equal(srcContent, dstContent)
|
||||
@ -155,7 +154,7 @@ func createTestFolder(dirPath, dirType string) error {
|
||||
path := filepath.Join(dirPath, "testpath")
|
||||
switch dirType {
|
||||
case FileType:
|
||||
err = ioutil.WriteFile(path, []byte("This is a test"), 0o640)
|
||||
err = os.WriteFile(path, []byte("This is a test"), 0o640)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -172,7 +171,7 @@ func createTestFolder(dirPath, dirType string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(path, "another_file"), []byte("This is a test"), 0o640)
|
||||
err = os.WriteFile(filepath.Join(path, "another_file"), []byte("This is a test"), 0o640)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@ -314,7 +314,7 @@ type fakeSettings struct {
|
||||
|
||||
// newFakeSettings creates a temporary folder for files.
|
||||
func newFakeSettings(rollout float64, earlyAccess bool) *fakeSettings {
|
||||
dir, err := ioutil.TempDir("", "test-settings")
|
||||
dir, err := os.MkdirTemp("", "test-settings")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -50,41 +50,42 @@ type VersionInfo struct {
|
||||
|
||||
// VersionMap represents the structure of the version.json file.
|
||||
// It looks like this:
|
||||
// {
|
||||
// "stable": {
|
||||
// "Version": "2.3.4",
|
||||
// "Package": "https://protonmail.com/.../bridge_2.3.4_linux.tgz",
|
||||
// "Installers": [
|
||||
// "https://protonmail.com/.../something.deb",
|
||||
// "https://protonmail.com/.../something.rpm",
|
||||
// "https://protonmail.com/.../PKGBUILD"
|
||||
// ],
|
||||
// "LandingPage": "https://protonmail.com/bridge",
|
||||
// "ReleaseNotesPage": "https://protonmail.com/.../release_notes.html",
|
||||
// "RolloutProportion": 0.5
|
||||
// },
|
||||
// "early": {
|
||||
// "Version": "2.4.0",
|
||||
// "Package": "https://protonmail.com/.../bridge_2.4.0_linux.tgz",
|
||||
// "Installers": [
|
||||
// "https://protonmail.com/.../something.deb",
|
||||
// "https://protonmail.com/.../something.rpm",
|
||||
// "https://protonmail.com/.../PKGBUILD"
|
||||
// ],
|
||||
// "LandingPage": "https://protonmail.com/bridge",
|
||||
// "ReleaseNotesPage": "https://protonmail.com/.../release_notes.html",
|
||||
// "RolloutProportion": 0.5
|
||||
// },
|
||||
// "...": {
|
||||
// ...
|
||||
// }
|
||||
// }.
|
||||
//
|
||||
// {
|
||||
// "stable": {
|
||||
// "Version": "2.3.4",
|
||||
// "Package": "https://protonmail.com/.../bridge_2.3.4_linux.tgz",
|
||||
// "Installers": [
|
||||
// "https://protonmail.com/.../something.deb",
|
||||
// "https://protonmail.com/.../something.rpm",
|
||||
// "https://protonmail.com/.../PKGBUILD"
|
||||
// ],
|
||||
// "LandingPage": "https://protonmail.com/bridge",
|
||||
// "ReleaseNotesPage": "https://protonmail.com/.../release_notes.html",
|
||||
// "RolloutProportion": 0.5
|
||||
// },
|
||||
// "early": {
|
||||
// "Version": "2.4.0",
|
||||
// "Package": "https://protonmail.com/.../bridge_2.4.0_linux.tgz",
|
||||
// "Installers": [
|
||||
// "https://protonmail.com/.../something.deb",
|
||||
// "https://protonmail.com/.../something.rpm",
|
||||
// "https://protonmail.com/.../PKGBUILD"
|
||||
// ],
|
||||
// "LandingPage": "https://protonmail.com/bridge",
|
||||
// "ReleaseNotesPage": "https://protonmail.com/.../release_notes.html",
|
||||
// "RolloutProportion": 0.5
|
||||
// },
|
||||
// "...": {
|
||||
// ...
|
||||
// }
|
||||
// }.
|
||||
type VersionMap map[string]VersionInfo
|
||||
|
||||
// getVersionFileURL returns the URL of the version file.
|
||||
// For example:
|
||||
// - https://protonmail.com/download/bridge/version_linux.json
|
||||
// - https://protonmail.com/download/ie/version_linux.json
|
||||
// - https://protonmail.com/download/bridge/version_linux.json
|
||||
// - https://protonmail.com/download/ie/version_linux.json
|
||||
func (u *Updater) getVersionFileURL() string {
|
||||
return fmt.Sprintf("%v/%v/version_%v.json", Host, u.updateURLName, u.platform)
|
||||
}
|
||||
|
||||
@ -20,7 +20,6 @@ package users
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -30,7 +29,7 @@ import (
|
||||
// isFolderEmpty checks whether a folder is empty.
|
||||
// path must point to an existing folder.
|
||||
func isFolderEmpty(path string) (bool, error) {
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
@ -90,13 +89,13 @@ func copyFolder(srcPath, dstPath string) error {
|
||||
if err = os.MkdirAll(dstPath, 0o700); err != nil {
|
||||
return err
|
||||
}
|
||||
files, err := ioutil.ReadDir(srcPath)
|
||||
files, err := os.ReadDir(srcPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// copy only regular files and folders
|
||||
for _, fileInfo := range files {
|
||||
mode := fileInfo.Mode()
|
||||
mode := fileInfo.Type()
|
||||
if mode&os.ModeSymlink != 0 {
|
||||
continue // we skip symbolic links to avoid potential endless recursion
|
||||
}
|
||||
@ -227,7 +226,7 @@ func (u *Users) MigrateCache(srcPath, dstPath string) error {
|
||||
|
||||
// GODT-1381 Edge case: read-only source migration: prevent re-naming
|
||||
// (read-only is conserved). Do copy instead.
|
||||
tmp, err := ioutil.TempFile(srcPath, "tmp")
|
||||
tmp, err := os.CreateTemp(srcPath, "tmp")
|
||||
if err == nil {
|
||||
// Removal of tmp file cannot be deferred, as we are going to try to move the containing folder.
|
||||
if err = tmp.Close(); err == nil {
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -37,7 +36,7 @@ const (
|
||||
// tempFileWithContent() creates a temporary file in folderPath containing the string content.
|
||||
// Returns the path of the created file.
|
||||
func tempFileWithContent(folderPath, content string) (string, error) {
|
||||
file, err := ioutil.TempFile(folderPath, "")
|
||||
file, err := os.CreateTemp(folderPath, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -49,7 +48,7 @@ func tempFileWithContent(folderPath, content string) (string, error) {
|
||||
// itemCountInFolder() counts the number of items (files, folders, etc) in a folder.
|
||||
// Returns -1 if an error occurred.
|
||||
func itemCountInFolder(path string) int {
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
@ -83,13 +82,13 @@ func filesAreIdentical(path1, path2 string) bool {
|
||||
func TestCache_IsFolderEmpty(t *testing.T) {
|
||||
_, err := isFolderEmpty("")
|
||||
r.Error(t, err)
|
||||
tempDirPath, err := ioutil.TempDir("", "")
|
||||
tempDirPath, err := os.MkdirTemp("", "")
|
||||
defer func() { r.NoError(t, os.Remove(tempDirPath)) }()
|
||||
r.NoError(t, err)
|
||||
result, err := isFolderEmpty(tempDirPath)
|
||||
r.NoError(t, err)
|
||||
r.True(t, result)
|
||||
tempFile, err := ioutil.TempFile(tempDirPath, "")
|
||||
tempFile, err := os.CreateTemp(tempDirPath, "")
|
||||
r.NoError(t, err)
|
||||
defer func() { r.NoError(t, os.Remove(tempFile.Name())) }()
|
||||
r.NoError(t, tempFile.Close())
|
||||
@ -101,10 +100,10 @@ func TestCache_IsFolderEmpty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCache_CheckFolderIsSuitableDestinationForCache(t *testing.T) {
|
||||
tempDirPath, err := ioutil.TempDir("", "")
|
||||
tempDirPath, err := os.MkdirTemp("", "")
|
||||
defer func() { _ = os.Remove(tempDirPath) }() // cleanup in case we fail before removing it.
|
||||
r.NoError(t, err)
|
||||
tempFile, err := ioutil.TempFile(tempDirPath, "")
|
||||
tempFile, err := os.CreateTemp(tempDirPath, "")
|
||||
r.NoError(t, err)
|
||||
defer func() { _ = os.Remove(tempFile.Name()) }() // cleanup in case we fail before removing it.
|
||||
r.NoError(t, tempFile.Close())
|
||||
@ -122,10 +121,10 @@ func TestCache_CopyFolder(t *testing.T) {
|
||||
// |-srcSubDir/
|
||||
// |-file2
|
||||
|
||||
srcDir, err := ioutil.TempDir("", "")
|
||||
srcDir, err := os.MkdirTemp("", "")
|
||||
defer func() { r.NoError(t, os.RemoveAll(srcDir)) }()
|
||||
r.NoError(t, err)
|
||||
srcSubDir, err := ioutil.TempDir(srcDir, "")
|
||||
srcSubDir, err := os.MkdirTemp(srcDir, "")
|
||||
r.NoError(t, err)
|
||||
subDirName := filepath.Base(srcSubDir)
|
||||
file1, err := tempFileWithContent(srcDir, str1)
|
||||
@ -162,7 +161,7 @@ func TestCache_CopyFolder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCache_IsSubfolderOf(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
defer func() { r.NoError(t, os.Remove(dir)) }()
|
||||
r.NoError(t, err)
|
||||
r.True(t, isSubfolderOf(dir, dir))
|
||||
|
||||
@ -19,7 +19,6 @@ package users
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
@ -166,7 +165,7 @@ func initMocks(t *testing.T) mocks {
|
||||
mockCtrl = gomock.NewController(t)
|
||||
}
|
||||
|
||||
cacheFile, err := ioutil.TempFile("", "bridge-store-cache-*.db")
|
||||
cacheFile, err := os.CreateTemp("", "bridge-store-cache-*.db")
|
||||
r.NoError(t, err, "could not get temporary file for store cache")
|
||||
r.NoError(t, cacheFile.Close())
|
||||
|
||||
@ -193,7 +192,7 @@ func initMocks(t *testing.T) mocks {
|
||||
m.storeMaker.EXPECT().New(gomock.Any()).DoAndReturn(func(user store.BridgeUser) (*store.Store, error) {
|
||||
var sentryReporter *sentry.Reporter // Sentry reporter is not used under unit tests.
|
||||
|
||||
dbFile, err := ioutil.TempFile(t.TempDir(), "bridge-store-db-*.db")
|
||||
dbFile, err := os.CreateTemp(t.TempDir(), "bridge-store-db-*.db")
|
||||
r.NoError(t, err, "could not get temporary file for store db")
|
||||
r.NoError(t, dbFile.Close())
|
||||
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@ -65,12 +64,12 @@ func (v *Version) SemVer() *semver.Version {
|
||||
|
||||
// VerifyFiles verifies all files in the version directory.
|
||||
func (v *Version) VerifyFiles(kr *crypto.KeyRing) error {
|
||||
fileBytes, err := ioutil.ReadFile(filepath.Join(v.path, sumFile)) //nolint:gosec
|
||||
fileBytes, err := os.ReadFile(filepath.Join(v.path, sumFile)) //nolint:gosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sigBytes, err := ioutil.ReadFile(filepath.Join(v.path, sumFile+".sig")) //nolint:gosec
|
||||
sigBytes, err := os.ReadFile(filepath.Join(v.path, sumFile+".sig")) //nolint:gosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -19,7 +19,6 @@ package versioner
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -33,7 +32,7 @@ import (
|
||||
)
|
||||
|
||||
func TestVerifyFiles(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "verify-test")
|
||||
tempDir, err := os.MkdirTemp("", "verify-test")
|
||||
require.NoError(t, err)
|
||||
|
||||
version := &Version{
|
||||
@ -53,7 +52,7 @@ func TestVerifyFiles(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyWithBadFile(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "verify-test")
|
||||
tempDir, err := os.MkdirTemp("", "verify-test")
|
||||
require.NoError(t, err)
|
||||
|
||||
version := &Version{
|
||||
@ -76,7 +75,7 @@ func TestVerifyWithBadFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVerifyWithBadSubFile(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "verify-test")
|
||||
tempDir, err := os.MkdirTemp("", "verify-test")
|
||||
require.NoError(t, err)
|
||||
|
||||
version := &Version{
|
||||
@ -136,10 +135,10 @@ func makeFile(t *testing.T, path string) {
|
||||
}
|
||||
|
||||
func signFile(t *testing.T, path string, kr *crypto.KeyRing) {
|
||||
file, err := ioutil.ReadFile(path)
|
||||
file, err := os.ReadFile(path)
|
||||
require.NoError(t, err)
|
||||
|
||||
sig, err := kr.SignDetached(crypto.NewPlainMessage(file))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, ioutil.WriteFile(path+".sig", sig.GetBinary(), 0o700))
|
||||
require.NoError(t, os.WriteFile(path+".sig", sig.GetBinary(), 0o700))
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ package versioner
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
@ -43,7 +43,7 @@ func New(root string) *Versioner {
|
||||
|
||||
// ListVersions returns a collection of all available version numbers, sorted from newest to oldest.
|
||||
func (v *Versioner) ListVersions() (Versions, error) {
|
||||
dirs, err := ioutil.ReadDir(v.root)
|
||||
dirs, err := os.ReadDir(v.root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
package versioner
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@ -33,7 +33,7 @@ import (
|
||||
// RemoveOldVersions is a noop on darwin; we don't test it there.
|
||||
|
||||
func TestRemoveOldVersions(t *testing.T) {
|
||||
updates, err := ioutil.TempDir(t.TempDir(), "updates")
|
||||
updates, err := os.MkdirTemp(t.TempDir(), "updates")
|
||||
require.NoError(t, err)
|
||||
|
||||
v := newTestVersioner(t, "myCoolApp", updates, "2.3.4-beta", "2.3.4", "2.3.5", "2.4.0")
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
package versioner
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@ -29,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
func TestListVersions(t *testing.T) {
|
||||
updates, err := ioutil.TempDir("", "updates")
|
||||
updates, err := os.MkdirTemp("", "updates")
|
||||
require.NoError(t, err)
|
||||
|
||||
v := newTestVersioner(t, "myCoolApp", updates, "2.3.4-beta", "2.3.4", "2.3.5", "2.4.0")
|
||||
|
||||
Reference in New Issue
Block a user