47fac22230
- .claude/CLAUDE.md - .claude/commands/subagentes.md - .claude/rules/INDEX.md - .mcp.json - bash/functions/cybersecurity/analyze_dns.md - bash/functions/cybersecurity/audit_http_headers.md - bash/functions/cybersecurity/audit_ssh_config.md - bash/functions/cybersecurity/check_firewall.md - bash/functions/cybersecurity/detect_suspicious_users.md - bash/functions/cybersecurity/encrypt_file.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
62 lines
2.3 KiB
Markdown
62 lines
2.3 KiB
Markdown
---
|
|
name: pc_locations_drift
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func PcLocationsDrift(registryRoot string, pcID string) ([]LocationDrift, error)"
|
|
description: "Compara la tabla pc_locations contra el estado real del disco para el PC actual. Detecta tres tipos de drift: carpetas activas que no existen, entradas missing cuya carpeta reaparece, y artefactos indexados en disco sin fila en pc_locations."
|
|
tags: [doctor, sync, pc_locations, drift, pendiente-usar]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports:
|
|
- "bufio"
|
|
- "database/sql"
|
|
- "fmt"
|
|
- "os"
|
|
- "path/filepath"
|
|
- "strings"
|
|
- "github.com/mattn/go-sqlite3"
|
|
tested: true
|
|
tests:
|
|
- "active entry whose folder is missing reports missing_on_disk"
|
|
- "active entry with existing folder reports no drift"
|
|
- "missing entry whose folder reappears reports status_should_be_active"
|
|
- "indexed app on disk without pc_locations row reports untracked_on_disk"
|
|
test_file_path: "functions/infra/pc_locations_drift_test.go"
|
|
file_path: "functions/infra/pc_locations_drift.go"
|
|
params:
|
|
- name: registryRoot
|
|
desc: "Ruta absoluta a la raiz del registry (donde vive registry.db)."
|
|
- name: pcID
|
|
desc: "Identificador del PC (ej: 'home-wsl'). Si vacio, se lee de la primera linea no vacia de ~/.fn_pc."
|
|
output: "Slice de LocationDrift con todos los discrepancias encontradas. Vacio si no hay drift. Error solo si no se puede abrir registry.db."
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
drifts, err := PcLocationsDrift("/home/lucas/fn_registry", "")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
for _, d := range drifts {
|
|
fmt.Printf("[%s] %s/%s -> %s\n", d.Issue, d.EntityType, d.EntityID, d.DirPath)
|
|
}
|
|
```
|
|
|
|
## Notas
|
|
|
|
Read-only — nunca modifica la BD ni el disco. Util como paso inicial de `fn doctor sync`.
|
|
|
|
La funcion `readFnPC` es compartida en el paquete infra (lee `~/.fn_pc` ignorando lineas vacias y comentarios con `#`).
|
|
|
|
Tipos de issue reportados:
|
|
- `missing_on_disk`: entrada `active` cuya carpeta no existe → sugerir cambiar status a `missing`
|
|
- `status_should_be_active`: entrada `missing` cuya carpeta existe → sugerir cambiar status a `active`
|
|
- `untracked_on_disk`: artefacto indexado con carpeta en disco pero sin fila en `pc_locations` → sugerir insertar
|