aboutsummaryrefslogtreecommitdiff
path: root/session.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-10-21 00:45:58 +0700
committerShulhan <ms@kilabit.info>2023-10-21 11:25:36 +0700
commit664c121f5d52364901100b817e1fa641d245fad0 (patch)
tree25ec1b90efebed9bdb6d710307ac6caa2c2466e5 /session.go
parentcda5c7c31a84b01e2231bed579d7f4bb6212a272 (diff)
downloadawwan-664c121f5d52364901100b817e1fa641d245fad0.tar.xz
all: implement local "#get:" and "#put:" with owner and mode
In local environment, using magic command "#get" or "#put" with mode like "#get:$USER:$GROUP+$MODE" or "#put:$USER:$GROUP+MODE" will changes the file owner to $USER or $GROUP and/or permission to $MODE. The file owner does not works if user does not have permission to changes the owner.
Diffstat (limited to 'session.go')
-rw-r--r--session.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/session.go b/session.go
index faca1d0..9320382 100644
--- a/session.go
+++ b/session.go
@@ -18,6 +18,7 @@ import (
"github.com/shuLhan/share/lib/ascii"
"github.com/shuLhan/share/lib/ini"
libos "github.com/shuLhan/share/lib/os"
+ libexec "github.com/shuLhan/share/lib/os/exec"
"github.com/shuLhan/share/lib/ssh/config"
)
@@ -148,6 +149,21 @@ func (ses *Session) Copy(stmt *Statement) (err error) {
if err != nil {
return fmt.Errorf(`%s: %w`, logp, err)
}
+
+ if len(stmt.owner) != 0 {
+ var cmd = fmt.Sprintf(`chown %s %s`, stmt.owner, dst)
+ err = libexec.Run(cmd, nil, nil)
+ if err != nil {
+ return fmt.Errorf(`%s: chown %s: %w`, logp, stmt.owner, err)
+ }
+ }
+ if stmt.mode != 0 {
+ err = os.Chmod(dst, stmt.mode)
+ if err != nil {
+ return fmt.Errorf(`%s: %w`, logp, err)
+ }
+ }
+
return nil
}