Skip to content

Commit 9296ec9

Browse files
jchionhmurphm8
authored andcommitted
Initial commit of the source code (#1)
1 parent 69c034c commit 9296ec9

31 files changed

+3189
-0
lines changed

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/eclipse-bin/
2+
/bin
3+
/build
4+
/pkg
5+
.classpath
6+
.project
7+
.settings
8+
.vscode/
9+
.DS_Store
10+
*.swp
11+
*.swo
12+
*.orig
13+
mock_*.go
14+
### JetBrains+all Patch ###
15+
# Ignores the whole .idea folder and all .iml files
16+
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
17+
18+
.idea/
19+
20+
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
21+
22+
*.iml
23+
modules.xml
24+
.idea/misc.xml
25+
*.ipr
26+
27+
**/*.swp
28+
29+
assets
30+
31+
# End of https://www.gitignore.io/api/jetbrains+all

LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,31 @@
173173
defend, and hold each Contributor harmless for any liability
174174
incurred by, or claims asserted against, such Contributor by reason
175175
of your accepting any such warranty or additional liability.
176+
177+
END OF TERMS AND CONDITIONS
178+
179+
APPENDIX: How to apply the Apache License to your work.
180+
181+
To apply the Apache License to your work, attach the following
182+
boilerplate notice, with the fields enclosed by brackets "[]"
183+
replaced with your own identifying information. (Don't include
184+
the brackets!) The text should be enclosed in the appropriate
185+
comment syntax for the file format. We also recommend that a
186+
file or class name and description of purpose be included on the
187+
same "printed page" as the copyright notice for easier
188+
identification within third-party archives.
189+
190+
Copyright 2019 Amazon.com, Inc. or its affiliates.
191+
192+
Licensed under the Apache License, Version 2.0 (the "License");
193+
you may not use this file except in compliance with the License.
194+
You may obtain a copy of the License at
195+
196+
http://www.apache.org/licenses/LICENSE-2.0
197+
198+
Unless required by applicable law or agreed to in writing, software
199+
distributed under the License is distributed on an "AS IS" BASIS,
200+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201+
See the License for the specific language governing permissions and
202+
limitations under the License.
203+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
** github.com/mholt/archiver; version 3.1.1 -- https://github.com/mholt/archiver
2+
Copyright (c) 2016 Matthew Holt
3+
4+
MIT License
5+
6+
Copyright (c) 2016 Matthew Holt
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in all
16+
copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
SOFTWARE.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package archiver
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"log"
7+
"os"
8+
"path/filepath"
9+
"runtime"
10+
"strings"
11+
)
12+
13+
// Archiver represent a archive format
14+
type Archiver interface {
15+
// Match checks supported files
16+
Match(filename string) bool
17+
// Make makes an archive file on disk.
18+
Make(destination string, sources []string) error
19+
// Open extracts an archive file on disk.
20+
Open(source, destination string) error
21+
// Write writes an archive to a Writer.
22+
Write(output io.Writer, sources []string) error
23+
// Read reads an archive from a Reader.
24+
Read(input io.Reader, destination string) error
25+
}
26+
27+
// SupportedFormats contains all supported archive formats
28+
var SupportedFormats = map[string]Archiver{}
29+
30+
// RegisterFormat adds a supported archive format
31+
func RegisterFormat(name string, format Archiver) {
32+
if _, ok := SupportedFormats[name]; ok {
33+
log.Printf("Format %s already exists, skip!\n", name)
34+
return
35+
}
36+
SupportedFormats[name] = format
37+
}
38+
39+
// MatchingFormat returns the first archive format that matches
40+
// the given file, or nil if there is no match
41+
func MatchingFormat(fpath string) Archiver {
42+
for _, fmt := range SupportedFormats {
43+
if fmt.Match(fpath) {
44+
return fmt
45+
}
46+
}
47+
return nil
48+
}
49+
50+
func writeNewFile(fpath string, in io.Reader, fm os.FileMode) error {
51+
err := os.MkdirAll(filepath.Dir(fpath), 0755)
52+
if err != nil {
53+
return fmt.Errorf("%s: making directory for file: %v", fpath, err)
54+
}
55+
56+
out, err := os.Create(fpath)
57+
if err != nil {
58+
return fmt.Errorf("%s: creating new file: %v", fpath, err)
59+
}
60+
defer out.Close()
61+
62+
err = out.Chmod(fm)
63+
if err != nil && runtime.GOOS != "windows" {
64+
return fmt.Errorf("%s: changing file mode: %v", fpath, err)
65+
}
66+
67+
_, err = io.Copy(out, in)
68+
if err != nil {
69+
return fmt.Errorf("%s: writing file: %v", fpath, err)
70+
}
71+
return nil
72+
}
73+
74+
func writeNewSymbolicLink(fpath string, target string) error {
75+
err := os.MkdirAll(filepath.Dir(fpath), 0755)
76+
if err != nil {
77+
return fmt.Errorf("%s: making directory for file: %v", fpath, err)
78+
}
79+
80+
_, err = os.Lstat(fpath)
81+
if err == nil {
82+
err = os.Remove(fpath)
83+
if err != nil {
84+
return fmt.Errorf("%s: failed to unlink: %+v", fpath, err)
85+
}
86+
}
87+
88+
err = os.Symlink(target, fpath)
89+
if err != nil {
90+
return fmt.Errorf("%s: making symbolic link for: %v", fpath, err)
91+
}
92+
93+
return nil
94+
}
95+
96+
func writeNewHardLink(fpath string, target string) error {
97+
err := os.MkdirAll(filepath.Dir(fpath), 0755)
98+
if err != nil {
99+
return fmt.Errorf("%s: making directory for file: %v", fpath, err)
100+
}
101+
102+
_, err = os.Lstat(fpath)
103+
if err == nil {
104+
err = os.Remove(fpath)
105+
if err != nil {
106+
return fmt.Errorf("%s: failed to unlink: %+v", fpath, err)
107+
}
108+
}
109+
110+
err = os.Link(target, fpath)
111+
if err != nil {
112+
return fmt.Errorf("%s: making hard link for: %v", fpath, err)
113+
}
114+
115+
return nil
116+
}
117+
118+
func mkdir(dirPath string) error {
119+
err := os.MkdirAll(dirPath, 0755)
120+
if err != nil {
121+
return fmt.Errorf("%s: making directory: %v", dirPath, err)
122+
}
123+
return nil
124+
}
125+
126+
func sanitizeExtractPath(filePath string, destination string) error {
127+
// to avoid zip slip (writing outside of the destination), we resolve
128+
// the target path, and make sure it's nested in the intended
129+
// destination, or bail otherwise.
130+
destpath := filepath.Join(destination, filePath)
131+
if !strings.HasPrefix(destpath, filepath.Clean(destination)) {
132+
return fmt.Errorf("%s: illegal file path", filePath)
133+
}
134+
return nil
135+
}

0 commit comments

Comments
 (0)