0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 21:30:16 +02:00

Fix tarinator for windows

This commit is contained in:
Zack Scholl 2018-04-22 07:22:42 -06:00
parent 1ced0aa532
commit f689ca3909
5 changed files with 15 additions and 6 deletions

4
Gopkg.lock generated
View file

@ -52,8 +52,8 @@
[[projects]] [[projects]]
name = "github.com/schollz/tarinator-go" name = "github.com/schollz/tarinator-go"
packages = ["."] packages = ["."]
revision = "835680f17d252bd7a6047e670079f35e5626dc1e" revision = "a8626a55d48dbb55141e51226eefa15c157a65a8"
version = "v0.1.0" version = "v0.3.3"
[[projects]] [[projects]]
name = "github.com/sirupsen/logrus" name = "github.com/sirupsen/logrus"

View file

@ -253,7 +253,7 @@ func (c *Connection) Run() error {
} }
if c.Local { if c.Local {
fmt.Fprintf(os.Stderr, "Receive with: croc --code 8-local --server %s --yes\n", GetLocalIP()) fmt.Fprintf(os.Stderr, "Receive with: croc --code %s --server %s --yes\n", c.Code, GetLocalIP())
} else { } else {
fmt.Fprintf(os.Stderr, "Code is: %s\n", c.Code) fmt.Fprintf(os.Stderr, "Code is: %s\n", c.Code)
} }

View file

@ -39,6 +39,13 @@ func Tarinate(paths []string, tarPath string) error {
} }
func tarwalk(source, target string, tw *tar.Writer) error { func tarwalk(source, target string, tw *tar.Writer) error {
source = filepath.ToSlash(source)
if len(source) > 0 {
if source[0:2] == "./" {
source = source[2:]
}
}
info, err := os.Stat(source) info, err := os.Stat(source)
if err != nil { if err != nil {
return nil return nil
@ -46,7 +53,8 @@ func tarwalk(source, target string, tw *tar.Writer) error {
var baseDir string var baseDir string
if info.IsDir() { if info.IsDir() {
baseDir = filepath.Base(source) baseDir = filepath.ToSlash(filepath.Base(source))
} }
return filepath.Walk(source, return filepath.Walk(source,
@ -59,6 +67,7 @@ func tarwalk(source, target string, tw *tar.Writer) error {
return err return err
} }
path = filepath.ToSlash(path)
if baseDir != "" { if baseDir != "" {
header.Name = filepath.ToSlash(filepath.Join(baseDir, strings.TrimPrefix(path, source))) header.Name = filepath.ToSlash(filepath.Join(baseDir, strings.TrimPrefix(path, source)))
} }
@ -104,7 +113,7 @@ func UnTarinate(extractPath, sourcefile string) error {
} }
tarBallReader := tar.NewReader(fileReader) tarBallReader := tar.NewReader(fileReader)
extractPath = filepath.FromSlash(extractPath)
for { for {
header, err := tarBallReader.Next() header, err := tarBallReader.Next()
if err != nil { if err != nil {

View file

@ -9,7 +9,7 @@ import (
func TestArchive(t *testing.T) { func TestArchive(t *testing.T) {
paths := []string{ paths := []string{
"somescript.sh", "somescript.sh",
"test_files/", "./test_files/",
} }
err := Tarinate(paths, "output_test.tar.gz") err := Tarinate(paths, "output_test.tar.gz")

View file