Skip to content

Commit

Permalink
chore(deps): update (#310)
Browse files Browse the repository at this point in the history
* chore(go-releaser): update version

* chore(goreleaser): update config

* fix(zip): delete temporary file after transferring it (#304)

* Fixing deleting temporary files

* style(util):

* chore(deps): go mod tidy

---------

Co-authored-by: Claudio d'Angelis <claudiodangelis@gmail.com>

---------

Co-authored-by: Vincenzo Aiello <vincenzoaiello300@gmail.com>
  • Loading branch information
claudiodangelis and vincenzoAiello authored Dec 8, 2023
1 parent 64ffcab commit c2c3200
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.14.x
go-version: 1.21.x
# Runs the goreleaser
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
uses: goreleaser/goreleaser-action@v5
with:
version: v1.6.3
version: latest
args: release --rm-dist
key: ${{ secrets.YOUR_PRIVATE_KEY }}
env:
Expand Down
26 changes: 15 additions & 11 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ builds:
ignore:
- goos: darwin
goarch: 386
- goos: darwin
goarch: arm64
- goos: windows
goarch: arm64
archives:
- replacements:
darwin: macOS
windows: Windows
386: i386
amd64: x86_64
# - replacements:
# darwin: macOS
# windows: Windows
# 386: i386
# amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
Expand All @@ -49,12 +53,12 @@ release:
Refer to the list of assets below for all supported platform.
nfpms:
- replacements:
darwin: macOS
windows: Windows
386: i386
amd64: x86_64
homepage: https://claudiodangelis.com/qrcp
# - replacements:
# darwin: macOS
# windows: Windows
# 386: i386
# amd64: x86_64
- homepage: https://claudiodangelis.com/qrcp
maintainer: Claudio d'Angelis <claudiodangelis@gmail.com>
description: Transfer files over wifi from your computer to your mobile device by scanning a QR code without leaving the terminal.
license: MIT
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496
github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807
github.com/glendc/go-external-ip v0.1.0
github.com/jhoonb/archivex v0.0.0-20180718040744-0488e4ce1681
github.com/manifoldco/promptui v0.9.0
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1430,8 +1430,6 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jhoonb/archivex v0.0.0-20180718040744-0488e4ce1681 h1:EiEjLram6Y0WXygV4WyzKmTr3XaR4CD3tvjdTrsk3cU=
github.com/jhoonb/archivex v0.0.0-20180718040744-0488e4ce1681/go.mod h1:GN1Mg/uXQ6qwXA0HypnUO3xlcQJS9/y68EsHNeuuRa4=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down
94 changes: 77 additions & 17 deletions util/util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package util

import (
"archive/zip"
"crypto/rand"
"encoding/base64"
"errors"
Expand All @@ -14,8 +15,6 @@ import (
"strconv"
"strings"
"time"

"github.com/jhoonb/archivex"
)

// Expand tilde in paths
Expand All @@ -33,44 +32,105 @@ func Expand(input string) string {
return input
}

// add folder to the zip file
func addFolderToZip(zipWriter *zip.Writer, source, target string) error {

//explore the folder and add all to the zip
return filepath.Walk(source, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

header, err := zip.FileInfoHeader(info)
if err != nil {
return err
}
header.Name = path

if info.IsDir() {
header.Name += "/"
} else {
header.Method = zip.Deflate
}

writer, err := zipWriter.CreateHeader(header)
if err != nil {
return err
}

if info.IsDir() {
return nil
}

file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()

_, err = io.Copy(writer, file)
return err
})
}

// add files to the zip file
func addFileToZip(zipWriter *zip.Writer, fileToAdd string) error {
f1, err := os.Open(fileToAdd)
if err != nil {
return err
}
defer f1.Close()

w1, err := zipWriter.Create(filepath.Base(fileToAdd))
if err != nil {
panic(err)
}
if _, err := io.Copy(w1, f1); err != nil {
panic(err)
}

return nil
}

// ZipFiles and return the resulting zip's filename
func ZipFiles(files []string) (string, error) {
zip := new(archivex.ZipFile)
tmpfile, err := ioutil.TempFile("", "qrcp")
//create temporary file
tmpfile, err := os.CreateTemp("", "qrcp")
if err != nil {
return "", err
}
tempFileName := tmpfile.Name() + ".zip"
tmpfile.Close()
if err := os.Rename(tmpfile.Name(), tmpfile.Name()+".zip"); err != nil {
if err := os.Rename(tmpfile.Name(), tempFileName); err != nil {
return "", err
}
if err := zip.Create(tmpfile.Name() + ".zip"); err != nil {

//create zip file
zipFile, err := os.Create(tempFileName)
if err != nil {
return "", err
}
defer zipFile.Close()

//add files and folder in the zip
zipWriter := zip.NewWriter(zipFile)
defer zipWriter.Close()
for _, filename := range files {
fileinfo, err := os.Stat(filename)
if err != nil {
return "", err
}
if fileinfo.IsDir() {
if err := zip.AddAll(filename, true); err != nil {
if err := addFolderToZip(zipWriter, filename, tempFileName); err != nil {
return "", err
}
} else {
file, err := os.Open(filename)
if err != nil {
return "", err
}
defer file.Close()
if err := zip.Add(filename, file, fileinfo); err != nil {
if err := addFileToZip(zipWriter, filename); err != nil {
return "", err
}
}
}
if err := zip.Close(); err != nil {
return "", nil
}
return zip.Name, nil
return tempFileName, nil
}

// GetRandomURLPath returns a random string of 4 alphanumeric characters
Expand Down

0 comments on commit c2c3200

Please sign in to comment.