Skip to content

Commit

Permalink
Beter copy and compress
Browse files Browse the repository at this point in the history
  • Loading branch information
koudis committed Feb 14, 2024
1 parent 75425a0 commit 611ef3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
16 changes: 9 additions & 7 deletions modules/bringauto_package/Package.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bringauto_package

import (
"bringauto/modules/bringauto_prerequisites"
"compress/flate"
"fmt"
"github.com/mholt/archiver/v3"
"io/ioutil"
Expand Down Expand Up @@ -67,10 +68,9 @@ func (packg *Package) CheckPrerequisites(*bringauto_prerequisites.Args) error {
}

// CreatePackage creates a package from sourceDir directory
// - construct package name
// - zip all files into archive with name <package_name>.zip
// - copy the zip archive to the outputDir
//
// - construct package name
// - zip all files into archive with name <package_name>.zip
// - copy the zip archive to the outputDir
func (packg *Package) CreatePackage(sourceDir string, outputDir string) error {
var err error
if _, err = os.Stat(sourceDir); os.IsNotExist(err) {
Expand Down Expand Up @@ -123,9 +123,11 @@ func createZIPArchive(sourceDir string, archivePath string) error {
}

zipArchive := archiver.Zip{
MkdirAll: true,
FileMethod: archiver.Deflate,
OverwriteExisting: true,
MkdirAll: true,
FileMethod: archiver.Deflate,
OverwriteExisting: true,
SelectiveCompression: true,
CompressionLevel: flate.BestSpeed,
}

err = zipArchive.Archive(files, archivePath)
Expand Down
9 changes: 4 additions & 5 deletions modules/bringauto_ssh/SFTP.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type SFTP struct {
// Download directory from RemoteDir to EmptyLocalDir.
// EmptyLocalDir must be empty!
// Function returns error in case of problem or nil if succeeded.
//
func (sftpd *SFTP) DownloadDirectory() error {
var err error

Expand Down Expand Up @@ -71,7 +70,7 @@ func (sftpd *SFTP) copyRecursive(sftpClient *sftp.Client, remoteDir string, loca
normalizedRemoteDir, _ := normalizePath(remoteDir)
normalizedLocalDir, _ := normalizePath(localDir)

allDone := make(chan bool)
allDone := make(chan bool, 2000)
fileCount := 0

walk := sftpClient.Walk(normalizedRemoteDir)
Expand Down Expand Up @@ -114,8 +113,9 @@ func (sftpd *SFTP) copyRecursive(sftpClient *sftp.Client, remoteDir string, loca
fileCount += 1
go func() {
defer func() { allDone <- true }()
sourceFileBuff := bufio.NewReaderSize(sourceFile, 1024*1024*2)
destFileBuff := bufio.NewWriterSize(destFile, 1027*1024*2)

sourceFileBuff := bufio.NewReaderSize(sourceFile, 1024*1024)
destFileBuff := bufio.NewWriterSize(destFile, 1027*1024)

_, err = io.Copy(destFileBuff, sourceFileBuff)
if err != nil {
Expand Down Expand Up @@ -144,7 +144,6 @@ func (sftpd *SFTP) copyRecursive(sftpClient *sftp.Client, remoteDir string, loca
}

// normalizePath
//
func normalizePath(p string) (string, error) {
regexp, regexpErr := regexp.CompilePOSIX("[/]{2,}")
if regexpErr != nil {
Expand Down

0 comments on commit 611ef3b

Please sign in to comment.