Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/services/connection_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"tinyrdm/backend/consts"
. "tinyrdm/backend/storage"
"tinyrdm/backend/types"
"tinyrdm/backend/utils/confdir"
_ "tinyrdm/backend/utils/proxy"

"github.com/klauspost/compress/zip"
"github.com/redis/go-redis/v9"
"github.com/vrischmann/userdir"
sshagent "github.com/xanzy/ssh-agent"
"golang.org/x/crypto/ssh"
"golang.org/x/net/proxy"
Expand Down Expand Up @@ -526,7 +526,7 @@ func (c *connectionService) ExportConnections() (resp types.JSResp) {

// compress the connections profile with zip
const connectionFilename = "connections.yaml"
inputFile, err := os.Open(path.Join(userdir.GetConfigHome(), consts.APP_DATA_FOLDER, connectionFilename))
inputFile, err := os.Open(path.Join(confdir.GetConfigDir(), consts.APP_DATA_FOLDER, connectionFilename))
if err != nil {
resp.Msg = err.Error()
return
Expand Down Expand Up @@ -602,7 +602,7 @@ func (c *connectionService) ImportConnections() (resp types.JSResp) {
}
defer zippedFile.Close()

outputFile, err := os.Create(path.Join(userdir.GetConfigHome(), consts.APP_DATA_FOLDER, connectionFilename))
outputFile, err := os.Create(path.Join(confdir.GetConfigDir(), consts.APP_DATA_FOLDER, connectionFilename))
if err != nil {
resp.Msg = err.Error()
return
Expand Down
5 changes: 2 additions & 3 deletions backend/services/connection_service_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import (
"tinyrdm/backend/types"

"github.com/klauspost/compress/zip"
"github.com/vrischmann/userdir"
)

// ExportConnectionsToBytes exports connections as zip bytes for web download
func (c *connectionService) ExportConnectionsToBytes() ([]byte, string, error) {
const connectionFilename = "connections.yaml"
filename := "connections_" + time.Now().Format("20060102150405") + ".zip"

inputFile, err := os.Open(path.Join(userdir.GetConfigHome(), consts.APP_DATA_FOLDER, connectionFilename))
inputFile, err := os.Open(path.Join(confdir.GetConfigDir(), consts.APP_DATA_FOLDER, connectionFilename))
if err != nil {
return nil, "", err
}
Expand Down Expand Up @@ -78,7 +77,7 @@ func (c *connectionService) ImportConnectionsFromBytes(data []byte) (resp types.
}
defer zippedFile.Close()

outputFile, err := os.Create(path.Join(userdir.GetConfigHome(), consts.APP_DATA_FOLDER, connectionFilename))
outputFile, err := os.Create(path.Join(confdir.GetConfigDir(), consts.APP_DATA_FOLDER, connectionFilename))
if err != nil {
resp.Msg = "failed to save connections"
return
Expand Down
5 changes: 2 additions & 3 deletions backend/storage/local_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"path"

"tinyrdm/backend/consts"

"github.com/vrischmann/userdir"
"tinyrdm/backend/utils/confdir"
)

// localStorage provides reading and writing application data to the user's
Expand All @@ -18,7 +17,7 @@ type localStorage struct {
// NewLocalStore returns a localStore instance.
func NewLocalStore(filename string) *localStorage {
return &localStorage{
ConfPath: path.Join(userdir.GetConfigHome(), consts.APP_DATA_FOLDER, filename),
ConfPath: path.Join(confdir.GetConfigDir(), consts.APP_DATA_FOLDER, filename),
}
}

Expand Down
20 changes: 20 additions & 0 deletions backend/utils/confdir/dir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package confdir

import (
"log"
"os"
"sync"
)

var confdirOnceValue = sync.OnceValue(func() string {
dir, err := os.UserConfigDir()
if err != nil {
log.Printf("get user config dir failed: %v, fallback to home dir", err)
dir, _ = os.UserHomeDir()
}
return dir
})

func GetConfigDir() string {
return confdirOnceValue()
}
5 changes: 2 additions & 3 deletions backend/utils/convert/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"os"
"path"
"tinyrdm/backend/consts"

"github.com/vrischmann/userdir"
"tinyrdm/backend/utils/confdir"
)

func writeExecuteFile(content []byte, filename string) (string, error) {
filepath := path.Join(userdir.GetConfigHome(), consts.APP_DATA_FOLDER, "decoder", filename)
filepath := path.Join(confdir.GetConfigDir(), consts.APP_DATA_FOLDER, "decoder", filename)
_ = os.Mkdir(path.Dir(filepath), 0777)
err := os.WriteFile(filepath, content, 0777)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/pierrec/lz4/v4 v4.1.27
github.com/redis/go-redis/v9 v9.20.0
github.com/vmihailenco/msgpack/v5 v5.4.1
github.com/vrischmann/userdir v0.0.0-20151206171402-20f291cebd68
github.com/wailsapp/wails/v2 v2.12.0
github.com/xanzy/ssh-agent v0.3.3
golang.org/x/crypto v0.53.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/vrischmann/userdir v0.0.0-20151206171402-20f291cebd68 h1:Ah2/69Z24rwD6OByyOdpJDmttftz0FTF8Q4QZ/SF1E4=
github.com/vrischmann/userdir v0.0.0-20151206171402-20f291cebd68/go.mod h1:EqKqAeKddSL9XSGnfXd/7iLncccKhR16HBKVva7ENw8=
github.com/wailsapp/go-webview2 v1.0.23 h1:jmv8qhz1lHibCc79bMM/a/FqOnnzOGEisLav+a0b9P0=
github.com/wailsapp/go-webview2 v1.0.23/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
Expand Down