summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-09-24 13:46:59 +0700
committerShulhan <ms@kilabit.info>2023-09-26 00:24:08 +0700
commita91585331cf6ea99da56bc79551a72acd923a1a6 (patch)
treedb9fd736cef75596de4c9cd2b1553b22fe75f530
parent96a37d7c09161b1986736f169b1a6e205fb33015 (diff)
downloadawwan-a91585331cf6ea99da56bc79551a72acd923a1a6.tar.xz
all: add prefix "awwan." to the name of temporary directory
Each time the new session is created in local or remote, it will create new temporary directory. Previously, the name of temporary directory is random 16 characters and numbers. To distinguish this directory with others, we add prefix "awwan." to the name.
-rw-r--r--awwan.go6
-rw-r--r--session.go9
-rw-r--r--ssh_client.go2
3 files changed, 10 insertions, 7 deletions
diff --git a/awwan.go b/awwan.go
index ad3d166..18dc2bc 100644
--- a/awwan.go
+++ b/awwan.go
@@ -217,12 +217,12 @@ func (aww *Awwan) Local(req *Request) (err error) {
}
// Create temporary directory.
- err = os.MkdirAll(ses.tmpDir, 0700)
+ err = os.MkdirAll(ses.dirTmp, 0700)
if err != nil {
- return fmt.Errorf("%s: %s: %w", logp, ses.tmpDir, err)
+ return fmt.Errorf("%s: %s: %w", logp, ses.dirTmp, err)
}
defer func() {
- err = os.RemoveAll(ses.tmpDir)
+ err = os.RemoveAll(ses.dirTmp)
if err != nil {
log.Printf("%s: %s", logp, err)
}
diff --git a/session.go b/session.go
index 269466a..181b9de 100644
--- a/session.go
+++ b/session.go
@@ -21,6 +21,9 @@ import (
"github.com/shuLhan/share/lib/ssh/config"
)
+// defDirTmpPrefix default prefix for temporary directory.
+const defDirTmpPrefix = `awwan.`
+
// Session manage and cache SSH client and list of scripts.
// One session have one SSH client, but may contains more than one script.
type Session struct {
@@ -39,7 +42,7 @@ type Session struct {
SSHPort string // The value of "Port" in configuration.
hostname string
- tmpDir string
+ dirTmp string
paths []string
}
@@ -71,7 +74,7 @@ func NewSession(aww *Awwan, sessionDir string) (ses *Session, err error) {
}
randomString = string(ascii.Random([]byte(ascii.LettersNumber), 16))
- ses.tmpDir = filepath.Join(defTmpDir, randomString)
+ ses.dirTmp = filepath.Join(defTmpDir, defDirTmpPrefix+randomString)
return ses, nil
}
@@ -528,7 +531,7 @@ func (ses *Session) initSSHClient(req *Request, sshSection *config.Section) (err
lastIdentFile = sshSection.IdentityFile[len(sshSection.IdentityFile)-1]
}
- ses.sshc, err = newSshClient(sshSection, ses.tmpDir, req.stdout, req.stderr)
+ ses.sshc, err = newSshClient(sshSection, ses.dirTmp, req.stdout, req.stderr)
if err != nil {
return fmt.Errorf(`%s: %w`, logp, err)
}
diff --git a/ssh_client.go b/ssh_client.go
index 3256f93..71f3b3b 100644
--- a/ssh_client.go
+++ b/ssh_client.go
@@ -70,7 +70,7 @@ func newSshClient(section *config.Section, dirTmp string, stdout, stderr io.Writ
if len(dirTmp) == 0 {
var randomString = string(ascii.Random([]byte(ascii.LettersNumber), 16))
- sshc.dirTmp = filepath.Join(defTmpDir, randomString)
+ sshc.dirTmp = filepath.Join(defTmpDir, defDirTmpPrefix+randomString)
}
err = sshc.mkdir(sshc.dirTmp, 0700)