cloud-game/pkg/extractor/zip/extractor.go
sergystepanov 1fcf34ee02
Add new Libretro core manager module (#249)
* Add initial external configuration files support.

These external configuration files allow changing app params at the runtime without recompilation.

* Find config files with specified directory in the tests

* Add aspect ratio recalculation config

* Clean code

* Add new configuration files into the Docker container image

* Add shared core and config paths into the Libretro cores config

* Split ROM <-> Emulator mapping between workers and coordinators

* Extract coordinator config

* Add shared worker/coordinator server config

* Add explicit embedded shared worker/coordinator struct for auto-config reflection fill

* Remove default stun/turn servers from the config

* Extract and add new ice servers config structures

* Update coordinator config params

* Add auto emulation lib loader based on the runtime OS/arch

* Update configuration structures

* Remove shared config embedding

* Add missing network config params

* Add game library external config

* Remove unused config parameters

* Add WebRTC encoder external options

* Add user dir for config search

* Update config loader

* Update config

* Add generic downloader with Grab lib implementation

* Add a simple file downloader backed by the grab lib

* Add initial Libretro core repos abstractions

* Expose compression info for Libretro cores repository records

* Add pipe-based abstract file downloader

* Refactor downloader

* Refactor Libretro repos

* Add worker coresync stubs

* Add multiprocess-safe HTTP-based core manager implementation

* Remove Libretro cores from the repo

* Keep custom N64 cores in te repo for now

* Add Libretro cores repo select in the config

* Fix http manager repo switch

* Cleanup code

* Add greedy Libretro lib loader

* Don't crash when arch map is not set

* Disable dynamic recompiler for pcsx core by default since it's could cause a crash

* Use global Libretro dynalib handler

* Shorten the default Libretro cores store path

* Update zip extractor implementation

* Remove explicit fig lib field markings

* Add config note to the README file

* Add GitHub repo backend for the core downloader

* Fix GitHub repo param list in the manager factory

* Add env variables reader with CLOUD_GAME prefix

* Re-optimize ice server info struct custom marshaler
2020-12-31 13:24:27 +03:00

67 lines
1.3 KiB
Go

package zip
import (
"archive/zip"
"io"
"log"
"os"
"path/filepath"
"strings"
)
type Extractor struct{}
func New() Extractor { return Extractor{} }
func (e Extractor) Extract(src string, dest string) (files []string, err error) {
r, err := zip.OpenReader(src)
if err != nil {
return files, err
}
defer r.Close()
for _, f := range r.File {
path := filepath.Join(dest, f.Name)
// negate ZipSlip vulnerability (http://bit.ly/2MsjAWE)
if !strings.HasPrefix(path, filepath.Clean(dest)+string(os.PathSeparator)) {
log.Printf("warning: %s is illegal path", path)
continue
}
// remake directory
if f.FileInfo().IsDir() {
if err := os.MkdirAll(path, os.ModePerm); err != nil {
log.Printf("error: %v", err)
}
continue
}
// make file
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
log.Printf("error: %v", err)
continue
}
out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
log.Printf("error: %v", err)
continue
}
rc, err := f.Open()
if err != nil {
log.Printf("error: %v", err)
continue
}
if _, err = io.Copy(out, rc); err != nil {
log.Printf("error: %v", err)
_ = out.Close()
_ = rc.Close()
continue
}
_ = out.Close()
_ = rc.Close()
files = append(files, path)
}
return files, nil
}