feat: file_save_disk, file_delete, file_serve, upload_parse, upload_handler, thumbnail_generate (issue 0014 fase 3)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: file_delete
|
||||
kind: function
|
||||
lang: go
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "func FileDelete(path string) error"
|
||||
description: "Elimina un archivo del disco. Rechaza paths con \"..\" para evitar path traversal. Retorna error si el archivo no existe o si falla el remove."
|
||||
tags: [file, delete, disk, storage, security, infra]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: [fmt, os, path/filepath, strings]
|
||||
params:
|
||||
- name: path
|
||||
desc: "ruta del archivo a eliminar (no debe contener \"..\")"
|
||||
output: "nil si el archivo se elimino correctamente, error si el path es vacio, contiene path traversal, no existe o falla la operacion"
|
||||
tested: true
|
||||
tests: ["elimina archivo existente", "rechaza path con ..", "rechaza path vacio", "retorna error si no existe"]
|
||||
test_file_path: "functions/infra/file_delete_test.go"
|
||||
file_path: "functions/infra/file_delete.go"
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```go
|
||||
err := FileDelete("./uploads/a1b2c3d4.png")
|
||||
if err != nil {
|
||||
log.Printf("delete fallo: %v", err)
|
||||
}
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
La proteccion contra path traversal es defensiva pero NO es suficiente por si sola: la app debe pasar paths que ya estan resueltos al directorio de storage (usar `filepath.Join(baseDir, storedName)`). Esta funcion es un cinturon adicional contra bugs en la app que llamaria.
|
||||
|
||||
NO sigue symlinks de forma especial — `os.Remove` borra el symlink, no el target.
|
||||
Reference in New Issue
Block a user