Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
fixing windows download and environment #3
Merged
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f6ca4fe
extension per os
m0veax dc3db08
prototyped .zip
m0veax a8b5e8a
method header
m0veax 464a822
fixed extensions
m0veax ea73135
decide either unzip or untar
m0veax ee85e22
downloading windows sources
m0veax 4169140
unzipping
m0veax 49ff549
cmd.exe for windows
m0veax f5fd250
whitespaces and restored gitignore
m0veax 245c982
find parent process
m0veax fda712c
run cmd exe in shell context
m0veax db09e94
package vars for extensions
m0veax e7c922e
extension as function param
m0veax 6392954
beautifying
m0veax 0e1aedc
added log output similar to tar
m0veax
Jump to file or symbol
Failed to load files and symbols.
| @@ -0,0 +1,58 @@ | ||
| +package main | ||
| + | ||
| +import ( | ||
| + "archive/zip" | ||
| + "io" | ||
| + "log" | ||
| + "os" | ||
| + "path/filepath" | ||
| +) | ||
| + | ||
| +func unzip(source, target string) { | ||
| + | ||
| + r, err := zip.OpenReader(source) | ||
| + | ||
| + defer r.Close() | ||
| + | ||
| + if err != nil { | ||
| + log.Fatal(err) | ||
| + } | ||
| + | ||
| + if err := os.MkdirAll(target, 0755); err != nil { | ||
| + | ||
| + log.Fatal(err) | ||
| + } | ||
| + | ||
| + for _, file := range r.File { | ||
| + | ||
| + path := filepath.Join(target, file.Name) | ||
| + if file.FileInfo().IsDir() { | ||
| + log.Println("Creating directory :", file.Name) | ||
| + os.MkdirAll(path, file.Mode()) | ||
| + continue | ||
| + } | ||
| + | ||
| + fileReader, err := file.Open() | ||
| + if err != nil { | ||
| + log.Fatal(err) | ||
| + } | ||
| + | ||
| + defer fileReader.Close() | ||
| + | ||
| + targetFile, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, file.Mode()) | ||
| + if err != nil { | ||
| + log.Fatal(err) | ||
| + } | ||
| + | ||
| + defer targetFile.Close() | ||
| + | ||
| + log.Println("Unzipping :", file.Name) | ||
| + | ||
| + if _, err := io.Copy(targetFile, fileReader); err != nil { | ||
| + | ||
| + log.Fatal(err) | ||
| + } | ||
| + | ||
| + } | ||
| + | ||
| +} |