Skip to content

Commit

Permalink
Fixed issue mholt#222
Browse files Browse the repository at this point in the history
  • Loading branch information
iotanbo committed Oct 18, 2021
1 parent d35d4ce commit 601314e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
@@ -1,6 +1,8 @@
# 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>

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.
This is a fork of `github.com/mholt/archiver` adapted for usage with IGU.

Introducing **Archiver 3.5** - 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
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
3 changes: 2 additions & 1 deletion go.mod
@@ -1,4 +1,4 @@
module github.com/mholt/archiver/v3
module github.com/iotanbo/archiver/v3

go 1.13

Expand All @@ -8,6 +8,7 @@ require (
github.com/golang/snappy v0.0.2
github.com/klauspost/compress v1.11.4
github.com/klauspost/pgzip v1.2.5
github.com/mholt/archiver/v3 v3.5.0
github.com/nwaples/rardecode v1.1.0
github.com/pierrec/lz4/v4 v4.1.2
github.com/ulikunitz/xz v0.5.9
Expand Down
11 changes: 10 additions & 1 deletion go.sum
@@ -1,22 +1,31 @@
github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc=
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 h1:iFaUwBSo5Svw6L7HYpRu/0lE3e0BaElwnNO1qkNQxBY=
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj60/X5sZFNxpG4HBPDHVqxNm4DfnCKgrbZOT+s=
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw=
github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
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.4/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/mholt/archiver/v3 v3.5.0 h1:nE8gZIrw66cu4osS/U7UW7YDuGMHssxKutU8IfWxwWE=
github.com/mholt/archiver/v3 v3.5.0/go.mod h1:qqTTPUK/HZPFgFQ/TJ3BzvTpF/dPtFVJXdQbCmeMxwc=
github.com/nwaples/rardecode v1.1.0 h1:vSxaY8vQhOcVr4mm5e8XllHWTiM4JF507A0Katqw7MQ=
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/pierrec/lz4/v4 v4.0.3/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pierrec/lz4/v4 v4.1.2 h1:qvY3YFXRQE/XB8MlLzJH7mSzBs74eA2gg52YTk6jUPM=
github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I=
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
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
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 601314e

Please sign in to comment.