scran import is working

This commit is contained in:
venture
2026-11-16 11:31:37 +01:00
parent 7b3f20b8d7
commit 01233c216e
6 changed files with 570 additions and 32 deletions
+24 -5
View File
@@ -33,12 +33,15 @@ type Prober interface {
type BasicProber struct{}
func (BasicProber) Probe(_ context.Context, path string, _ fs.FileInfo) (Probe, error) {
return Probe{Mime: mimeForPath(path)}, nil
}
func mimeForPath(path string) string {
mimeType := mime.TypeByExtension(strings.ToLower(filepath.Ext(path)))
if mimeType == "" {
mimeType = "application/octet-stream"
}
return Probe{Mime: mimeType}, nil
return mimeType
}
type Service struct {
@@ -65,6 +68,7 @@ type ScanResult struct {
Created int
Updated int
Unchanged int
Pruned int
Errors []ScanError
}
@@ -129,8 +133,20 @@ func metadataJSON(existing string, updates map[string]any) (string, error) {
return string(encoded), nil
}
func fileMetadata(existing, relPath string, info fs.FileInfo, probe Probe) (string, error) {
func hasSourcePath(metadata, root string) bool {
var values map[string]any
if err := json.Unmarshal([]byte(metadata), &values); err != nil {
return false
}
sourceRoot, _ := values["source_root"].(string)
sourcePath, ok := values["source_path"].(string)
return ok && sourcePath != "" && sourceRoot == root
}
func fileMetadata(existing, root, relPath string, info fs.FileInfo, probe Probe) (string, error) {
updates := map[string]any{
"source_root": root,
"source_path": relPath,
"size": info.Size(),
"mtime": info.ModTime().UnixMilli(),
@@ -145,6 +161,9 @@ func fileMetadata(existing, relPath string, info fs.FileInfo, probe Probe) (stri
return metadataJSON(existing, updates)
}
func directoryMetadata(existing, relPath string) (string, error) {
return metadataJSON(existing, map[string]any{"source_path": relPath})
func directoryMetadata(existing, root, relPath string) (string, error) {
return metadataJSON(existing, map[string]any{
"source_root": root,
"source_path": relPath,
})
}