diff options
| author | Shulhan <ms@kilabit.info> | 2023-10-24 21:22:41 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-10-25 00:52:32 +0700 |
| commit | a5b672b2792c555aa3acfb4def2cc02bd57bdbd6 (patch) | |
| tree | 70d11d0eb1ddbc4a62e120b7989964aaa531d99e /session.go | |
| parent | 8b66ca40783ae37a3718cfbd0897a7fed36c41e5 (diff) | |
| download | awwan-a5b672b2792c555aa3acfb4def2cc02bd57bdbd6.tar.xz | |
all: log and simplify error when source file is not exist
Previously, if the source file to be copied is not exist, awwan will
output only error for the ".vault" file, twice, for example
!!! Copy: <source>.vault: open <source>.vault not exist
Local: Copy: <source>.vault: open <source>.vault not exist
This changes make the first line output to print the original source
file first, the non-ecrypted one, and then followed by encrypted one,
??? loadFileInput "<source>": not exist
Local: Copy "<source>.vault": not exist
Diffstat (limited to 'session.go')
| -rw-r--r-- | session.go | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -514,7 +514,6 @@ func (ses *Session) executeScriptOnRemote(req *Request, pos linePosition) (err e err = ses.SudoPut(req, stmt) } if err != nil { - fmt.Fprintf(req.stderr, "!!! %s\n", err) return err } } @@ -699,27 +698,34 @@ func (ses *Session) loadFileEnv(awwanEnv string, isVault bool) (err error) { // On success, it will return the content of file and true if the file is // from encrypted file .vault. func (ses *Session) loadFileInput(path string) (content []byte, isVault bool, err error) { - var relPath = relativePath(ses.BaseDir, path) + var ( + logp = `loadFileInput` + relPath = relativePath(ses.BaseDir, path) + ) content, err = os.ReadFile(path) if err == nil { return content, false, nil } if !errors.Is(err, fs.ErrNotExist) { - return nil, false, fmt.Errorf(`%s: %s`, relPath, err) + return nil, false, err } + log.Printf(`??? %s %q: not exist`, logp, relPath) path = path + defEncryptExt relPath += defEncryptExt content, err = os.ReadFile(path) if err != nil { - return nil, false, fmt.Errorf(`%s: %s`, relPath, err) + if errors.Is(err, fs.ErrNotExist) { + return nil, false, fmt.Errorf(`%s %q: %w`, logp, relPath, fs.ErrNotExist) + } + return nil, false, err } content, err = ses.cryptoc.decrypt(content) if err != nil { - return nil, false, fmt.Errorf(`%s: %s`, relPath, err) + return nil, false, fmt.Errorf(`%s %q: %s`, logp, relPath, err) } return content, true, nil |
