mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
feat(fmt): Fix formatting
This commit is contained in:
@@ -27,7 +27,7 @@ func DownloadToFile(ctx context.Context, client *http.Client, req *http.Request,
|
||||
// Attach context.
|
||||
req = req.WithContext(ctx)
|
||||
|
||||
logger.DebugCF("download", "Starting download", map[string]interface{}{
|
||||
logger.DebugCF("download", "Starting download", map[string]any{
|
||||
"url": req.URL.String(),
|
||||
"max_bytes": maxBytes,
|
||||
})
|
||||
@@ -52,7 +52,7 @@ func DownloadToFile(ctx context.Context, client *http.Client, req *http.Request,
|
||||
}
|
||||
tmpPath := tmpFile.Name()
|
||||
|
||||
logger.DebugCF("download", "Streaming to temp file", map[string]interface{}{
|
||||
logger.DebugCF("download", "Streaming to temp file", map[string]any{
|
||||
"path": tmpPath,
|
||||
})
|
||||
|
||||
@@ -84,7 +84,7 @@ func DownloadToFile(ctx context.Context, client *http.Client, req *http.Request,
|
||||
return "", fmt.Errorf("failed to close temp file: %w", err)
|
||||
}
|
||||
|
||||
logger.DebugCF("download", "Download complete", map[string]interface{}{
|
||||
logger.DebugCF("download", "Download complete", map[string]any{
|
||||
"path": tmpPath,
|
||||
"bytes_written": written,
|
||||
})
|
||||
|
||||
+7
-6
@@ -22,13 +22,13 @@ func ExtractZipFile(zipPath string, targetDir string) error {
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
logger.DebugCF("zip", "Extracting ZIP", map[string]interface{}{
|
||||
logger.DebugCF("zip", "Extracting ZIP", map[string]any{
|
||||
"zip_path": zipPath,
|
||||
"target_dir": targetDir,
|
||||
"entries": len(reader.File),
|
||||
})
|
||||
|
||||
if err := os.MkdirAll(targetDir, 0755); err != nil {
|
||||
if err := os.MkdirAll(targetDir, 0o755); err != nil {
|
||||
return fmt.Errorf("failed to create target dir: %w", err)
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ func ExtractZipFile(zipPath string, targetDir string) error {
|
||||
|
||||
// Double-check the resolved path is within target directory (defense-in-depth).
|
||||
targetDirClean := filepath.Clean(targetDir)
|
||||
if !strings.HasPrefix(filepath.Clean(destPath), targetDirClean+string(filepath.Separator)) && filepath.Clean(destPath) != targetDirClean {
|
||||
if !strings.HasPrefix(filepath.Clean(destPath), targetDirClean+string(filepath.Separator)) &&
|
||||
filepath.Clean(destPath) != targetDirClean {
|
||||
return fmt.Errorf("zip entry escapes target dir: %q", f.Name)
|
||||
}
|
||||
|
||||
@@ -55,14 +56,14 @@ func ExtractZipFile(zipPath string, targetDir string) error {
|
||||
}
|
||||
|
||||
if f.FileInfo().IsDir() {
|
||||
if err := os.MkdirAll(destPath, 0755); err != nil {
|
||||
if err := os.MkdirAll(destPath, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// Ensure parent directory exists.
|
||||
if err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil {
|
||||
if err := os.MkdirAll(filepath.Dir(destPath), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -98,7 +99,7 @@ func extractSingleFile(f *zip.File, destPath string) error {
|
||||
defer func() {
|
||||
if cerr := outFile.Close(); cerr != nil {
|
||||
_ = os.Remove(destPath)
|
||||
logger.ErrorCF("zip", "Failed to close file", map[string]interface{}{
|
||||
logger.ErrorCF("zip", "Failed to close file", map[string]any{
|
||||
"dest_path": destPath,
|
||||
"error": cerr.Error(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user