Initial updates server repository commit.
Reinitialize repository history and exclude generated OTA artifact outputs. Made-with: Cursor
This commit is contained in:
55
internal/storage/zip.go
Normal file
55
internal/storage/zip.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func unzipToDir(readerAt io.ReaderAt, size int64, target string) error {
|
||||
if err := os.MkdirAll(target, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
zr, err := zip.NewReader(readerAt, size)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range zr.File {
|
||||
name := filepath.Clean(f.Name)
|
||||
if strings.HasPrefix(name, "..") {
|
||||
return fmt.Errorf("invalid zip entry path: %s", f.Name)
|
||||
}
|
||||
fullPath := filepath.Join(target, name)
|
||||
if f.FileInfo().IsDir() {
|
||||
if err := os.MkdirAll(fullPath, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(fullPath), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
src, err := f.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dst, err := os.Create(fullPath)
|
||||
if err != nil {
|
||||
src.Close()
|
||||
return err
|
||||
}
|
||||
if _, err := io.Copy(dst, src); err != nil {
|
||||
dst.Close()
|
||||
src.Close()
|
||||
return err
|
||||
}
|
||||
dst.Close()
|
||||
src.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user