Skip to content

Commit

Permalink
Fix issue mholt#222 in package github.com/iotanbo/archiver/v3
Browse files Browse the repository at this point in the history
  • Loading branch information
iotanbo authored and sugurd committed Oct 19, 2021
1 parent d35d4ce commit 404089f
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 15 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/macos-latest.yml
@@ -0,0 +1,25 @@
name: Macos-latest

on:
push:
branches: [ master, iotanbo ]
pull_request:
branches: [ master, iotanbo ]

jobs:

build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Build
run: go build cmd/arc/*.go

- name: Test
run: go test -v ./...
25 changes: 25 additions & 0 deletions .github/workflows/ubuntu-latest.yml
@@ -0,0 +1,25 @@
name: Ubuntu-latest

on:
push:
branches: [ master, iotanbo ]
pull_request:
branches: [ master, iotanbo ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Build
run: go build cmd/arc/*.go

- name: Test
run: go test -v ./...
25 changes: 25 additions & 0 deletions .github/workflows/windows-latest.yml
@@ -0,0 +1,25 @@
name: Windows-latest

on:
push:
branches: [ master, iotanbo ]
pull_request:
branches: [ master, iotanbo ]

jobs:

build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Build
run: go build cmd/arc/main.go

- name: Test
run: go test -v ./...
19 changes: 15 additions & 4 deletions README.md
@@ -1,6 +1,17 @@
# archiver [![archiver GoDoc](https://img.shields.io/badge/reference-godoc-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/mholt/archiver?tab=doc) <a href="https://dev.azure.com/mholt-dev/Archiver/_build"><img src="https://img.shields.io/azure-devops/build/mholt-dev/1e14e7f7-f929-4fec-a1db-fa5a3c0d4ca9/2/master.svg?label=cross-platform%20tests&style=flat-square"></a>
# archiver [![archiver GoDoc](https://img.shields.io/badge/reference-godoc-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/mholt/archiver?tab=doc) <a href="https://dev.azure.com/mholt-dev/Archiver/_build"><img src="https://img.shields.io/azure-devops/build/mholt-dev/1e14e7f7-f929-4fec-a1db-fa5a3c0d4ca9/2/master.svg?label=cross-platform%20tests&style=flat-square"></a> [![Ubuntu-latest](https://github.com/iotanbo/archiver/actions/workflows/ubuntu-latest.yml/badge.svg)](https://github.com/iotanbo/archiver/actions/workflows/ubuntu-latest.yml) [![Macos-latest](https://github.com/iotanbo/archiver/actions/workflows/macos-latest.yml/badge.svg)](https://github.com/iotanbo/archiver/actions/workflows/macos-latest.yml) [![Windows-latest](https://github.com/iotanbo/archiver/actions/workflows/windows-latest.yml/badge.svg)](https://github.com/iotanbo/archiver/actions/workflows/windows-latest.yml)

Introducing **Archiver 3.1** - a cross-platform, multi-format archive utility and Go library. A powerful and flexible library meets an elegant CLI in this generic replacement for several platform-specific or format-specific archive utilities.
## Note
This is a fork of https://github.com/mholt/archiver with some issues fixed.
It is recommended to use the original package except if you need those urgent fixes.
To use this package:

```
go get github.com/iotanbo/archiver/v3@v3.5.1-iotanbo
import "github.com/iotanbo/archiver/v3"
```
## About

Introducing **Archiver 3** - a cross-platform, multi-format archive utility and Go library. A powerful and flexible library meets an elegant CLI in this generic replacement for several platform-specific or format-specific archive utilities.

## Features

Expand Down Expand Up @@ -203,11 +214,11 @@ The archiver package allows you to easily create and open archives, walk their c
To use as a dependency in your project:

```bash
go get github.com/mholt/archiver/v3
go get github.com/iotanbo/archiver/v3@v3.5.1-iotanbo
```

```go
import "github.com/mholt/archiver/v3"
import "github.com/iotanbo/archiver/v3"
```

[See the package's GoDoc](https://pkg.go.dev/github.com/mholt/archiver?tab=doc) for full API documentation.
Expand Down
6 changes: 5 additions & 1 deletion archiver.go
Expand Up @@ -125,6 +125,9 @@ type File struct {
type FileInfo struct {
os.FileInfo
CustomName string
// Stores path to the source.
// Used when reading a symlink.
SrcPath string
}

// Name returns fi.CustomName if not empty;
Expand Down Expand Up @@ -358,10 +361,11 @@ func isSymlink(fi os.FileInfo) bool {

// within returns true if sub is within or equal to parent.
func within(parent, sub string) bool {
rel, err := filepath.Rel(parent, sub)
rel, err := filepath.Rel(parent, sub) //rel
if err != nil {
return false
}
//return true
return !strings.Contains(rel, "..")
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/arc/main.go
Expand Up @@ -10,8 +10,8 @@ import (
"path/filepath"
"strings"

"github.com/iotanbo/archiver/v3"
"github.com/klauspost/compress/zip"
"github.com/mholt/archiver/v3"
"github.com/nwaples/rardecode"
)

Expand Down
2 changes: 1 addition & 1 deletion error_test.go
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

"github.com/mholt/archiver/v3"
"github.com/iotanbo/archiver/v3"
)

func TestIllegalPathErrorString(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
@@ -1,4 +1,4 @@
module github.com/mholt/archiver/v3
module github.com/iotanbo/archiver/v3

go 1.13

Expand Down
1 change: 0 additions & 1 deletion go.sum
Expand Up @@ -9,7 +9,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.11.4 h1:kz40R/YWls3iqT9zX9AHN3WoVsrAWVyui5sxuLqiXqU=
github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
Expand Down
9 changes: 7 additions & 2 deletions tar.go
Expand Up @@ -327,6 +327,7 @@ func (t *Tar) writeWalk(source, topLevelFolder, destination string) error {
FileInfo: FileInfo{
FileInfo: info,
CustomName: nameInArchive,
SrcPath: fpath,
},
ReadCloser: file,
})
Expand Down Expand Up @@ -372,10 +373,14 @@ func (t *Tar) Write(f File) error {

var linkTarget string
if isSymlink(f) {
fi, ok := f.FileInfo.(FileInfo)
if !ok {
return fmt.Errorf("failed to cast fs.FileInfo to archiver.FileInfo: %v", f)
}
var err error
linkTarget, err = os.Readlink(f.Name())
linkTarget, err = os.Readlink(fi.SrcPath)
if err != nil {
return fmt.Errorf("%s: readlink: %v", f.Name(), err)
return fmt.Errorf("%s: readlink: %v", fi.SrcPath, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tar_test.go
Expand Up @@ -6,7 +6,7 @@ import (
"path"
"testing"

"github.com/mholt/archiver/v3"
"github.com/iotanbo/archiver/v3"
)

func requireRegularFile(t *testing.T, path string) os.FileInfo {
Expand Down
11 changes: 8 additions & 3 deletions zip.go
Expand Up @@ -350,6 +350,7 @@ func (z *Zip) writeWalk(source, topLevelFolder, destination string) error {
FileInfo: FileInfo{
FileInfo: info,
CustomName: nameInArchive,
SrcPath: fpath,
},
ReadCloser: file,
})
Expand Down Expand Up @@ -431,14 +432,18 @@ func (z *Zip) writeFile(f File, writer io.Writer) error {
return nil // directories have no contents
}
if isSymlink(f) {
fi, ok := f.FileInfo.(FileInfo)
if !ok {
return fmt.Errorf("failed to cast fs.FileInfo to archiver.FileInfo: %v", f)
}
// file body for symlinks is the symlink target
linkTarget, err := os.Readlink(f.Name())
linkTarget, err := os.Readlink(fi.SrcPath)
if err != nil {
return fmt.Errorf("%s: readlink: %v", f.Name(), err)
return fmt.Errorf("%s: readlink: %v", fi.SrcPath, err)
}
_, err = writer.Write([]byte(filepath.ToSlash(linkTarget)))
if err != nil {
return fmt.Errorf("%s: writing symlink target: %v", f.Name(), err)
return fmt.Errorf("%s: writing symlink target: %v", fi.SrcPath, err)
}
return nil
}
Expand Down

0 comments on commit 404089f

Please sign in to comment.