Skip to content

Commit

Permalink
fully tested and improved
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnywong committed Jun 26, 2022
1 parent b73ba8e commit 834bd78
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 39 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release and publish trzsz-go
on:
release:
types: [released]
jobs:
release-and-publish:
name: Release and publish trzsz-go
runs-on: ubuntu-latest
steps:
- name: Checkout trzsz-go
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '>=1.18.0'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release --rm-dist --skip-publish
- name: Upload Release Assets
uses: trzsz/upload-release-assets@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ github.event.release.id }}
assets_path: |
dist/*.tar.gz
dist/*.zip
- name: Publish rpm to Gemfury
env:
FURY_TOKEN: ${{ secrets.FURY_TOKEN }}
run: |
for filename in dist/trzsz*.rpm; do
curl -F package=@"$filename" https://{$FURY_TOKEN}@push.fury.io/trzsz/
done
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ bin/
debian/files

*.swp

dist/
vendor/
73 changes: 73 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
project_name: trzsz
before:
hooks:
- go mod tidy
builds:
- id: trz
main: ./cmd/trz
binary: trz
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
- id: tsz
main: ./cmd/tsz
binary: tsz
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
- id: trzsz
main: ./cmd/trzsz
binary: trzsz
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- id: trzsz
replacements:
darwin: macos
386: i386
amd64: x86_64
arm64: aarch64
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
files:
- none*
nfpms:
- id: trzsz
builds:
- trz
- tsz
- trzsz
replacements:
amd64: 64-bit
386: 32-bit
darwin: macOS
linux: Tux
homepage: https://trzsz.github.io/
maintainer: Lonny Wong <lonnywong@qq.com>
description: |-
trzsz ( trz / tsz ) is a simple file transfer tools.
similar to lrzsz ( rz / sz ), and compatible with tmux.
license: MIT
formats:
- rpm
bindir: /usr/bin
overrides:
rpm:
replacements:
amd64: x86_64
rpm:
group: Unspecified
snapshot:
name_template: '{{ .Version }}.next'
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

## Installation

### on Ubuntu
*Not released yet, please download the latest [release](https://github.com/trzsz/trzsz-go/releases) from GitHub.*
### with Apt

```sh
sudo add-apt-repository ppa:trzsz/ppa
Expand All @@ -14,7 +13,25 @@ sudo apt install trzsz
```


### on Windows / macOS / Other
### with Yum
```
echo '[trzsz]
name=Trzsz Repo
baseurl=https://yum.fury.io/trzsz/
enabled=1
gpgcheck=0' | sudo tee /etc/yum.repos.d/trzsz.repo
sudo yum install trzsz
```


### with Homebrew
```
brew update
brew install trzsz-go
```


### on Windows

Please download the latest [release](https://github.com/trzsz/trzsz-go/releases) from GitHub.

Expand All @@ -33,8 +50,6 @@ sudo make install

### on Local

Install the `trzsz` binary to one of the `PATH` directory.

Add `trzsz` before the shell to support trzsz ( trz / tsz ), e.g.:

```sh
Expand All @@ -53,8 +68,6 @@ trzsz --dragfile ssh x.x.x.x

### on Server

Install the `trz` and `tsz` binaries to one of the `PATH` directory.

Similar to lrzsz ( rz / sz ), command `trz` to upload files, command `tsz /path/to/file` to download files.

For more information, see the website of trzsz: [https://trzsz.github.io](https://trzsz.github.io/).
Expand Down
8 changes: 7 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
trzsz (0.0.1.8) xenial; urgency=medium
trzsz (0.1.8) trusty; urgency=medium

* Release v0.1.8 with Go1.18.

-- Lonny Wong <lonnywong@qq.com> Sat, 25 Jun 2022 22:52:30 +0800

trzsz (0.0.1) xenial; urgency=medium

* Initial Release.

Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Section: utils
Priority: optional
Maintainer: Lonny Wong <lonnywong@qq.com>
Build-Depends: debhelper (>=9),
golang-1.13-go
golang-1.18-go
Standards-Version: 3.9.6
Homepage: https://trzsz.github.io
Vcs-Browser: https://github.com/trzsz/trzsz-go
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export CGO_ENABLED=0
export GOCACHE=/tmp/.cache/go-build

%:
PATH="/usr/lib/go-1.13/bin:${PATH}" dh $@
PATH="/usr/lib/go-1.18/bin:${PATH}" dh $@
8 changes: 6 additions & 2 deletions trzsz/comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,14 @@ func checkPathReadable(pathID int, path string, info os.FileInfo, list *[]*Trzsz
}
for _, file := range files {
p := filepath.Join(path, file.Name())
info, err := os.Stat(p)
if err != nil {
return err
}
r := make([]string, len(relPath))
copy(r, relPath)
r = append(r, file.Name())
if err := checkPathReadable(pathID, p, file, list, r, visitedDir); err != nil {
if err := checkPathReadable(pathID, p, info, list, r, visitedDir); err != nil {
return err
}
}
Expand All @@ -268,7 +272,6 @@ func checkPathReadable(pathID int, path string, info os.FileInfo, list *[]*Trzsz

func checkPathsReadable(paths []string, directory bool) ([]*TrzszFile, error) {
var list []*TrzszFile
visitedDir := make(map[string]bool)
for i, p := range paths {
path, err := filepath.Abs(p)
if err != nil {
Expand All @@ -283,6 +286,7 @@ func checkPathsReadable(paths []string, directory bool) ([]*TrzszFile, error) {
if !directory && info.IsDir() {
return nil, newTrzszError(fmt.Sprintf("Is a directory: %s", path))
}
visitedDir := make(map[string]bool)
if err := checkPathReadable(i, path, info, &list, []string{info.Name()}, visitedDir); err != nil {
return nil, err
}
Expand Down
28 changes: 14 additions & 14 deletions trzsz/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (t *TrzszTransfer) cleanInput(timeoutDuration time.Duration) {
}

func (t *TrzszTransfer) writeAll(buf []byte) error {
if gTrzszArgs != nil && gTrzszArgs.TraceLog {
writeTraceLog(buf, false)
}
written := 0
length := len(buf)
for written < length {
Expand Down Expand Up @@ -381,7 +384,6 @@ func (t *TrzszTransfer) recvConfig() (map[string]interface{}, error) {
}

func (t *TrzszTransfer) clientExit(msg string) error {
t.cleanInput(200 * time.Millisecond)
return t.sendString("EXIT", msg)
}

Expand All @@ -395,9 +397,6 @@ func (t *TrzszTransfer) serverExit(msg string) {
term.Restore(int(os.Stdin.Fd()), t.stdinState)
}
os.Stdout.WriteString("\x1b8\x1b[0J")
if IsWindows() {
os.Stdout.WriteString("\r\n")
}
os.Stdout.WriteString(msg)
os.Stdout.WriteString("\n")
}
Expand Down Expand Up @@ -574,22 +573,23 @@ func (t *TrzszTransfer) sendFiles(files []*TrzszFile, progress ProgressCallback)
if err != nil {
return nil, err
}
buf := buffer[:n]
if err := t.sendData(buf, binary, escapeCodes); err != nil {
size := int64(n)
data := buffer[:n]
if err := t.sendData(data, binary, escapeCodes); err != nil {
return nil, err
}
if _, err := hasher.Write(buf); err != nil {
if _, err := hasher.Write(data); err != nil {
return nil, err
}
if err := t.checkInteger(int64(n)); err != nil {
if err := t.checkInteger(size); err != nil {
return nil, err
}
step += int64(n)
step += size
if progress != nil && !reflect.ValueOf(progress).IsNil() {
progress.onStep(step)
}
chunkTime := time.Now().Sub(beginTime)
if chunkTime < 500*time.Millisecond && bufSize < maxBufSize {
if size == bufSize && chunkTime < 500*time.Millisecond && bufSize < maxBufSize {
bufSize = minInt64(bufSize*2, maxBufSize)
buffer = make([]byte, bufSize)
}
Expand Down Expand Up @@ -624,15 +624,15 @@ func doCreateFile(path string) (*os.File, error) {
file, err := os.Create(path)
if err != nil {
if e, ok := err.(*fs.PathError); ok {
if errno, ok := e.Err.(syscall.Errno); ok {
if errno == 13 {
if errno, ok := e.Unwrap().(syscall.Errno); ok {
if (!IsWindows() && errno == 13) || (IsWindows() && errno == 5) {
return nil, newTrzszError(fmt.Sprintf("No permission to write: %s", path))
} else if errno == 21 {
} else if (!IsWindows() && errno == 21) || (IsWindows() && errno == 0x2000002a) {
return nil, newTrzszError(fmt.Sprintf("Is a directory: %s", path))
}
}
}
return nil, err
return nil, newTrzszError(fmt.Sprintf("%v", err))
}
return file, nil
}
Expand Down
Loading

0 comments on commit 834bd78

Please sign in to comment.