Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
feat: add multi-path support and ZIP improvements across file APIs
Dmitry Ngca9f4a021167
diff --git a/backend/pkg/flowfiles/files.go b/backend/pkg/flowfiles/files.goindex 418ef755..f1766664 100644--- a/backend/pkg/flowfiles/files.go+++ b/backend/pkg/flowfiles/files.go@@ -278,8 +278,14 @@ func ListDirEntriesRecursive(dir, sourceDir string) ([]File, error) {func Sort(files []File) {sort.Slice(files, func(i, j int) bool {- if files[i].ModifiedAt.Equal(files[j].ModifiedAt) {- return files[i].Name < files[j].Name+ if files[i].Path < files[j].Path {+ return true+ } else if files[i].Path > files[j].Path {+ return false+ } else if files[i].Name < files[j].Name {+ return true+ } else if files[i].Name > files[j].Name {+ return false}return files[i].ModifiedAt.After(files[j].ModifiedAt)})@@ -443,27 +449,94 @@ func ZipDirectory(w io.Writer, dirPath string) error {return fmt.Errorf("failed to get file info: %w", err)}- header, err := zip.FileInfoHeader(info)+ return zipWriteFile(zw, entryPath, filepath.ToSlash(rel), info)+ })+}++// ZipRelativePaths writes a set of cache-relative paths into a single ZIP+// stream. Each relPath is resolved against baseDir:+// - Regular files are stored under their relPath (e.g. "uploads/file.txt").+// - Directories are walked recursively; each nested regular file is stored+// under relPath + "/" + path-relative-to-dir (e.g. "container/etc/nginx.conf").+// - Symlinks and other special entries are silently skipped.+// - Missing entries are silently skipped to tolerate concurrent cache changes.+//+// The caller is responsible for deduplicating relPaths before calling this+// function; no internal deduplication of ZIP entry names is performed.+func ZipRelativePaths(w io.Writer, baseDir string, relPaths []string) error {+ zw := zip.NewWriter(w)+ defer zw.Close()++ for _, relPath := range relPaths {+ localPath := filepath.Join(baseDir, filepath.FromSlash(relPath))++ info, err := os.Lstat(localPath)if err != nil {- return fmt.Errorf("failed to create zip header: %w", err)+ if errors.Is(err, os.ErrNotExist) {+ continue+ }+ return fmt.Errorf("stat %q: %w", relPath, err)+ }+ if info.Mode()&os.ModeSymlink != 0 {+ continue}- header.Name = filepath.ToSlash(rel)- header.Method = zip.Deflate- zf, err := zw.CreateHeader(header)- if err != nil {- return fmt.Errorf("failed to create zip entry: %w", err)+ if info.Mode().IsRegular() {+ if err := zipWriteFile(zw, localPath, relPath, info); err != nil {+ return err+ }+ continue}- f, err := os.Open(entryPath)- if err != nil {- return fmt.Errorf("failed to open file for zip: %w", err)+ if !info.IsDir() {+ continue}- defer f.Close()- _, err = io.Copy(zf, f)- return err- })+ if err := filepath.WalkDir(localPath, func(entryPath string, d fs.DirEntry, err error) error {+ if err != nil {+ return err+ }+ if d.Type()&os.ModeSymlink != 0 || d.IsDir() || !d.Type().IsRegular() {+ return nil+ }+ rel, err := filepath.Rel(localPath, entryPath)+ if err != nil {+ return fmt.Errorf("relative path: %w", err)+ }+ fi, err := d.Info()+ if err != nil {+ return err+ }+ return zipWriteFile(zw, entryPath, path.Join(relPath, filepath.ToSlash(rel)), fi)+ }); err != nil {+ return fmt.Errorf("walking %q: %w", relPath, err)+ }+ }++ return nil+}++// zipWriteFile adds a single regular file to an open zip.Writer.+func zipWriteFile(zw *zip.Writer, localPath, zipName string, info os.FileInfo) error {+ header, err := zip.FileInfoHeader(info)+ if err != nil {+ return fmt.Errorf("failed to create zip header for %q: %w", zipName, err)+ }+ header.Name = zipName+ header.Method = zip.Deflate++ zf, err := zw.CreateHeader(header)+ if err != nil {+ return fmt.Errorf("failed to create zip entry %q: %w", zipName, err)+ }++ f, err := os.Open(localPath)+ if err != nil {+ return fmt.Errorf("failed to open %q for zip: %w", localPath, err)+ }+ _, copyErr := io.Copy(zf, f)+ f.Close()+ return copyErr}// ResourceRef is a lightweight reference to a user resource for copying into a flow.@@ -718,6 +791,85 @@ func collectRelativeFilePaths(dir string) []string {return paths}+// DeduplicatePaths returns a deduplicated, coverage-minimised slice of the+// original input paths, preserving first-occurrence order. The rules applied:+//+// 1. Whitespace-only entries are dropped.+// 2. Entries whose path.Clean form is an absolute path or starts with "../"+// are silently dropped (path-traversal safety).+// 3. Paths whose path.Clean forms are equal are deduplicated; the first+// occurrence (original value) wins.+// 4. A path that is a descendant of another surviving path is dropped because+// the ancestor already covers it. For example, when both "uploads/dir" and+// "uploads/dir/file.txt" are present, only "uploads/dir" is kept.+//+// The "/" suffix trick is used for the ancestor check to ensure that+// "uploads/my_dir" does not erroneously cover "uploads/my_dir_extra".+//+// Original (un-normalised) values of surviving paths are returned.+func DeduplicatePaths(paths []string) []string {+ type entry struct {+ original string+ clean string // path.Clean result used only for comparison+ }++ entries := make([]entry, 0, len(paths))+ seen := make(map[string]struct{}, len(paths))++ for _, p := range paths {+ trimmed := strings.TrimSpace(p)+ if trimmed == "" {+ continue+ }++ // Normalise for comparison (backslashes → forward slashes, then Clean).+ normalized := path.Clean(strings.ReplaceAll(trimmed, "\\", "/"))++ // Safety: reject absolute paths and anything that escapes via "..".+ if path.IsAbs(normalized) || normalized == ".." || strings.HasPrefix(normalized, "../") {+ continue+ }++ // Exact-path deduplication (after normalisation).+ if _, dup := seen[normalized]; dup {+ continue+ }+ seen[normalized] = struct{}{}++ entries = append(entries, entry{original: trimmed, clean: normalized})+ }++ if len(entries) == 0 {+ return nil+ }++ // Coverage deduplication: drop entry B if any other entry A is an ancestor+ // of B. A is an ancestor when B's clean path with "/" appended starts with+ // A's clean path with "/" appended:+ // strings.HasPrefix(cleanB+"/", cleanA+"/")+ // The "/" suffix on both sides prevents "uploads/dir_x" from matching+ // "uploads/dir" as a parent.+ result := make([]string, 0, len(entries))+ for i, b := range entries {+ bPrefix := b.clean + "/"+ covered := false+ for j, a := range entries {+ if i == j {+ continue+ }+ if strings.HasPrefix(bPrefix, a.clean+"/") {+ covered = true+ break+ }+ }+ if !covered {+ result = append(result, b.original)+ }+ }++ return result+}+// BaseName returns the last path component of a slash-separated path.func BaseName(p string) string {for i := len(p) - 1; i >= 0; i-- {diff --git a/backend/pkg/flowfiles/files_test.go b/backend/pkg/flowfiles/files_test.goindex 83891cdb..fe18ecec 100644--- a/backend/pkg/flowfiles/files_test.go+++ b/backend/pkg/flowfiles/files_test.go@@ -638,6 +638,53 @@ func TestExtractTarRejectsTooManyFiles(t *testing.T) {assert.Contains(t, err.Error(), "maximum file count")}+func TestZipRelativePaths(t *testing.T) {+ t.Run("files and directory contents with cache-relative names", func(t *testing.T) {+ base := t.TempDir()+ require.NoError(t, os.MkdirAll(filepath.Join(base, "uploads"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(base, "uploads", "a.txt"), []byte("alpha"), 0644))+ require.NoError(t, os.MkdirAll(filepath.Join(base, "container", "etc", "nginx"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(base, "container", "etc", "nginx", "nginx.conf"), []byte("nginx"), 0644))+ if err := os.Symlink(filepath.Join(base, "uploads", "a.txt"), filepath.Join(base, "uploads", "link.txt")); err != nil {+ t.Skipf("symlink creation not available: %v", err)+ }++ var buf bytes.Buffer+ err := ZipRelativePaths(&buf, base, []string{+ "uploads/a.txt",+ "uploads/link.txt", // symlink: skipped+ "container/etc", // directory: entries under container/etc/...+ "uploads/missing.txt", // missing: silently skipped+ })+ require.NoError(t, err)++ zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))+ require.NoError(t, err)+ contents := map[string]string{}+ for _, f := range zr.File {+ rc, err := f.Open()+ require.NoError(t, err)+ data, _ := io.ReadAll(rc)+ rc.Close()+ contents[f.Name] = string(data)+ }++ assert.Equal(t, "alpha", contents["uploads/a.txt"])+ assert.Equal(t, "nginx", contents["container/etc/nginx/nginx.conf"])+ assert.NotContains(t, contents, "uploads/link.txt", "symlinks must be excluded")+ assert.NotContains(t, contents, "uploads/missing.txt", "missing files must be silently skipped")+ })++ t.Run("empty relPaths produces empty zip", func(t *testing.T) {+ var buf bytes.Buffer+ require.NoError(t, ZipRelativePaths(&buf, t.TempDir(), nil))++ zr, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))+ require.NoError(t, err)+ assert.Empty(t, zr.File)+ })+}+func TestZipDirectory(t *testing.T) {src := t.TempDir()require.NoError(t, os.WriteFile(filepath.Join(src, "a.txt"), []byte("hello"), 0644))@@ -685,16 +732,226 @@ func TestZipDirectoryExcludesSymlinks(t *testing.T) {assert.NotContains(t, names, "link.txt")}+func TestDeduplicatePaths(t *testing.T) {+ tests := []struct {+ name string+ input []string+ expected []string+ }{+ // ── core user scenario ────────────────────────────────────────────────+ {+ name: "user example: parent covers nested paths, underscore sibling survives",+ input: []string{+ "uploads/my_dir1/my_dir2/",+ "uploads/my_dir1/my_file1.txt",+ "uploads/my_dir1/my_dir2/my_file2.txt",+ "uploads/my_dir1_temp",+ "uploads/my_dir1",+ },+ // uploads/my_dir1 covers the first three; uploads/my_dir1_temp is independent+ expected: []string{"uploads/my_dir1_temp", "uploads/my_dir1"},+ },++ // ── exact deduplication ───────────────────────────────────────────────+ {+ name: "exact string duplicates keep first occurrence",+ input: []string{"uploads/file.txt", "uploads/file.txt", "uploads/file.txt"},+ expected: []string{"uploads/file.txt"},+ },+ {+ name: "trailing slash and no trailing slash are the same path",+ input: []string{"uploads/dir/", "uploads/dir"},+ expected: []string{"uploads/dir/"},+ },+ {+ name: "normalisation via .. collapses to same path as plain entry",+ input: []string{"uploads/my_dir1_temp/../my_dir1/", "uploads/my_dir1"},+ // both clean to "uploads/my_dir1"; original of first occurrence is returned+ expected: []string{"uploads/my_dir1_temp/../my_dir1/"},+ },++ // ── parent-covers-child ───────────────────────────────────────────────+ {+ name: "parent covers direct child file",+ input: []string{"uploads/dir/file.txt", "uploads/dir"},+ expected: []string{"uploads/dir"},+ },+ {+ name: "parent covers nested subdirectory",+ input: []string{"uploads/dir/sub/", "uploads/dir"},+ expected: []string{"uploads/dir"},+ },+ {+ name: "top-level covers deep nesting",+ input: []string{"uploads/a/b/c/d.txt", "uploads/a"},+ expected: []string{"uploads/a"},+ },+ {+ name: "all descendants collapsed to single ancestor",+ input: []string{"uploads/a/x.txt", "uploads/a/y.txt", "uploads/a/sub/z.txt", "uploads/a"},+ expected: []string{"uploads/a"},+ },+ {+ name: "ancestor given last still covers earlier entries",+ input: []string{"uploads/dir/file.txt", "uploads/dir/sub/", "uploads/dir"},+ expected: []string{"uploads/dir"},+ },+ {+ name: "intermediate node covers its subtree but is covered by root",+ input: []string{"uploads/a", "uploads/a/b", "uploads/a/b/c.txt"},+ expected: []string{"uploads/a"},+ },++ // ── no false positives ────────────────────────────────────────────────+ {+ name: "underscore suffix prevents false parent match",+ input: []string{"uploads/dir", "uploads/dir_extra"},+ expected: []string{"uploads/dir", "uploads/dir_extra"},+ },+ {+ name: "numeric suffix does not create false match",+ input: []string{"uploads/dir1", "uploads/dir"},+ expected: []string{"uploads/dir1", "uploads/dir"},+ },+ {+ name: "sibling directories both survive",+ input: []string{"uploads/a", "uploads/b"},+ expected: []string{"uploads/a", "uploads/b"},+ },+ {+ name: "independent flat files both survive",+ input: []string{"uploads/a.txt", "uploads/b.txt"},+ expected: []string{"uploads/a.txt", "uploads/b.txt"},+ },++ // ── order preservation ────────────────────────────────────────────────+ {+ name: "input order preserved when no path is covered",+ input: []string{"uploads/z.txt", "uploads/a.txt", "uploads/m.txt"},+ expected: []string{"uploads/z.txt", "uploads/a.txt", "uploads/m.txt"},+ },++ // ── multiple namespaces ───────────────────────────────────────────────+ {+ name: "uploads resources container do not interfere with each other",+ input: []string{"uploads/dir", "resources/dir", "container/dir"},+ expected: []string{"uploads/dir", "resources/dir", "container/dir"},+ },+ {+ name: "same relative name in different namespaces are independent",+ input: []string{"uploads/dir/file.txt", "container/dir"},+ expected: []string{"uploads/dir/file.txt", "container/dir"},+ },+ {+ name: "coverage is scoped within each namespace",+ input: []string{"uploads/dir/file.txt", "uploads/dir", "resources/dir/file.txt"},+ expected: []string{"uploads/dir", "resources/dir/file.txt"},+ },++ // ── original value preservation ───────────────────────────────────────+ {+ name: "original path with trailing slash returned when it survives",+ input: []string{"uploads/dir/", "resources/other.txt"},+ expected: []string{"uploads/dir/", "resources/other.txt"},+ },+ {+ name: "original dotdot path returned when it survives and is safe",+ input: []string{"uploads/tmp/../keep/"},+ // path.Clean → "uploads/keep"; not absolute, not leading ".." → safe; original returned+ expected: []string{"uploads/tmp/../keep/"},+ },++ // ── security: reject path traversal ──────────────────────────────────+ {+ name: "leading dotdot path rejected",+ input: []string{"../etc/passwd"},+ expected: nil,+ },+ {+ name: "absolute path rejected",+ input: []string{"/etc/passwd"},+ expected: nil,+ },+ {+ name: "path that cleans to dotdot escape rejected",+ input: []string{"uploads/../../etc/passwd"},+ // path.Clean → "../../etc/passwd" → starts with "../" → rejected+ expected: nil,+ },+ {+ name: "dotdot that fully escapes root rejected",+ input: []string{"../"},+ // path.Clean → ".." → equals ".." → rejected+ expected: nil,+ },+ {+ name: "mixed safe and unsafe: only safe paths returned",+ input: []string{"uploads/safe.txt", "../etc/passwd", "/etc/shadow", "uploads/../../evil"},+ expected: []string{"uploads/safe.txt"},+ },+ {+ name: "all unsafe inputs return nil",+ input: []string{"../a", "/b", "uploads/../../c"},+ expected: nil,+ },++ // ── edge cases ────────────────────────────────────────────────────────+ {+ name: "nil input returns nil",+ input: nil,+ expected: nil,+ },+ {+ name: "empty slice returns nil",+ input: []string{},+ expected: nil,+ },+ {+ name: "whitespace-only entries dropped",+ input: []string{"", " ", "\t", "uploads/file.txt"},+ expected: []string{"uploads/file.txt"},+ },+ {+ name: "single safe path returned unchanged",+ input: []string{"uploads/report.txt"},+ expected: []string{"uploads/report.txt"},+ },+ {+ name: "backslash normalised to slash for comparison, original returned",+ input: []string{`uploads\file.txt`},+ expected: []string{`uploads\file.txt`},+ },+ {+ name: "backslash and slash variants of same path are deduplicated",+ input: []string{`uploads\file.txt`, "uploads/file.txt"},+ // both clean to "uploads/file.txt"; first occurrence wins+ expected: []string{`uploads\file.txt`},+ },+ {+ name: "dot in middle is cleaned and deduped correctly",+ input: []string{"uploads/./file.txt", "uploads/file.txt"},+ expected: []string{"uploads/./file.txt"},+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ got := DeduplicatePaths(tt.input)+ assert.Equal(t, tt.expected, got)+ })+ }+}+func TestSort(t *testing.T) {now := time.Now()files := []File{- {Name: "b.txt", ModifiedAt: now.Add(-2 * time.Hour)},- {Name: "a.txt", ModifiedAt: now.Add(-1 * time.Hour)},- {Name: "c.txt", ModifiedAt: now.Add(-1 * time.Hour)},+ {Name: "b.txt", Path: "b.txt", ModifiedAt: now.Add(-2 * time.Hour)},+ {Name: "a.txt", Path: "a.txt", ModifiedAt: now.Add(-1 * time.Hour)},+ {Name: "c.txt", Path: "c.txt", ModifiedAt: now.Add(-1 * time.Hour)},}Sort(files)assert.Equal(t, "a.txt", files[0].Name)- assert.Equal(t, "c.txt", files[1].Name)- assert.Equal(t, "b.txt", files[2].Name)+ assert.Equal(t, "c.txt", files[2].Name)+ assert.Equal(t, "b.txt", files[1].Name)}diff --git a/backend/pkg/server/docs/docs.go b/backend/pkg/server/docs/docs.goindex daef6312..a3e87ccc 100644--- a/backend/pkg/server/docs/docs.go+++ b/backend/pkg/server/docs/docs.go@@ -2026,7 +2026,7 @@ const docTemplate = `{"tags": ["FlowFiles"],- "summary": "Delete flow file or directory by cached path",+ "summary": "Delete flow files or directories by cached paths","parameters": [{"minimum": 0,@@ -2038,15 +2038,24 @@ const docTemplate = `{},{"type": "string",- "description": "relative path in cache: uploads/, resources/, or container/",+ "description": "relative path in cache: uploads/, resources/, or container/ (may be combined with paths[])","name": "path",- "in": "query",- "required": true+ "in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "relative paths in cache (repeatable): uploads/, resources/, or container/",+ "name": "paths[]",+ "in": "query"}],"responses": {"200": {- "description": "flow file deleted successful",+ "description": "flow files deleted successfully","schema": {"allOf": [{@@ -2115,9 +2124,19 @@ const docTemplate = `{},{"type": "string",- "description": "absolute path inside the running container; defaults to /work",+ "description": "absolute path inside the running container; defaults to /work (may be combined with paths[])","name": "path","in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "absolute paths inside the running container (repeatable)",+ "name": "paths[]",+ "in": "query"}],"responses": {@@ -2173,6 +2192,7 @@ const docTemplate = `{"BearerAuth": []}],+ "description": "Single regular file: served as a direct attachment.\nSingle directory or multiple paths (any mix): packaged as a ZIP archive.","produces": ["application/octet-stream","application/zip",@@ -2181,7 +2201,7 @@ const docTemplate = `{"tags": ["FlowFiles"],- "summary": "Download flow file or directory by cached path",+ "summary": "Download flow file(s) or directory by cached path(s)","parameters": [{"minimum": 0,@@ -2193,15 +2213,24 @@ const docTemplate = `{},{"type": "string",- "description": "relative path in cache: uploads/, resources/, or container/",+ "description": "relative path in cache: uploads/, resources/, or container/ (may be combined with paths[])","name": "path",- "in": "query",- "required": true+ "in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "relative paths in cache (repeatable)",+ "name": "paths[]",+ "in": "query"}],"responses": {"200": {- "description": "file content, or ZIP archive for directories",+ "description": "file content, or ZIP archive for directories / multiple paths","schema": {"type": "file"}@@ -2249,7 +2278,7 @@ const docTemplate = `{"tags": ["FlowFiles"],- "summary": "Pull a file or directory from the running container into the local cache",+ "summary": "Pull files or directories from the running container into the local cache","parameters": [{"minimum": 0,@@ -2260,7 +2289,7 @@ const docTemplate = `{"required": true},{- "description": "pull request",+ "description": "pull request: path or paths are required","name": "request","in": "body","required": true,@@ -2271,7 +2300,7 @@ const docTemplate = `{],"responses": {"200": {- "description": "container path synced to local cache",+ "description": "container paths synced to local cache, sorted by cache path","schema": {"allOf": [{@@ -4695,10 +4724,20 @@ const docTemplate = `{"parameters": [{"type": "string",- "description": "virtual directory path; empty for root",+ "description": "virtual directory path; empty for root (may be combined with paths[])","name": "path","in": "query"},+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "additional virtual directory paths (repeatable)",+ "name": "paths[]",+ "in": "query"+ },{"type": "boolean","description": "list recursively (default false)",@@ -4837,10 +4876,19 @@ const docTemplate = `{"parameters": [{"type": "string",- "description": "virtual path to delete",+ "description": "virtual path to delete (may be combined with paths[])","name": "path",- "in": "query",- "required": true+ "in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "additional virtual paths to delete (repeatable)",+ "name": "paths[]",+ "in": "query"}],"responses": {@@ -4977,24 +5025,35 @@ const docTemplate = `{}],"produces": [- "application/octet-stream"+ "application/octet-stream",+ "application/zip",+ "application/json"],"tags": ["Resources"],- "summary": "Download a resource",+ "summary": "Download a resource or resources","parameters": [{"type": "string",- "description": "virtual path to download",+ "description": "virtual path to download (may be combined with paths[])","name": "path",- "in": "query",- "required": true+ "in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "additional virtual paths to download (repeatable)",+ "name": "paths[]",+ "in": "query"}],"responses": {"200": {- "description": "file content, or ZIP archive for directories",+ "description": "file content, or ZIP archive for directories / multiple paths","schema": {"type": "file"}@@ -8056,12 +8115,19 @@ const docTemplate = `{"type": "object","properties": {"force": {- "description": "Force overwrites the local cache entry if it already exists.",+ "description": "Force overwrites local cache entries that already exist.","type": "boolean"},"path": {- "description": "Path is an arbitrary path inside the container, e.g. \"/etc/nginx/conf\" or \"/work/uploads/report.txt\".",+ "description": "Path is a single container path (maintained for backward compatibility).\nCombined with Paths if both are provided.","type": "string"+ },+ "paths": {+ "description": "Paths is a list of container paths to pull. Combined with Path if provided.",+ "type": "array",+ "items": {+ "type": "string"+ }}}},diff --git a/backend/pkg/server/docs/swagger.json b/backend/pkg/server/docs/swagger.jsonindex 3df9f1a8..3114fb74 100644--- a/backend/pkg/server/docs/swagger.json+++ b/backend/pkg/server/docs/swagger.json@@ -2018,7 +2018,7 @@"tags": ["FlowFiles"],- "summary": "Delete flow file or directory by cached path",+ "summary": "Delete flow files or directories by cached paths","parameters": [{"minimum": 0,@@ -2030,15 +2030,24 @@},{"type": "string",- "description": "relative path in cache: uploads/, resources/, or container/",+ "description": "relative path in cache: uploads/, resources/, or container/ (may be combined with paths[])","name": "path",- "in": "query",- "required": true+ "in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "relative paths in cache (repeatable): uploads/, resources/, or container/",+ "name": "paths[]",+ "in": "query"}],"responses": {"200": {- "description": "flow file deleted successful",+ "description": "flow files deleted successfully","schema": {"allOf": [{@@ -2107,9 +2116,19 @@},{"type": "string",- "description": "absolute path inside the running container; defaults to /work",+ "description": "absolute path inside the running container; defaults to /work (may be combined with paths[])","name": "path","in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "absolute paths inside the running container (repeatable)",+ "name": "paths[]",+ "in": "query"}],"responses": {@@ -2165,6 +2184,7 @@"BearerAuth": []}],+ "description": "Single regular file: served as a direct attachment.\nSingle directory or multiple paths (any mix): packaged as a ZIP archive.","produces": ["application/octet-stream","application/zip",@@ -2173,7 +2193,7 @@"tags": ["FlowFiles"],- "summary": "Download flow file or directory by cached path",+ "summary": "Download flow file(s) or directory by cached path(s)","parameters": [{"minimum": 0,@@ -2185,15 +2205,24 @@},{"type": "string",- "description": "relative path in cache: uploads/, resources/, or container/",+ "description": "relative path in cache: uploads/, resources/, or container/ (may be combined with paths[])","name": "path",- "in": "query",- "required": true+ "in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "relative paths in cache (repeatable)",+ "name": "paths[]",+ "in": "query"}],"responses": {"200": {- "description": "file content, or ZIP archive for directories",+ "description": "file content, or ZIP archive for directories / multiple paths","schema": {"type": "file"}@@ -2241,7 +2270,7 @@"tags": ["FlowFiles"],- "summary": "Pull a file or directory from the running container into the local cache",+ "summary": "Pull files or directories from the running container into the local cache","parameters": [{"minimum": 0,@@ -2252,7 +2281,7 @@"required": true},{- "description": "pull request",+ "description": "pull request: path or paths are required","name": "request","in": "body","required": true,@@ -2263,7 +2292,7 @@],"responses": {"200": {- "description": "container path synced to local cache",+ "description": "container paths synced to local cache, sorted by cache path","schema": {"allOf": [{@@ -4687,10 +4716,20 @@"parameters": [{"type": "string",- "description": "virtual directory path; empty for root",+ "description": "virtual directory path; empty for root (may be combined with paths[])","name": "path","in": "query"},+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "additional virtual directory paths (repeatable)",+ "name": "paths[]",+ "in": "query"+ },{"type": "boolean","description": "list recursively (default false)",@@ -4829,10 +4868,19 @@"parameters": [{"type": "string",- "description": "virtual path to delete",+ "description": "virtual path to delete (may be combined with paths[])","name": "path",- "in": "query",- "required": true+ "in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "additional virtual paths to delete (repeatable)",+ "name": "paths[]",+ "in": "query"}],"responses": {@@ -4969,24 +5017,35 @@}],"produces": [- "application/octet-stream"+ "application/octet-stream",+ "application/zip",+ "application/json"],"tags": ["Resources"],- "summary": "Download a resource",+ "summary": "Download a resource or resources","parameters": [{"type": "string",- "description": "virtual path to download",+ "description": "virtual path to download (may be combined with paths[])","name": "path",- "in": "query",- "required": true+ "in": "query"+ },+ {+ "type": "array",+ "items": {+ "type": "string"+ },+ "collectionFormat": "multi",+ "description": "additional virtual paths to download (repeatable)",+ "name": "paths[]",+ "in": "query"}],"responses": {"200": {- "description": "file content, or ZIP archive for directories",+ "description": "file content, or ZIP archive for directories / multiple paths","schema": {"type": "file"}@@ -8048,12 +8107,19 @@"type": "object","properties": {"force": {- "description": "Force overwrites the local cache entry if it already exists.",+ "description": "Force overwrites local cache entries that already exist.","type": "boolean"},"path": {- "description": "Path is an arbitrary path inside the container, e.g. \"/etc/nginx/conf\" or \"/work/uploads/report.txt\".",+ "description": "Path is a single container path (maintained for backward compatibility).\nCombined with Paths if both are provided.","type": "string"+ },+ "paths": {+ "description": "Paths is a list of container paths to pull. Combined with Path if provided.",+ "type": "array",+ "items": {+ "type": "string"+ }}}},diff --git a/backend/pkg/server/docs/swagger.yaml b/backend/pkg/server/docs/swagger.yamlindex 4cbc737c..ddbcf48a 100644--- a/backend/pkg/server/docs/swagger.yaml+++ b/backend/pkg/server/docs/swagger.yaml@@ -985,12 +985,19 @@ definitions:models.PullFlowFilesRequest:properties:force:- description: Force overwrites the local cache entry if it already exists.+ description: Force overwrites local cache entries that already exist.type: booleanpath:- description: Path is an arbitrary path inside the container, e.g. "/etc/nginx/conf"- or "/work/uploads/report.txt".+ description: |-+ Path is a single container path (maintained for backward compatibility).+ Combined with Paths if both are provided.type: string+ paths:+ description: Paths is a list of container paths to pull. Combined with Path+ if provided.+ items:+ type: string+ type: arraytype: objectmodels.ResourceEntry:properties:@@ -2976,16 +2983,24 @@ paths:name: flowIDrequired: truetype: integer- - description: 'relative path in cache: uploads/, resources/, or container/'+ - description: 'relative path in cache: uploads/, resources/, or container/+ (may be combined with paths[])'in: queryname: path- required: truetype: string+ - collectionFormat: multi+ description: 'relative paths in cache (repeatable): uploads/, resources/,+ or container/'+ in: query+ items:+ type: string+ name: paths[]+ type: arrayproduces:- application/jsonresponses:"200":- description: flow file deleted successful+ description: flow files deleted successfullyschema:allOf:- $ref: '#/definitions/SuccessResponse'@@ -3011,7 +3026,7 @@ paths:$ref: '#/definitions/ErrorResponse'security:- BearerAuth: []- summary: Delete flow file or directory by cached path+ summary: Delete flow files or directories by cached pathstags:- FlowFilesget:@@ -3117,9 +3132,17 @@ paths:required: truetype: integer- description: absolute path inside the running container; defaults to /work+ (may be combined with paths[])in: queryname: pathtype: string+ - collectionFormat: multi+ description: absolute paths inside the running container (repeatable)+ in: query+ items:+ type: string+ name: paths[]+ type: arrayproduces:- application/jsonresponses:@@ -3155,6 +3178,9 @@ paths:- FlowFiles/flows/{flowID}/files/download:get:+ description: |-+ Single regular file: served as a direct attachment.+ Single directory or multiple paths (any mix): packaged as a ZIP archive.parameters:- description: flow idin: path@@ -3162,18 +3188,25 @@ paths:name: flowIDrequired: truetype: integer- - description: 'relative path in cache: uploads/, resources/, or container/'+ - description: 'relative path in cache: uploads/, resources/, or container/+ (may be combined with paths[])'in: queryname: path- required: truetype: string+ - collectionFormat: multi+ description: relative paths in cache (repeatable)+ in: query+ items:+ type: string+ name: paths[]+ type: arrayproduces:- application/octet-stream- application/zip- application/jsonresponses:"200":- description: file content, or ZIP archive for directories+ description: file content, or ZIP archive for directories / multiple pathsschema:type: file"400":@@ -3194,7 +3227,7 @@ paths:$ref: '#/definitions/ErrorResponse'security:- BearerAuth: []- summary: Download flow file or directory by cached path+ summary: Download flow file(s) or directory by cached path(s)tags:- FlowFiles/flows/{flowID}/files/pull:@@ -3208,7 +3241,7 @@ paths:name: flowIDrequired: truetype: integer- - description: pull request+ - description: 'pull request: path or paths are required'in: bodyname: requestrequired: true@@ -3218,7 +3251,7 @@ paths:- application/jsonresponses:"200":- description: container path synced to local cache+ description: container paths synced to local cache, sorted by cache pathschema:allOf:- $ref: '#/definitions/SuccessResponse'@@ -3248,7 +3281,7 @@ paths:$ref: '#/definitions/ErrorResponse'security:- BearerAuth: []- summary: Pull a file or directory from the running container into the local+ summary: Pull files or directories from the running container into the localcachetags:- FlowFiles@@ -4840,11 +4873,17 @@ paths:/resources/:delete:parameters:- - description: virtual path to delete+ - description: virtual path to delete (may be combined with paths[])in: queryname: path- required: truetype: string+ - collectionFormat: multi+ description: additional virtual paths to delete (repeatable)+ in: query+ items:+ type: string+ name: paths[]+ type: arrayproduces:- application/jsonresponses:@@ -4880,10 +4919,18 @@ paths:- Resourcesget:parameters:- - description: virtual directory path; empty for root+ - description: virtual directory path; empty for root (may be combined with+ paths[])in: queryname: pathtype: string+ - collectionFormat: multi+ description: additional virtual directory paths (repeatable)+ in: query+ items:+ type: string+ name: paths[]+ type: array- description: list recursively (default false)in: queryname: recursive@@ -5014,16 +5061,24 @@ paths:/resources/download:get:parameters:- - description: virtual path to download+ - description: virtual path to download (may be combined with paths[])in: queryname: path- required: truetype: string+ - collectionFormat: multi+ description: additional virtual paths to download (repeatable)+ in: query+ items:+ type: string+ name: paths[]+ type: arrayproduces:- application/octet-stream+ - application/zip+ - application/jsonresponses:"200":- description: file content, or ZIP archive for directories+ description: file content, or ZIP archive for directories / multiple pathsschema:type: file"400":@@ -5044,7 +5099,7 @@ paths:$ref: '#/definitions/ErrorResponse'security:- BearerAuth: []- summary: Download a resource+ summary: Download a resource or resourcestags:- Resources/resources/mkdir:diff --git a/backend/pkg/server/models/flow_files.go b/backend/pkg/server/models/flow_files.goindex 8b9398ca..fb63baca 100644--- a/backend/pkg/server/models/flow_files.go+++ b/backend/pkg/server/models/flow_files.go@@ -37,9 +37,12 @@ type ContainerFiles struct {// PullFlowFilesRequest is the request body for pulling files from a container.type PullFlowFilesRequest struct {- // Path is an arbitrary path inside the container, e.g. "/etc/nginx/conf" or "/work/uploads/report.txt".+ // Path is a single container path (maintained for backward compatibility).+ // Combined with Paths if both are provided.Path string `json:"path"`- // Force overwrites the local cache entry if it already exists.+ // Paths is a list of container paths to pull. Combined with Path if provided.+ Paths []string `json:"paths"`+ // Force overwrites local cache entries that already exist.Force bool `json:"force"`}diff --git a/backend/pkg/server/services/flow_files.go b/backend/pkg/server/services/flow_files.goindex 07f4528e..3efe8f33 100644--- a/backend/pkg/server/services/flow_files.go+++ b/backend/pkg/server/services/flow_files.go@@ -1,6 +1,7 @@package servicesimport (+ "bytes""context""errors""fmt"@@ -300,14 +301,17 @@ func (s *FlowFileService) UploadFlowFiles(c *gin.Context) {})}-// DeleteFlowFile is a function to delete a cached flow file or directory by path-// @Summary Delete flow file or directory by cached path+// DeleteFlowFile is a function to delete one or more cached flow files or directories by path.+// Accepts a single "path" query parameter and/or repeated "paths[]" parameters; both may be+// combined and duplicates (after path normalization) are silently ignored.+// @Summary Delete flow files or directories by cached paths// @Tags FlowFiles// @Produce json// @Security BearerAuth// @Param flowID path int true "flow id" minimum(0)-// @Param path query string true "relative path in cache: uploads/, resources/, or container/"-// @Success 200 {object} response.successResp{data=models.FlowFiles} "flow file deleted successful"+// @Param path query string false "relative path in cache: uploads/, resources/, or container/ (may be combined with paths[])"+// @Param paths[] query []string false "relative paths in cache (repeatable): uploads/, resources/, or container/"+// @Success 200 {object} response.successResp{data=models.FlowFiles} "flow files deleted successfully"// @Failure 400 {object} response.errorResp "invalid flow file request data"// @Failure 403 {object} response.errorResp "deleting flow file not permitted"// @Failure 404 {object} response.errorResp "flow file not found"@@ -327,52 +331,118 @@ func (s *FlowFileService) DeleteFlowFile(c *gin.Context) {return}- localPath, err := s.resolveCachedPath(flowID, c.Query("path"))- if err != nil {- logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("invalid delete path")+ // Collect paths from both "path" and "paths[]" query params, then deduplicate strings.+ rawPaths := c.QueryArray("paths[]")+ if singlePath := c.Query("path"); singlePath != "" {+ rawPaths = append(rawPaths, singlePath)+ }+ reqPaths := flowfiles.DeduplicatePaths(rawPaths)+ if len(reqPaths) == 0 {+ err = errors.New("at least one path is required (use 'path' or 'paths[]' query parameters)")+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("missing delete paths")response.Error(c, response.ErrFlowFilesInvalidRequest, err)return}- info, err := os.Lstat(localPath)- if err != nil {- if errors.Is(err, os.ErrNotExist) {- response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", c.Query("path")))- } else {- logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error reading cached flow file")- response.Error(c, response.ErrInternal, err)+ // Resolve and validate every path before performing any deletion; deduplicate+ // by resolved local path to handle path-equivalent inputs (e.g. "uploads/./x" == "uploads/x").+ type resolvedEntry struct {+ reqPath string+ localPath string+ info os.FileInfo+ }+ seenLocal := make(map[string]struct{}, len(reqPaths))+ entries := make([]resolvedEntry, 0, len(reqPaths))+ for _, reqPath := range reqPaths {+ localPath, err := s.resolveCachedPath(flowID, reqPath)+ if err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("invalid delete path")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return}- return+ if _, dup := seenLocal[localPath]; dup {+ continue+ }+ seenLocal[localPath] = struct{}{}++ info, err := os.Lstat(localPath)+ if err != nil {+ if errors.Is(err, os.ErrNotExist) {+ response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", reqPath))+ } else {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error reading cached flow file")+ response.Error(c, response.ErrInternal, err)+ }+ return+ }+ entries = append(entries, resolvedEntry{+ reqPath: reqPath,+ localPath: localPath,+ info: info,+ })}- deletedFile := convertFlowFile(flowfiles.NewFileWithPath(info, filepath.ToSlash(c.Query("path"))))- if err := s.deleteUploadFromContainer(c.Request.Context(), flowID, c.Query("path")); err != nil {- logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error deleting file from primary container")- response.Error(c, response.ErrInternal, err)- return+ // Expand each entry to collect the full set of files and directories that will+ // actually disappear from the cache. For directories we walk recursively so+ // that every removed sub-entry is reported to the caller and published via+ // subscription — giving the client a precise picture of what was deleted.+ // The actual deletion below still operates on the minimal deduplicated set.+ expandedFiles := make([]flowfiles.File, 0, len(entries))+ for _, e := range entries {+ relPath := filepath.ToSlash(e.reqPath)+ expandedFiles = append(expandedFiles, flowfiles.NewFileWithPath(e.info, relPath))+ if e.info.IsDir() {+ nested, nestErr := flowfiles.ListDirEntriesRecursive(e.localPath, relPath)+ if nestErr != nil {+ logger.FromContext(c).WithError(nestErr).WithFields(map[string]any{+ "flow_id": flowID,+ "path": relPath,+ }).Warn("could not expand directory contents before deletion; reporting top-level entry only")+ }+ expandedFiles = append(expandedFiles, nested...)+ }}+ flowfiles.Sort(expandedFiles)+ deletedFiles := convertFlowFiles(expandedFiles)- if err := os.RemoveAll(localPath); err != nil {- logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error deleting cached flow file")+ // One Docker exec removes all relevant container paths in a single API call.+ allReqPaths := make([]string, 0, len(entries))+ for _, e := range entries {+ allReqPaths = append(allReqPaths, e.reqPath)+ }+ if err := s.deleteUploadsFromContainer(c.Request.Context(), flowID, allReqPaths); err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error deleting files from primary container")response.Error(c, response.ErrInternal, err)return}- s.publishFlowFileDeleted(c.Request.Context(), flow, deletedFile)+ // Remove local cache entries after the container sync succeeded.+ for _, e := range entries {+ if err := os.RemoveAll(e.localPath); err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error deleting cached flow file")+ response.Error(c, response.ErrInternal, err)+ return+ }+ }++ s.publishFlowFilesDeleted(c.Request.Context(), flow, deletedFiles)response.Success(c, http.StatusOK, models.FlowFiles{- Files: nil,- Total: 0,+ Files: deletedFiles,+ Total: uint64(len(deletedFiles)),})}-// DownloadFlowFile is a function to download a flow file or directory (as ZIP) by cached path-// @Summary Download flow file or directory by cached path+// DownloadFlowFile is a function to download flow file(s) or directory by cached path(s)+// @Summary Download flow file(s) or directory by cached path(s)+// @Description Single regular file: served as a direct attachment.+// @Description Single directory or multiple paths (any mix): packaged as a ZIP archive.// @Tags FlowFiles-// @Produce octet-stream,application/zip,json+// @Produce application/octet-stream,application/zip,json// @Security BearerAuth// @Param flowID path int true "flow id" minimum(0)-// @Param path query string true "relative path in cache: uploads/, resources/, or container/"-// @Success 200 {file} binary "file content, or ZIP archive for directories"+// @Param path query string false "relative path in cache: uploads/, resources/, or container/ (may be combined with paths[])"+// @Param paths[] query []string false "relative paths in cache (repeatable)"+// @Success 200 {file} binary "file content, or ZIP archive for directories / multiple paths"// @Failure 400 {object} response.errorResp "invalid flow file request data"// @Failure 403 {object} response.errorResp "downloading flow file not permitted"// @Failure 404 {object} response.errorResp "flow file not found"@@ -391,59 +461,140 @@ func (s *FlowFileService) DownloadFlowFile(c *gin.Context) {return}- localPath, err := s.resolveCachedPath(flowID, c.Query("path"))- if err != nil {- logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("invalid download path")+ // Collect paths from both "path" and "paths[]" query params, then deduplicate.+ rawPaths := c.QueryArray("paths[]")+ if singlePath := c.Query("path"); singlePath != "" {+ rawPaths = append(rawPaths, singlePath)+ }+ reqPaths := flowfiles.DeduplicatePaths(rawPaths)+ if len(reqPaths) == 0 {+ err = errors.New("at least one path is required (use 'path' or 'paths[]' query parameters)")+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("missing download paths")response.Error(c, response.ErrFlowFilesInvalidRequest, err)return}- info, err := os.Lstat(localPath)- if err != nil {- if errors.Is(err, os.ErrNotExist) {- response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", c.Query("path")))- } else {- logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error reading cached flow file")- response.Error(c, response.ErrInternal, err)+ // Resolve and validate every path; deduplicate by resolved local path.+ type resolvedEntry struct {+ reqPath string+ localPath string+ info os.FileInfo+ }+ seenLocal := make(map[string]struct{}, len(reqPaths))+ entries := make([]resolvedEntry, 0, len(reqPaths))+ for _, reqPath := range reqPaths {+ localPath, err := s.resolveCachedPath(flowID, reqPath)+ if err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("invalid download path")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }+ if _, dup := seenLocal[localPath]; dup {+ continue+ }+ seenLocal[localPath] = struct{}{}++ info, err := os.Lstat(localPath)+ if err != nil {+ if errors.Is(err, os.ErrNotExist) {+ response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", reqPath))+ } else {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error reading cached flow file")+ response.Error(c, response.ErrInternal, err)+ }+ return+ }+ // Never serve symlinks — could point outside the flow data directory.+ if info.Mode()&os.ModeSymlink != 0 {+ response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", reqPath))+ return+ }+ if !info.IsDir() && !info.Mode().IsRegular() {+ response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", reqPath))+ return}+ entries = append(entries, resolvedEntry{reqPath: reqPath, localPath: localPath, info: info})+ }++ if len(entries) == 0 {+ response.Error(c, response.ErrFlowFilesNotFound, errors.New("no accessible paths found"))return}- // Never serve symlinks — could point outside the flow data directory.- if info.Mode()&os.ModeSymlink != 0 {- response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", c.Query("path")))+ // Single regular file → serve as a direct attachment.+ // We open the file explicitly and use DataFromReader with a known Content-Length+ // so that Gin's response writer emits a proper Content-Length header instead of+ // relying on http.ServeFile, which conflicts with Gin's middleware-set headers+ // and can produce content-length: 0 in certain request contexts.+ if len(entries) == 1 && entries[0].info.Mode().IsRegular() {+ e := entries[0]+ f, err := os.Open(e.localPath)+ if err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error opening flow file for download")+ response.Error(c, response.ErrInternal, err)+ return+ }+ defer f.Close()++ contentType := "application/octet-stream"+ c.DataFromReader(http.StatusOK, e.info.Size(), contentType, f,+ map[string]string{+ "Content-Disposition": mime.FormatMediaType("attachment", map[string]string{+ "filename": filepath.Base(e.localPath),+ }),+ })return}- if info.IsDir() {- name := filepath.Base(localPath)- c.Header("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{- "filename": name + ".zip",- }))- c.Header("Content-Type", "application/zip")- if err := flowfiles.ZipDirectory(c.Writer, localPath); err != nil {+ // Single directory → ZIP with paths relative to that directory (backward-compat).+ // The archive is buffered so an explicit Content-Length can be set; this allows+ // clients (including Swagger UI) to recognise and download the file correctly.+ if len(entries) == 1 && entries[0].info.IsDir() {+ name := filepath.Base(entries[0].localPath)+ var buf bytes.Buffer+ if err := flowfiles.ZipDirectory(&buf, entries[0].localPath); err != nil {logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error creating ZIP archive")+ response.Error(c, response.ErrInternal, err)+ return}+ c.DataFromReader(http.StatusOK, int64(buf.Len()), "application/zip", &buf,+ map[string]string{+ "Content-Disposition": mime.FormatMediaType("attachment", map[string]string{+ "filename": name + ".zip",+ }),+ })return}- if !info.Mode().IsRegular() {- response.Error(c, response.ErrFlowFilesNotFound, fmt.Errorf("'%s' not found in local cache", c.Query("path")))+ // Multiple paths (any mix of files and directories) → ZIP with cache-relative paths.+ // Buffered for the same reason as above.+ relPaths := make([]string, 0, len(entries))+ for _, e := range entries {+ relPaths = append(relPaths, filepath.ToSlash(e.reqPath))+ }+ var buf bytes.Buffer+ if err := flowfiles.ZipRelativePaths(&buf, s.flowDataDir(flowID), relPaths); err != nil {+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error creating ZIP archive")+ response.Error(c, response.ErrInternal, err)return}-- c.FileAttachment(localPath, filepath.Base(localPath))+ c.DataFromReader(http.StatusOK, int64(buf.Len()), "application/zip", &buf,+ map[string]string{+ "Content-Disposition": mime.FormatMediaType("attachment", map[string]string{+ "filename": "download.zip",+ }),+ })}-// PullFlowFiles is a function to sync a path from the container into the local cache-// @Summary Pull a file or directory from the running container into the local cache+// PullFlowFiles is a function to sync one or more paths from the container into the local cache+// @Summary Pull files or directories from the running container into the local cache// @Tags FlowFiles// @Accept json// @Produce json// @Security BearerAuth// @Param flowID path int true "flow id" minimum(0)-// @Param request body models.PullFlowFilesRequest true "pull request"-// @Success 200 {object} response.successResp{data=models.FlowFiles} "container path synced to local cache"+// @Param request body models.PullFlowFilesRequest true "pull request: path or paths are required"+// @Success 200 {object} response.successResp{data=models.FlowFiles} "container paths synced to local cache, sorted by cache path"// @Failure 400 {object} response.errorResp "invalid pull request or container not running"// @Failure 403 {object} response.errorResp "pulling flow files not permitted"// @Failure 404 {object} response.errorResp "flow not found"@@ -478,47 +629,94 @@ func (s *FlowFileService) PullFlowFiles(c *gin.Context) {return}- containerPath := strings.TrimSpace(req.Path)- if containerPath == "" {- err = errors.New("path is required")- logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("missing container path in pull request")+ // Collect container paths from both req.Path and req.Paths, then deduplicate+ // with coverage semantics using flowfiles.DeduplicatePaths.+ // Container paths (/etc/nginx.conf) are normalised to their relative form+ // (etc/nginx.conf) so that DeduplicatePaths can apply ancestor coverage:+ // /etc/ covers /etc/nginx.conf → only /etc/ is pulled.+ rawPaths := req.Paths+ if strings.TrimSpace(req.Path) != "" {+ rawPaths = append(rawPaths, req.Path)+ }+ relPaths := make([]string, 0, len(rawPaths))+ for _, p := range rawPaths {+ trimmed := strings.TrimSpace(p)+ if trimmed == "" {+ continue+ }+ // Mirror SanitizeContainerCachePath normalisation: prepend "/", Clean, strip "/".+ rel := strings.TrimPrefix(path.Clean("/"+strings.ReplaceAll(trimmed, "\\", "/")), "/")+ if rel != "" && rel != "." {+ relPaths = append(relPaths, rel)+ }+ }+ dedupedRel := flowfiles.DeduplicatePaths(relPaths)+ if len(dedupedRel) == 0 {+ err = errors.New("at least one valid path is required (use 'path' or 'paths' fields)")+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("missing container paths in pull request")response.Error(c, response.ErrFlowFilesInvalidRequest, err)return}-- // Preserve the normalized container path under the local container cache:- // /etc/nginx/conf/ → container/etc/nginx/conf/- // /etc/nginx/nginx.conf → container/etc/nginx/nginx.conf- cacheRelPath, err := flowfiles.SanitizeContainerCachePath(containerPath)- if err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "container_path": containerPath,- }).Error("invalid container path")- response.Error(c, response.ErrFlowFilesInvalidRequest, fmt.Errorf("invalid container path: %w", err))- return+ // Reconstruct absolute paths for the Docker API.+ containerPaths := make([]string, len(dedupedRel))+ for i, rel := range dedupedRel {+ containerPaths[i] = "/" + rel}containerDir := s.flowContainerDir(flowID)- localTarget := filepath.Join(containerDir, filepath.FromSlash(cacheRelPath))- targetExists := false-- // Check for existing cache entry; honour force flag.- if _, statErr := os.Lstat(localTarget); statErr == nil {- targetExists = true- if !req.Force {- err = fmt.Errorf("'%s' already exists in the container cache; set force=true to overwrite", cacheRelPath)++ // ── Phase 1: validate every path and check for cache conflicts ────────────+ // All validation is done upfront so that no docker operations are started+ // if any path is invalid or already cached without force=true.+ type pullEntry struct {+ containerPath string+ cacheRelPath string+ localTarget string+ targetExists bool+ }+ seenCachePaths := make(map[string]struct{}, len(containerPaths))+ entries := make([]pullEntry, 0, len(containerPaths))+ for _, containerPath := range containerPaths {+ cacheRelPath, err := flowfiles.SanitizeContainerCachePath(containerPath)+ if err != nil {logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "cache_path": cacheRelPath,- }).Error("pull target already exists")- response.Error(c, response.ErrFlowFilesAlreadyExists, err)+ "flow_id": flowID,+ "container_path": containerPath,+ }).Error("invalid container path")+ response.Error(c, response.ErrFlowFilesInvalidRequest, fmt.Errorf("invalid container path %q: %w", containerPath, err))return}- } else if !errors.Is(statErr, os.ErrNotExist) {- logger.FromContext(c).WithError(statErr).WithField("flow_id", flowID).Error("error checking container cache entry")- response.Error(c, response.ErrInternal, statErr)- return++ // Deduplicate by resolved cache path (handles /etc/foo and etc/foo being equivalent).+ if _, dup := seenCachePaths[cacheRelPath]; dup {+ continue+ }+ seenCachePaths[cacheRelPath] = struct{}{}++ localTarget := filepath.Join(containerDir, filepath.FromSlash(cacheRelPath))+ targetExists := false+ if _, statErr := os.Lstat(localTarget); statErr == nil {+ targetExists = true+ if !req.Force {+ err = fmt.Errorf("'%s' already exists in the container cache; set force=true to overwrite", cacheRelPath)+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": cacheRelPath,+ }).Error("pull target already exists")+ response.Error(c, response.ErrFlowFilesAlreadyExists, err)+ return+ }+ } else if !errors.Is(statErr, os.ErrNotExist) {+ logger.FromContext(c).WithError(statErr).WithField("flow_id", flowID).Error("error checking container cache entry")+ response.Error(c, response.ErrInternal, statErr)+ return+ }+ entries = append(entries, pullEntry{+ containerPath: containerPath,+ cacheRelPath: cacheRelPath,+ localTarget: localTarget,+ targetExists: targetExists,+ })}if err := os.MkdirAll(containerDir, 0755); err != nil {@@ -551,96 +749,153 @@ func (s *FlowFileService) PullFlowFiles(c *gin.Context) {return}- reader, _, err := s.dockerClient.CopyFromContainer(c.Request.Context(), containerName, containerPath)- if err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "container_path": containerPath,- }).Error("error copying from container")- response.Error(c, response.ErrInternal, err)- return- }- defer reader.Close()+ // ── Phase 2: pull each validated entry from the container ─────────────────+ syncedFiles := make([]models.FlowFile, 0, len(entries))+ addedFiles := make([]models.FlowFile, 0, len(entries))+ updatedFiles := make([]models.FlowFile, 0)- stagingDir, err := os.MkdirTemp(containerDir, ".pull-*")- if err != nil {- logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error creating pull staging directory")- response.Error(c, response.ErrInternal, err)- return- }- defer os.RemoveAll(stagingDir)+ for _, entry := range entries {+ reader, _, err := s.dockerClient.CopyFromContainer(c.Request.Context(), containerName, entry.containerPath)+ if err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "container_path": entry.containerPath,+ }).Error("error copying from container")+ response.Error(c, response.ErrInternal, err)+ return+ }- if err := flowfiles.ExtractTar(reader, stagingDir); err != nil {- logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error extracting container TAR archive")- response.Error(c, response.ErrInternal, err)- return- }+ stagingDir, err := os.MkdirTemp(containerDir, ".pull-*")+ if err != nil {+ reader.Close()+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("error creating pull staging directory")+ response.Error(c, response.ErrInternal, err)+ return+ }- stagedTarget := flowfiles.ResolvePulledStagedTarget(stagingDir, cacheRelPath)- if stagedTarget == "" {- err = fmt.Errorf("pulled archive did not contain expected entry '%s'", cacheRelPath)- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "cache_path": cacheRelPath,- }).Error("pulled container archive did not contain expected entry")- response.Error(c, response.ErrInternal, err)- return- }- if _, err := os.Lstat(stagedTarget); err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "cache_path": cacheRelPath,- }).Error("pulled container archive did not contain expected entry")- response.Error(c, response.ErrInternal, err)- return- }+ extractErr := flowfiles.ExtractTar(reader, stagingDir)+ reader.Close()+ if extractErr != nil {+ os.RemoveAll(stagingDir)+ logger.FromContext(c).WithError(extractErr).WithField("flow_id", flowID).Error("error extracting container TAR archive")+ response.Error(c, response.ErrInternal, extractErr)+ return+ }- if req.Force {- if err := os.RemoveAll(localTarget); err != nil {+ stagedTarget := flowfiles.ResolvePulledStagedTarget(stagingDir, entry.cacheRelPath)+ if stagedTarget == "" {+ os.RemoveAll(stagingDir)+ err = fmt.Errorf("pulled archive did not contain expected entry '%s'", entry.cacheRelPath)logger.FromContext(c).WithError(err).WithFields(map[string]any{"flow_id": flowID,- "cache_path": cacheRelPath,- }).Error("error removing existing cache entry before forced pull")+ "cache_path": entry.cacheRelPath,+ }).Error("pulled container archive did not contain expected entry")response.Error(c, response.ErrInternal, err)return}- }- if err := os.MkdirAll(filepath.Dir(localTarget), 0755); err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "cache_path": cacheRelPath,- }).Error("error creating container cache parent directory")- response.Error(c, response.ErrInternal, err)- return- }- if err := os.Rename(stagedTarget, localTarget); err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "cache_path": cacheRelPath,- }).Error("error committing pulled container entry")- response.Error(c, response.ErrInternal, err)- return- }+ if _, statErr := os.Lstat(stagedTarget); statErr != nil {+ os.RemoveAll(stagingDir)+ logger.FromContext(c).WithError(statErr).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": entry.cacheRelPath,+ }).Error("pulled container archive did not contain expected entry")+ response.Error(c, response.ErrInternal, statErr)+ return+ }- info, err := os.Lstat(localTarget)- if err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "cache_path": cacheRelPath,- }).Error("error stating synced container entry")- response.Error(c, response.ErrInternal, err)- return+ if entry.targetExists {+ if err := os.RemoveAll(entry.localTarget); err != nil {+ os.RemoveAll(stagingDir)+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": entry.cacheRelPath,+ }).Error("error removing existing cache entry before forced pull")+ response.Error(c, response.ErrInternal, err)+ return+ }+ }+ if err := os.MkdirAll(filepath.Dir(entry.localTarget), 0755); err != nil {+ os.RemoveAll(stagingDir)+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": entry.cacheRelPath,+ }).Error("error creating container cache parent directory")+ response.Error(c, response.ErrInternal, err)+ return+ }+ if err := os.Rename(stagedTarget, entry.localTarget); err != nil {+ os.RemoveAll(stagingDir)+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": entry.cacheRelPath,+ }).Error("error committing pulled container entry")+ response.Error(c, response.ErrInternal, err)+ return+ }+ os.RemoveAll(stagingDir)++ info, err := os.Lstat(entry.localTarget)+ if err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "cache_path": entry.cacheRelPath,+ }).Error("error stating synced container entry")+ response.Error(c, response.ErrInternal, err)+ return+ }++ // Build the full list of synced entries: root entry + recursive contents for+ // directories. Mirrors the expansion done in DeleteFlowFile so the caller gets+ // a complete picture of what was actually written to the cache.+ relPath := path.Join(flowfiles.ContainerDirName, entry.cacheRelPath)+ rootFile := convertFlowFile(flowfiles.NewFileWithPath(info, relPath))+ expanded := []models.FlowFile{rootFile}+ if info.IsDir() {+ nested, nestErr := flowfiles.ListDirEntriesRecursive(entry.localTarget, relPath)+ if nestErr != nil {+ logger.FromContext(c).WithError(nestErr).WithFields(map[string]any{+ "flow_id": flowID,+ "path": relPath,+ }).Warn("could not list pulled directory contents for response")+ } else {+ for _, f := range nested {+ expanded = append(expanded, convertFlowFile(f))+ }+ }+ }+ syncedFiles = append(syncedFiles, expanded...)+ if entry.targetExists {+ updatedFiles = append(updatedFiles, expanded...)+ } else {+ addedFiles = append(addedFiles, expanded...)+ }}- synced := convertFlowFile(flowfiles.NewFileWithPath(info, path.Join(flowfiles.ContainerDirName, cacheRelPath)))- if targetExists {- s.publishFlowFileUpdated(c.Request.Context(), flow, synced)- } else {- s.publishFlowFilesAdded(c.Request.Context(), flow, []models.FlowFile{synced})+ // Sort results by cache path for deterministic output.+ sort.Slice(syncedFiles, func(i, j int) bool {+ if syncedFiles[i].Path < syncedFiles[j].Path {+ return true+ } else if syncedFiles[i].Path > syncedFiles[j].Path {+ return false+ } else if syncedFiles[i].Name < syncedFiles[j].Name {+ return true+ } else if syncedFiles[i].Name > syncedFiles[j].Name {+ return false+ }+ return syncedFiles[i].ModifiedAt.After(syncedFiles[j].ModifiedAt)+ })++ ctx := c.Request.Context()+ if len(addedFiles) > 0 {+ s.publishFlowFilesAdded(ctx, flow, addedFiles)+ }+ for _, f := range updatedFiles {+ s.publishFlowFileUpdated(ctx, flow, f)}+response.Success(c, http.StatusOK, models.FlowFiles{- Files: []models.FlowFile{synced},- Total: 1,+ Files: syncedFiles,+ Total: uint64(len(syncedFiles)),})}@@ -650,7 +905,8 @@ func (s *FlowFileService) PullFlowFiles(c *gin.Context) {// @Produce json// @Security BearerAuth// @Param flowID path int true "flow id" minimum(0)-// @Param path query string false "absolute path inside the running container; defaults to /work"+// @Param path query string false "absolute path inside the running container; defaults to /work (may be combined with paths[])"+// @Param paths[] query []string false "absolute paths inside the running container (repeatable)"// @Success 200 {object} response.successResp{data=models.ContainerFiles} "container files list received successful"// @Failure 400 {object} response.errorResp "invalid flow files request data or container not running"// @Failure 403 {object} response.errorResp "getting flow container files not permitted"@@ -684,9 +940,22 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {return}- containerPath := strings.TrimSpace(c.Query("path"))- if containerPath == "" {- containerPath = docker.WorkFolderPathInContainer+ // Collect paths from both "path" and "paths[]" query params, deduplicate by+ // exact string. If explicit paths are provided but all are whitespace-only,+ // return an error. When nothing is provided at all, default to /work.+ rawPaths := c.QueryArray("paths[]")+ if singlePath := strings.TrimSpace(c.Query("path")); singlePath != "" {+ rawPaths = append(rawPaths, singlePath)+ }+ containerPaths := deduplicateContainerPaths(rawPaths)+ if len(rawPaths) > 0 && len(containerPaths) == 0 {+ err = errors.New("at least one valid path is required (use 'path' or 'paths[]' query parameters)")+ logger.FromContext(c).WithError(err).WithField("flow_id", flowID).Error("missing container paths")+ response.Error(c, response.ErrFlowFilesInvalidRequest, err)+ return+ }+ if len(containerPaths) == 0 {+ containerPaths = []string{docker.WorkFolderPathInContainer}}containerName := primaryContainerName(flowID)@@ -706,40 +975,74 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {return}- pathStat, err := s.dockerClient.ContainerStatPath(c.Request.Context(), containerName, containerPath)- if err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "container_path": containerPath,- }).Error("error stating container path")- response.Error(c, response.ErrInternal, err)- return- }- if !pathStat.Mode.IsDir() {- file := convertContainerFile(path.Dir(containerPath), pathStat)- response.Success(c, http.StatusOK, models.ContainerFiles{- Path: containerPath,- Files: []models.ContainerFile{file},- Total: 1,- })- return+ // Query each path and collect results. Output is deduplicated by the+ // resolved file.Path so that overlapping queries never return the same+ // entry twice.+ seenPaths := make(map[string]struct{})+ allFiles := make([]models.ContainerFile, 0)+ for _, containerPath := range containerPaths {+ pathStat, err := s.dockerClient.ContainerStatPath(c.Request.Context(), containerName, containerPath)+ if err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "container_path": containerPath,+ }).Error("error stating container path")+ response.Error(c, response.ErrInternal, err)+ return+ }++ if !pathStat.Mode.IsDir() {+ file := convertContainerFile(path.Dir(containerPath), pathStat)+ if _, seen := seenPaths[file.Path]; !seen {+ seenPaths[file.Path] = struct{}{}+ allFiles = append(allFiles, file)+ }+ continue+ }++ stats, err := s.dockerClient.ListContainerDir(c.Request.Context(), containerName, containerPath)+ if err != nil {+ logger.FromContext(c).WithError(err).WithFields(map[string]any{+ "flow_id": flowID,+ "container_path": containerPath,+ }).Error("error listing container directory")+ response.Error(c, response.ErrInternal, err)+ return+ }+ for _, stat := range stats {+ file := convertContainerFile(containerPath, stat)+ if _, seen := seenPaths[file.Path]; !seen {+ seenPaths[file.Path] = struct{}{}+ allFiles = append(allFiles, file)+ }+ }}- stats, err := s.dockerClient.ListContainerDir(c.Request.Context(), containerName, containerPath)- if err != nil {- logger.FromContext(c).WithError(err).WithFields(map[string]any{- "flow_id": flowID,- "container_path": containerPath,- }).Error("error listing container directory")- response.Error(c, response.ErrInternal, err)- return+ // Sort by name for deterministic output across all paths.+ sort.Slice(allFiles, func(i, j int) bool {+ if allFiles[i].Path < allFiles[j].Path {+ return true+ } else if allFiles[i].Path > allFiles[j].Path {+ return false+ } else if allFiles[i].Name < allFiles[j].Name {+ return true+ } else if allFiles[i].Name > allFiles[j].Name {+ return false+ }+ return allFiles[i].ModifiedAt.Before(allFiles[j].ModifiedAt)+ })++ // Backward-compat: when exactly one container path was queried, echo it back+ // as Path so existing callers receive the same field value as before.+ responsePath := ""+ if len(containerPaths) == 1 {+ responsePath = containerPaths[0]}- files := convertContainerFiles(containerPath, stats)response.Success(c, http.StatusOK, models.ContainerFiles{- Path: containerPath,- Files: files,- Total: uint64(len(files)),+ Path: responsePath,+ Files: allFiles,+ Total: uint64(len(allFiles)),})}@@ -875,17 +1178,27 @@ func (s *FlowFileService) pushResourcePathsToContainer(c *gin.Context, flowID ui}}-// deleteUploadFromContainer removes cache paths that mirror the primary container's-// /work tree: uploads/... and resources/... Container mirror paths (container/...) stay-// host-only and are not removed inside the running container.-func (s *FlowFileService) deleteUploadFromContainer(ctx context.Context, flowID uint64, reqPath string) error {- if s.dockerClient == nil {+// deleteUploadsFromContainer removes cache paths that mirror the primary container's+// /work tree (uploads/... and resources/...) in a single Docker exec call.+// Container mirror paths (container/...) stay host-only and are not touched inside+// the running container. When Docker is unavailable or the container is not running,+// the function returns nil — the cache divergence will be resolved on next container start.+func (s *FlowFileService) deleteUploadsFromContainer(ctx context.Context, flowID uint64, reqPaths []string) error {+ if s.dockerClient == nil || len(reqPaths) == 0 {return nil}- cleaned := filepath.Clean(filepath.FromSlash(strings.ReplaceAll(reqPath, "\\", "/")))- parts := strings.SplitN(cleaned, string(filepath.Separator), 2)- if len(parts) == 0 || (parts[0] != flowfiles.UploadsDirName && parts[0] != flowfiles.ResourcesDirName) {+ // Collect container-side paths for entries that mirror into /work (uploads/ and resources/ only).+ containerPaths := make([]string, 0, len(reqPaths))+ for _, reqPath := range reqPaths {+ cleaned := filepath.Clean(filepath.FromSlash(strings.ReplaceAll(reqPath, "\\", "/")))+ parts := strings.SplitN(cleaned, string(filepath.Separator), 2)+ if len(parts) == 0 || (parts[0] != flowfiles.UploadsDirName && parts[0] != flowfiles.ResourcesDirName) {+ continue+ }+ containerPaths = append(containerPaths, path.Join(docker.WorkFolderPathInContainer, filepath.ToSlash(cleaned)))+ }+ if len(containerPaths) == 0 {return nil}@@ -898,9 +1211,15 @@ func (s *FlowFileService) deleteUploadFromContainer(ctx context.Context, flowIDreturn nil}- containerPath := path.Join(docker.WorkFolderPathInContainer, filepath.ToSlash(cleaned))+ // Build a single rm -rf command for all paths to minimise Docker API round-trips.+ quotedPaths := make([]string, len(containerPaths))+ for i, p := range containerPaths {+ quotedPaths[i] = shellQuote(p)+ }+ cmd := "rm -rf -- " + strings.Join(quotedPaths, " ")+createResp, err := s.dockerClient.ContainerExecCreate(ctx, containerName, container.ExecOptions{- Cmd: []string{"sh", "-c", fmt.Sprintf("rm -rf -- %s", shellQuote(containerPath))},+ Cmd: []string{"sh", "-c", cmd},AttachStdout: true,AttachStderr: true,})@@ -933,6 +1252,28 @@ func shellQuote(value string) string {return "'" + strings.ReplaceAll(value, "'", "'\"'\"'") + "'"}+// deduplicateContainerPaths returns a slice of trimmed, non-empty, unique+// container path strings, preserving first-occurrence order. Unlike+// flowfiles.DeduplicatePaths it applies no path.Clean or safety checks —+// those semantics are specific to host-side cache paths, not container-internal+// absolute paths.+func deduplicateContainerPaths(paths []string) []string {+ seen := make(map[string]struct{}, len(paths))+ result := make([]string, 0, len(paths))+ for _, p := range paths {+ trimmed := strings.TrimSpace(p)+ if trimmed == "" {+ continue+ }+ if _, dup := seen[trimmed]; dup {+ continue+ }+ seen[trimmed] = struct{}{}+ result = append(result, trimmed)+ }+ return result+}+func flowScopeForFiles(privs []string,uid uint64,@@ -1048,13 +1389,15 @@ func (s *FlowFileService) publishFlowFileUpdated(ctx context.Context, flow modelpublisher.FlowFileUpdated(ctx, convertModelFlowFile(file))}-func (s *FlowFileService) publishFlowFileDeleted(ctx context.Context, flow models.Flow, file models.FlowFile) {+func (s *FlowFileService) publishFlowFilesDeleted(ctx context.Context, flow models.Flow, files []models.FlowFile) {if s.ss == nil {return}publisher := s.ss.NewFlowPublisher(int64(flow.UserID), int64(flow.ID))- publisher.FlowFileDeleted(ctx, convertModelFlowFile(file))+ for _, file := range files {+ publisher.FlowFileDeleted(ctx, convertModelFlowFile(file))+ }}func sortFlowFiles(files []models.FlowFile) {diff --git a/backend/pkg/server/services/flow_files_test.go b/backend/pkg/server/services/flow_files_test.goindex 60084738..02d1c924 100644--- a/backend/pkg/server/services/flow_files_test.go+++ b/backend/pkg/server/services/flow_files_test.go@@ -946,18 +946,28 @@ type fakeDockerClient struct {running boolrunningErr error- // ContainerStatPath behaviour.+ // ContainerStatPath behaviour (single-path fallback).statPath container.PathStatstatPathErr error- // ListContainerDir behaviour.+ // ListContainerDir behaviour (single-path fallback).listDir []container.PathStatlistDirErr error+ // Per-path overrides for multi-path tests; take precedence over the+ // single-value fields above when the queried path has an entry here.+ statPathMap map[string]container.PathStat+ statPathErrMap map[string]error+ listDirMap map[string][]container.PathStat+ listDirErrMap map[string]error+// CopyFromContainer behaviour.- copyFromBody []byte- copyFromStat container.PathStat- copyFromErr error+ copyFromBody []byte+ copyFromStat container.PathStat+ copyFromErr error+ copyFromBodyMap map[string][]byte // per-path override; takes precedence over copyFromBody+ copyFromErrMap map[string]error // per-path override; takes precedence over copyFromErr+ copyFromCount int // total number of CopyFromContainer calls// CopyToContainer behaviour.copyToErr error@@ -1014,10 +1024,30 @@ func (f *fakeDockerClient) ContainerExecInspect(_ context.Context, _ string) (co}return container.ExecInspect{ExitCode: f.execInspectCode}, nil}-func (f *fakeDockerClient) ContainerStatPath(_ context.Context, _ string, _ string) (container.PathStat, error) {+func (f *fakeDockerClient) ContainerStatPath(_ context.Context, _ string, p string) (container.PathStat, error) {+ if f.statPathErrMap != nil {+ if err, ok := f.statPathErrMap[p]; ok {+ return container.PathStat{}, err+ }+ }+ if f.statPathMap != nil {+ if stat, ok := f.statPathMap[p]; ok {+ return stat, nil+ }+ }return f.statPath, f.statPathErr}-func (f *fakeDockerClient) ListContainerDir(_ context.Context, _ string, _ string) ([]container.PathStat, error) {+func (f *fakeDockerClient) ListContainerDir(_ context.Context, _ string, p string) ([]container.PathStat, error) {+ if f.listDirErrMap != nil {+ if err, ok := f.listDirErrMap[p]; ok {+ return nil, err+ }+ }+ if f.listDirMap != nil {+ if dir, ok := f.listDirMap[p]; ok {+ return dir, nil+ }+ }return f.listDir, f.listDirErr}func (f *fakeDockerClient) CopyToContainer(_ context.Context, containerID string, dstPath string, content io.Reader, options container.CopyToContainerOptions) error {@@ -1032,10 +1062,24 @@ func (f *fakeDockerClient) CopyToContainer(_ context.Context, containerID stringf.mu.Unlock()return f.copyToErr}-func (f *fakeDockerClient) CopyFromContainer(_ context.Context, _ string, _ string) (io.ReadCloser, container.PathStat, error) {+func (f *fakeDockerClient) CopyFromContainer(_ context.Context, _ string, containerPath string) (io.ReadCloser, container.PathStat, error) {+ f.mu.Lock()+ f.copyFromCount+++ f.mu.Unlock()++ if f.copyFromErrMap != nil {+ if err, ok := f.copyFromErrMap[containerPath]; ok {+ return nil, container.PathStat{}, err+ }+ }if f.copyFromErr != nil {return nil, container.PathStat{}, f.copyFromErr}+ if f.copyFromBodyMap != nil {+ if body, ok := f.copyFromBodyMap[containerPath]; ok {+ return io.NopCloser(bytes.NewReader(body)), f.copyFromStat, nil+ }+ }return io.NopCloser(bytes.NewReader(f.copyFromBody)), f.copyFromStat, nil}func (f *fakeDockerClient) Cleanup(_ context.Context) error { return nil }@@ -1613,13 +1657,23 @@ func TestFlowFileService_DeleteFlowFileScenarios(t *testing.T) {privs []stringseedFlow boolseedFiles []seedFile- queryPath string+ queryPath string // builds ?path=<value>; empty = no path param+ rawQuery string // when non-empty, used verbatim as query string (overrides queryPath)dockerRunning bool+ execCreateErr error // simulate ContainerExecCreate failure+ execInspectCode int // simulate non-zero exec exit code (must have dockerRunning:true)wantStatus int- wantDeletedPath string- wantRemainingFile string- wantContainerExec bool+ wantDeletedPath string // single path expected in "deleted" subscription events+ wantDeletedPaths []string // additional paths expected in "deleted" events (for bulk tests)+ wantFilesGone []string // relative paths inside flow data dir that must be absent+ wantFilesExist []string // relative paths that must still exist (fail-safe atomicity)+ wantContainerExec bool // assert at least one exec with "rm -rf"+ wantNoExec bool // assert zero exec calls+ wantSingleExec bool // assert exactly one exec call+ wantExecContains string // exec command must contain this substring+ wantResponseTotal int // > 0: verify response Total and Files length}{+ // ── single-path via ?path= (existing behaviour) ───────────────────────{name: "delete uploaded file",flowOwner: 1,@@ -1633,22 +1687,21 @@ func TestFlowFileService_DeleteFlowFileScenarios(t *testing.T) {wantDeletedPath: "uploads/report.txt",},{- name: "delete container directory recursively",- flowOwner: 1,- uid: 1,- flowID: 1,- privs: []string{"flow_files.upload"},- seedFlow: true,- seedFiles: []seedFile{{relPath: "container/etc", isDir: true}, {relPath: "container/etc/nginx.conf", content: "n"}},+ name: "delete container directory recursively",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "container/etc", isDir: true},+ {relPath: "container/etc/nginx.conf", content: "n"},+ },queryPath: "container/etc",wantStatus: http.StatusOK,wantDeletedPath: "container/etc",},{- name: "delete resources file",- flowOwner: 1,- uid: 1,- flowID: 1,+ name: "delete resources file",+ flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.upload"},seedFlow: true,seedFiles: []seedFile{{relPath: "resources/creds/p.txt", content: "p"}},@@ -1657,10 +1710,8 @@ func TestFlowFileService_DeleteFlowFileScenarios(t *testing.T) {wantDeletedPath: "resources/creds/p.txt",},{- name: "delete uploads file invokes container exec when running",- flowOwner: 1,- uid: 1,- flowID: 1,+ name: "delete uploads file invokes container exec when running",+ flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.upload"},seedFlow: true,seedFiles: []seedFile{{relPath: "uploads/report.txt", content: "r"}},@@ -1670,11 +1721,11 @@ func TestFlowFileService_DeleteFlowFileScenarios(t *testing.T) {wantDeletedPath: "uploads/report.txt",wantContainerExec: true,},++ // ── single-path: access control ──────────────────────────────────────{- name: "view privilege cannot delete",- flowOwner: 1,- uid: 1,- flowID: 1,+ name: "view privilege cannot delete",+ flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view"},seedFlow: true,queryPath: "uploads/report.txt",@@ -1688,46 +1739,313 @@ func TestFlowFileService_DeleteFlowFileScenarios(t *testing.T) {queryPath: "uploads/report.txt",wantStatus: http.StatusNotFound,},++ // ── single-path: invalid input ────────────────────────────────────────{- name: "missing path returns bad request",- flowOwner: 1,- uid: 1,- flowID: 1,+ name: "missing path returns bad request",+ flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.upload"},seedFlow: true,queryPath: "",wantStatus: http.StatusBadRequest,},{- name: "wrong-prefix path returns bad request",- flowOwner: 1,- uid: 1,- flowID: 1,+ name: "wrong-prefix path returns bad request",+ flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.upload"},seedFlow: true,queryPath: "tmp/x.txt",wantStatus: http.StatusBadRequest,},{- name: "path traversal returns bad request",- flowOwner: 1,- uid: 1,- flowID: 1,+ name: "path traversal returns bad request",+ flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.upload"},seedFlow: true,queryPath: "uploads/../../etc/passwd",wantStatus: http.StatusBadRequest,},{- name: "non-existent file returns not found",- flowOwner: 1,- uid: 1,- flowID: 1,+ name: "non-existent file returns not found",+ flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.upload"},seedFlow: true,queryPath: "uploads/missing.txt",wantStatus: http.StatusNotFound,},++ // ── paths[] parameter ─────────────────────────────────────────────────++ {+ // Verifies the paths[] param works independently without the singular path= param.+ name: "only paths[] param used deletes single file",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{{relPath: "uploads/report.txt", content: "r"}},+ rawQuery: "paths[]=uploads/report.txt",+ wantStatus: http.StatusOK,+ wantDeletedPath: "uploads/report.txt",+ wantFilesGone: []string{"uploads/report.txt"},+ },+ {+ // Both uploads/a.txt and uploads/b.txt are deleted in one request.+ name: "batch delete two uploads files via paths[]",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "uploads/a.txt", content: "a"},+ {relPath: "uploads/b.txt", content: "b"},+ },+ rawQuery: "paths[]=uploads/a.txt&paths[]=uploads/b.txt",+ wantStatus: http.StatusOK,+ wantDeletedPaths: []string{"uploads/a.txt", "uploads/b.txt"},+ wantFilesGone: []string{"uploads/a.txt", "uploads/b.txt"},+ wantResponseTotal: 2,+ },+ {+ // path= and paths[]= are combined; both files are deleted.+ name: "path and paths[] combined delete two files",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "uploads/a.txt", content: "a"},+ {relPath: "uploads/b.txt", content: "b"},+ },+ rawQuery: "path=uploads/a.txt&paths[]=uploads/b.txt",+ wantStatus: http.StatusOK,+ wantDeletedPaths: []string{"uploads/a.txt", "uploads/b.txt"},+ wantFilesGone: []string{"uploads/a.txt", "uploads/b.txt"},+ wantResponseTotal: 2,+ },+ {+ // Same path sent twice in paths[]; must be treated as a single deletion.+ name: "duplicate paths[] entries deduplicated",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{{relPath: "uploads/report.txt", content: "r"}},+ rawQuery: "paths[]=uploads/report.txt&paths[]=uploads/report.txt",+ wantStatus: http.StatusOK,+ wantDeletedPath: "uploads/report.txt",+ wantFilesGone: []string{"uploads/report.txt"},+ wantResponseTotal: 1,+ },+ {+ // uploads/dir covers uploads/dir/file.txt; DeduplicatePaths reduces the+ // list to just uploads/dir. The file disappears as part of recursive removal.+ // After directory expansion the response and subscription must report BOTH+ // the directory entry and its nested file.+ name: "paths[] parent covers child - child not separately processed",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "uploads/dir", isDir: true},+ {relPath: "uploads/dir/file.txt", content: "x"},+ },+ rawQuery: "paths[]=uploads/dir&paths[]=uploads/dir/file.txt",+ wantStatus: http.StatusOK,+ wantDeletedPath: "uploads/dir",+ wantDeletedPaths: []string{"uploads/dir/file.txt"},+ wantFilesGone: []string{"uploads/dir", "uploads/dir/file.txt"},+ wantResponseTotal: 2, // dir entry + nested file+ },++ {+ // Deletes a directory that contains nested sub-directories and files.+ // The response and subscription must enumerate every removed entry,+ // not just the top-level directory handle.+ name: "directory deletion reports all nested files and dirs in response",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "resources/folder", isDir: true},+ {relPath: "resources/folder/scope.md", content: "scope"},+ {relPath: "resources/folder/sub", isDir: true},+ {relPath: "resources/folder/sub/detail.txt", content: "detail"},+ },+ queryPath: "resources/folder",+ wantStatus: http.StatusOK,+ wantDeletedPath: "resources/folder",+ wantDeletedPaths: []string{+ "resources/folder/scope.md",+ "resources/folder/sub",+ "resources/folder/sub/detail.txt",+ },+ wantFilesGone: []string{"resources/folder"},+ wantResponseTotal: 4, // dir + 1 file + sub-dir + 1 nested file+ },+ {+ // Verifies the response contains file metadata for every deleted entry.+ name: "response contains metadata for all deleted files",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "uploads/a.txt", content: "a"},+ {relPath: "resources/creds/p.txt", content: "p"},+ },+ rawQuery: "paths[]=uploads/a.txt&paths[]=resources/creds/p.txt",+ wantStatus: http.StatusOK,+ wantDeletedPaths: []string{"uploads/a.txt", "resources/creds/p.txt"},+ wantResponseTotal: 2,+ },++ // ── Docker exec: batch optimisation ──────────────────────────────────+ {+ // Two uploads paths must result in exactly one Docker exec call.+ name: "single Docker exec issued for two uploads paths",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "uploads/a.txt", content: "a"},+ {relPath: "uploads/b.txt", content: "b"},+ },+ rawQuery: "paths[]=uploads/a.txt&paths[]=uploads/b.txt",+ dockerRunning: true,+ wantStatus: http.StatusOK,+ wantDeletedPaths: []string{"uploads/a.txt", "uploads/b.txt"},+ wantSingleExec: true,+ wantExecContains: "rm -rf",+ },+ {+ // container/ paths are host-only and must never be sent to the container.+ name: "container path does not trigger Docker exec",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "container/etc", isDir: true},+ {relPath: "container/etc/nginx.conf", content: "n"},+ },+ rawQuery: "paths[]=container/etc",+ dockerRunning: true,+ wantStatus: http.StatusOK,+ wantDeletedPath: "container/etc",+ wantNoExec: true,+ },+ {+ // resources/ paths are mirrored in the container; exec must be triggered.+ name: "resources path triggers Docker exec",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{{relPath: "resources/creds/p.txt", content: "p"}},+ rawQuery: "paths[]=resources/creds/p.txt",+ dockerRunning: true,+ wantStatus: http.StatusOK,+ wantDeletedPath: "resources/creds/p.txt",+ wantContainerExec: true,+ },+ {+ // Mixed uploads + container + resources: single exec, containing only the+ // two mirrored paths (/work/uploads/... and /work/resources/...); the+ // container path is excluded from the exec command.+ name: "mixed namespaces produce single exec with only mirrored paths",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "uploads/a.txt", content: "a"},+ {relPath: "container/etc", isDir: true},+ {relPath: "container/etc/nginx.conf", content: "n"},+ {relPath: "resources/creds/p.txt", content: "p"},+ },+ rawQuery: "paths[]=uploads/a.txt&paths[]=container/etc&paths[]=resources/creds/p.txt",+ dockerRunning: true,+ wantStatus: http.StatusOK,+ wantDeletedPaths: []string{"uploads/a.txt", "container/etc", "resources/creds/p.txt"},+ wantFilesGone: []string{"uploads/a.txt", "container/etc", "resources/creds/p.txt"},+ wantSingleExec: true,+ wantExecContains: "/work/uploads/a.txt",+ },++ // ── access control ────────────────────────────────────────────────────+ {+ // flow_files.admin bypasses the uid ownership filter.+ name: "admin can delete from other user flow",+ flowOwner: 2, uid: 1, flowID: 1,+ privs: []string{"flow_files.admin"},+ seedFlow: true,+ seedFiles: []seedFile{{relPath: "uploads/report.txt", content: "r"}},+ queryPath: "uploads/report.txt",+ wantStatus: http.StatusOK,+ wantDeletedPath: "uploads/report.txt",+ },++ // ── input validation: batch edge cases ───────────────────────────────+ {+ // All paths[] values consist of whitespace only; after trimming none remain.+ name: "all whitespace paths[] values return bad request",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ rawQuery: "paths[]=%20%20%20&paths[]=%09",+ wantStatus: http.StatusBadRequest,+ },+ {+ // First path is valid; second has an unsupported prefix.+ // Validation is fail-fast: the first file must NOT be deleted.+ name: "invalid prefix in second paths[] fails atomically",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "uploads/a.txt", content: "a"},+ },+ rawQuery: "paths[]=uploads/a.txt&paths[]=tmp/evil.txt",+ wantStatus: http.StatusBadRequest,+ wantFilesExist: []string{"uploads/a.txt"},+ },+ {+ // First path exists; second path does not.+ // Validation is fail-fast: the first file must NOT be deleted.+ name: "missing file in second paths[] fails atomically",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{+ {relPath: "uploads/a.txt", content: "a"},+ },+ rawQuery: "paths[]=uploads/a.txt&paths[]=uploads/missing.txt",+ wantStatus: http.StatusNotFound,+ wantFilesExist: []string{"uploads/a.txt"},+ },++ // ── Docker error handling ─────────────────────────────────────────────+ {+ // ContainerExecCreate fails; the handler must return 500 and must NOT+ // delete the local cache entry (container and cache would diverge otherwise).+ name: "exec create failure returns 500 and preserves local file",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{{relPath: "uploads/report.txt", content: "r"}},+ queryPath: "uploads/report.txt",+ dockerRunning: true,+ execCreateErr: fmt.Errorf("docker daemon unreachable"),+ wantStatus: http.StatusInternalServerError,+ wantFilesExist: []string{"uploads/report.txt"},+ },+ {+ // rm exits with a non-zero code; the handler must return 500 and must NOT+ // delete the local cache entry.+ name: "exec non-zero exit code returns 500 and preserves local file",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload"},+ seedFlow: true,+ seedFiles: []seedFile{{relPath: "uploads/report.txt", content: "r"}},+ queryPath: "uploads/report.txt",+ dockerRunning: true,+ execInspectCode: 1,+ wantStatus: http.StatusInternalServerError,+ wantFilesExist: []string{"uploads/report.txt"},+ },}for _, tt := range tests {@@ -1735,7 +2053,11 @@ func TestFlowFileService_DeleteFlowFileScenarios(t *testing.T) {db := setupFlowFileServiceTestDB(t)dataDir := t.TempDir()ss := &flowFileCaptureSubscriptions{}- fakeDocker := &fakeDockerClient{running: tt.dockerRunning}+ fakeDocker := &fakeDockerClient{+ running: tt.dockerRunning,+ execCreateErr: tt.execCreateErr,+ execInspectCode: tt.execInspectCode,+ }svc := NewFlowFileService(db, dataDir, fakeDocker, ss)if tt.seedFlow {@@ -1755,8 +2077,12 @@ func TestFlowFileService_DeleteFlowFileScenarios(t *testing.T) {require.NoError(t, os.WriteFile(abs, []byte(f.content), 0644))}+ // Build request URL.target := "/flows/1/files/"- if tt.queryPath != "" {+ switch {+ case tt.rawQuery != "":+ target += "?" + tt.rawQuery+ case tt.queryPath != "":target += "?path=" + tt.queryPath}c, w := newFlowFileTestContext(http.MethodDelete, target, nil, tt.privs, tt.uid, tt.flowID)@@ -1764,24 +2090,68 @@ func TestFlowFileService_DeleteFlowFileScenarios(t *testing.T) {svc.DeleteFlowFile(c)require.Equal(t, tt.wantStatus, w.Code)++ // ── success assertions ────────────────────────────────────────────if tt.wantStatus == http.StatusOK {- abs := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", tt.flowID), filepath.FromSlash(tt.queryPath))- _, err := os.Lstat(abs)- assert.True(t, os.IsNotExist(err), "deleted file/dir must be gone from cache")+ // Existing: check queryPath is gone (single-path tests).+ if tt.queryPath != "" {+ abs := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", tt.flowID), filepath.FromSlash(tt.queryPath))+ _, err := os.Lstat(abs)+ assert.True(t, os.IsNotExist(err), "deleted file/dir must be gone from cache: %s", tt.queryPath)+ }+ // New: check every explicitly listed gone path.+ for _, gone := range tt.wantFilesGone {+ abs := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", tt.flowID), filepath.FromSlash(gone))+ _, err := os.Lstat(abs)+ assert.True(t, os.IsNotExist(err), "expected %q to be gone from cache", gone)+ }- deleted := []string{}+ // Subscription events.+ deleted := make([]string, 0)for _, ev := range ss.snapshot() {if ev.channel == "flow" && ev.action == "deleted" {deleted = append(deleted, ev.path)}}- assert.Contains(t, deleted, tt.wantDeletedPath)+ if tt.wantDeletedPath != "" {+ assert.Contains(t, deleted, tt.wantDeletedPath)+ }+ for _, p := range tt.wantDeletedPaths {+ assert.Contains(t, deleted, p, "expected deleted event for %q", p)+ }+ // Response body total.+ if tt.wantResponseTotal > 0 {+ resp := decodeFlowFilesResponse(t, w)+ assert.Equal(t, uint64(tt.wantResponseTotal), resp.Total, "response Total mismatch")+ assert.Len(t, resp.Files, tt.wantResponseTotal, "response Files length mismatch")+ }++ // Existing Docker exec check.if tt.wantContainerExec {assert.NotEmpty(t, fakeDocker.execCommands, "expected docker exec to be invoked")assert.Contains(t, fakeDocker.execCommands[0], "rm -rf")}}++ // ── exec count assertions (checked regardless of status) ──────────+ if tt.wantNoExec {+ assert.Empty(t, fakeDocker.execCommands, "expected no docker exec call")+ }+ if tt.wantSingleExec {+ assert.Len(t, fakeDocker.execCommands, 1, "expected exactly one docker exec call")+ }+ if tt.wantExecContains != "" {+ require.NotEmpty(t, fakeDocker.execCommands, "exec must have been called to check its content")+ assert.Contains(t, fakeDocker.execCommands[0], tt.wantExecContains)+ }++ // ── atomicity / fail-safe: files that must still exist ────────────+ for _, exists := range tt.wantFilesExist {+ abs := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", tt.flowID), filepath.FromSlash(exists))+ _, err := os.Lstat(abs)+ assert.NoError(t, err, "expected %q to still exist on disk (atomicity guarantee)", exists)+ }})}}@@ -1797,25 +2167,25 @@ func TestFlowFileService_DownloadFlowFileScenarios(t *testing.T) {uid uint64flowID uint64privs []string- queryPath string- setupFile func(t *testing.T, dataDir string, flowID uint64) string+ queryPath string // builds ?path=<value>+ rawQuery string // when set, used verbatim as query string (overrides queryPath)+ setupFile func(t *testing.T, dataDir string, flowID uint64)wantStatus intwantBody stringwantContentType stringwantDispContains stringwantZipEntries map[string]string}{+ // ── single-path: existing behaviour (backward compatibility) ──────────{name: "download regular uploaded file",flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view"},queryPath: "uploads/report.txt",- setupFile: func(t *testing.T, dataDir string, flowID uint64) string {+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "uploads")require.NoError(t, os.MkdirAll(dir, 0755))- p := filepath.Join(dir, "report.txt")- require.NoError(t, os.WriteFile(p, []byte("payload"), 0644))- return p+ require.NoError(t, os.WriteFile(filepath.Join(dir, "report.txt"), []byte("payload"), 0644))},wantStatus: http.StatusOK,wantBody: "payload",@@ -1826,32 +2196,32 @@ func TestFlowFileService_DownloadFlowFileScenarios(t *testing.T) {flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view"},queryPath: "container/etc",- setupFile: func(t *testing.T, dataDir string, flowID uint64) string {+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "container", "etc")require.NoError(t, os.MkdirAll(filepath.Join(dir, "nginx"), 0755))require.NoError(t, os.WriteFile(filepath.Join(dir, "nginx", "nginx.conf"), []byte("nginx"), 0644))- return dir},wantStatus: http.StatusOK,wantContentType: "application/zip",wantDispContains: "etc.zip",- wantZipEntries: map[string]string{"nginx/nginx.conf": "nginx"},+ // Single dir → ZipDirectory → paths relative to dir root.+ wantZipEntries: map[string]string{"nginx/nginx.conf": "nginx"},},{name: "admin downloads other user's file",flowOwner: 2, uid: 1, flowID: 1,privs: []string{"flow_files.admin"},queryPath: "uploads/report.txt",- setupFile: func(t *testing.T, dataDir string, flowID uint64) string {+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "uploads")require.NoError(t, os.MkdirAll(dir, 0755))- p := filepath.Join(dir, "report.txt")- require.NoError(t, os.WriteFile(p, []byte("admin"), 0644))- return p+ require.NoError(t, os.WriteFile(filepath.Join(dir, "report.txt"), []byte("admin"), 0644))},wantStatus: http.StatusOK,wantBody: "admin",},++ // ── access control ────────────────────────────────────────────────────{name: "non-admin cannot download other user's file",flowOwner: 2, uid: 1, flowID: 1,@@ -1866,6 +2236,8 @@ func TestFlowFileService_DownloadFlowFileScenarios(t *testing.T) {queryPath: "uploads/report.txt",wantStatus: http.StatusForbidden,},++ // ── single-path: invalid input ────────────────────────────────────────{name: "empty path returns bad request",flowOwner: 1, uid: 1, flowID: 1,@@ -1885,7 +2257,7 @@ func TestFlowFileService_DownloadFlowFileScenarios(t *testing.T) {flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view"},queryPath: "uploads/link.txt",- setupFile: func(t *testing.T, dataDir string, flowID uint64) string {+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "uploads")require.NoError(t, os.MkdirAll(dir, 0755))target := filepath.Join(dir, "real.txt")@@ -1894,89 +2266,279 @@ func TestFlowFileService_DownloadFlowFileScenarios(t *testing.T) {if err := os.Symlink(target, link); err != nil {t.Skipf("symlink unavailable: %v", err)}- return link},wantStatus: http.StatusNotFound,},- }-- for _, tt := range tests {- t.Run(tt.name, func(t *testing.T) {- db := setupFlowFileServiceTestDB(t)- dataDir := t.TempDir()- svc := NewFlowFileService(db, dataDir, nil, nil)-- if tt.flowOwner != 0 {- seedFlow(t, db, tt.flowID, tt.flowOwner)- }- if tt.setupFile != nil {- tt.setupFile(t, dataDir, tt.flowID)- }-- target := "/flows/1/files/download"- if tt.queryPath != "" {- target += "?path=" + tt.queryPath- }- c, w := newFlowFileTestContext(http.MethodGet, target, nil, tt.privs, tt.uid, tt.flowID)-- svc.DownloadFlowFile(c)-- require.Equal(t, tt.wantStatus, w.Code)- if tt.wantStatus != http.StatusOK {- return- }- if tt.wantContentType != "" {- assert.Equal(t, tt.wantContentType, w.Header().Get("Content-Type"))- }- if tt.wantDispContains != "" {- assert.Contains(t, w.Header().Get("Content-Disposition"), tt.wantDispContains)- }- if tt.wantZipEntries != nil {- zr, err := zip.NewReader(bytes.NewReader(w.Body.Bytes()), int64(w.Body.Len()))- require.NoError(t, err)- got := map[string]string{}- for _, f := range zr.File {- rc, err := f.Open()- require.NoError(t, err)- data, err := io.ReadAll(rc)- rc.Close()- require.NoError(t, err)- got[f.Name] = string(data)- }- assert.Equal(t, tt.wantZipEntries, got)- } else if tt.wantBody != "" {- assert.Equal(t, tt.wantBody, w.Body.String())- }- })- }-}-// ─────────────────────────────────────────────────────────────────────────────-// PullFlowFiles handler tests.-// ─────────────────────────────────────────────────────────────────────────────+ // ── paths[] parameter ─────────────────────────────────────────────────-func TestFlowFileService_PullFlowFilesScenarios(t *testing.T) {- tests := []struct {- name string- flowOwner uint64- uid uint64- flowID uint64- privs []string- body any // marshaled via json- rawBody string- seedExisting bool- dockerSetup func(*fakeDockerClient)- dockerNil bool- wantStatus int- wantResponsePath string- wantEventChannel string // "added" | "updated" | ""- }{{- name: "pull new file",+ // Single file via paths[] must produce a direct file attachment.+ name: "single file via paths[] downloaded as direct attachment",flowOwner: 1, uid: 1, flowID: 1,- privs: []string{"flow_files.upload", "containers.view"},- body: models.PullFlowFilesRequest{Path: "/etc/nginx.conf"},- dockerSetup: func(d *fakeDockerClient) {+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=uploads/report.txt",+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {+ dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "uploads")+ require.NoError(t, os.MkdirAll(dir, 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, "report.txt"), []byte("payload"), 0644))+ },+ wantStatus: http.StatusOK,+ wantBody: "payload",+ wantDispContains: "report.txt",+ },+ {+ // Single directory via paths[] must produce a backward-compat ZIP with+ // paths relative to the directory root (not the flow data dir).+ name: "single directory via paths[] uses dir-relative zip paths",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=container/etc",+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {+ dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "container", "etc")+ require.NoError(t, os.MkdirAll(filepath.Join(dir, "nginx"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, "nginx", "nginx.conf"), []byte("nginx"), 0644))+ },+ wantStatus: http.StatusOK,+ wantContentType: "application/zip",+ wantDispContains: "etc.zip",+ wantZipEntries: map[string]string{"nginx/nginx.conf": "nginx"},+ },+ {+ // Two regular files → ZIP with cache-relative paths as entry names.+ name: "two files via paths[] packaged into zip with cache-relative paths",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=uploads/a.txt&paths[]=uploads/b.txt",+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {+ dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "uploads")+ require.NoError(t, os.MkdirAll(dir, 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, "a.txt"), []byte("alpha"), 0644))+ require.NoError(t, os.WriteFile(filepath.Join(dir, "b.txt"), []byte("bravo"), 0644))+ },+ wantStatus: http.StatusOK,+ wantContentType: "application/zip",+ wantDispContains: "download.zip",+ wantZipEntries: map[string]string{+ "uploads/a.txt": "alpha",+ "uploads/b.txt": "bravo",+ },+ },+ {+ // path= and paths[]= are combined; result is a multi-entry ZIP.+ name: "path= and paths[] combined produce multi-entry zip",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "path=uploads/a.txt&paths[]=resources/b.txt",+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {+ base := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID))+ require.NoError(t, os.MkdirAll(filepath.Join(base, "uploads"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(base, "uploads", "a.txt"), []byte("alpha"), 0644))+ require.NoError(t, os.MkdirAll(filepath.Join(base, "resources"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(base, "resources", "b.txt"), []byte("bravo"), 0644))+ },+ wantStatus: http.StatusOK,+ wantContentType: "application/zip",+ wantDispContains: "download.zip",+ wantZipEntries: map[string]string{+ "uploads/a.txt": "alpha",+ "resources/b.txt": "bravo",+ },+ },+ {+ // File and directory combined: directory contents use their full+ // cache-relative paths inside the ZIP.+ name: "file and directory via paths[] combined in zip",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=uploads/a.txt&paths[]=container/etc",+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {+ base := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID))+ require.NoError(t, os.MkdirAll(filepath.Join(base, "uploads"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(base, "uploads", "a.txt"), []byte("alpha"), 0644))+ require.NoError(t, os.MkdirAll(filepath.Join(base, "container", "etc"), 0755))+ require.NoError(t, os.WriteFile(filepath.Join(base, "container", "etc", "nginx.conf"), []byte("nginx"), 0644))+ },+ wantStatus: http.StatusOK,+ wantContentType: "application/zip",+ wantDispContains: "download.zip",+ wantZipEntries: map[string]string{+ "uploads/a.txt": "alpha",+ "container/etc/nginx.conf": "nginx",+ },+ },+ {+ // Parent directory covers child file via DeduplicatePaths; result is a+ // single-directory ZIP using dir-relative paths (backward compat).+ name: "paths[] parent covers child - single dir zip returned",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=uploads/dir&paths[]=uploads/dir/file.txt",+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {+ dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "uploads", "dir")+ require.NoError(t, os.MkdirAll(dir, 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, "file.txt"), []byte("content"), 0644))+ },+ wantStatus: http.StatusOK,+ wantContentType: "application/zip",+ wantDispContains: "dir.zip",+ wantZipEntries: map[string]string{"file.txt": "content"},+ },+ {+ // Sending the same path twice must result in a single entry in the ZIP.+ name: "duplicate paths in paths[] produce single-file download",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=uploads/report.txt&paths[]=uploads/report.txt",+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {+ dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "uploads")+ require.NoError(t, os.MkdirAll(dir, 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, "report.txt"), []byte("payload"), 0644))+ },+ wantStatus: http.StatusOK,+ wantBody: "payload",+ wantDispContains: "report.txt",+ },++ // ── paths[]: invalid input ─────────────────────────────────────────────+ {+ name: "whitespace-only paths[] returns bad request",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=%20%20&paths[]=%09",+ wantStatus: http.StatusBadRequest,+ },+ {+ name: "wrong-prefix path in paths[] returns bad request",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=tmp/evil.txt",+ wantStatus: http.StatusBadRequest,+ },+ {+ name: "path traversal in paths[] returns bad request",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=uploads/../../etc/passwd",+ wantStatus: http.StatusBadRequest,+ },+ {+ // First path is valid; second does not exist.+ // Validation is fail-fast: request returns 404 before any download.+ name: "missing file in batch returns not found",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=uploads/a.txt&paths[]=uploads/missing.txt",+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {+ dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "uploads")+ require.NoError(t, os.MkdirAll(dir, 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, "a.txt"), []byte("x"), 0644))+ },+ wantStatus: http.StatusNotFound,+ },+ {+ // Symlink in the batch must abort with 404 (no partial download).+ name: "symlink in paths[] batch returns not found",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view"},+ rawQuery: "paths[]=uploads/real.txt&paths[]=uploads/link.txt",+ setupFile: func(t *testing.T, dataDir string, flowID uint64) {+ dir := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", flowID), "uploads")+ require.NoError(t, os.MkdirAll(dir, 0755))+ require.NoError(t, os.WriteFile(filepath.Join(dir, "real.txt"), []byte("x"), 0644))+ if err := os.Symlink(filepath.Join(dir, "real.txt"), filepath.Join(dir, "link.txt")); err != nil {+ t.Skipf("symlink unavailable: %v", err)+ }+ },+ wantStatus: http.StatusNotFound,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ db := setupFlowFileServiceTestDB(t)+ dataDir := t.TempDir()+ svc := NewFlowFileService(db, dataDir, nil, nil)++ if tt.flowOwner != 0 {+ seedFlow(t, db, tt.flowID, tt.flowOwner)+ }+ if tt.setupFile != nil {+ tt.setupFile(t, dataDir, tt.flowID)+ }++ target := "/flows/1/files/download"+ switch {+ case tt.rawQuery != "":+ target += "?" + tt.rawQuery+ case tt.queryPath != "":+ target += "?path=" + tt.queryPath+ }+ c, w := newFlowFileTestContext(http.MethodGet, target, nil, tt.privs, tt.uid, tt.flowID)++ svc.DownloadFlowFile(c)++ require.Equal(t, tt.wantStatus, w.Code)+ if tt.wantStatus != http.StatusOK {+ return+ }+ if tt.wantContentType != "" {+ assert.Equal(t, tt.wantContentType, w.Header().Get("Content-Type"))+ }+ if tt.wantDispContains != "" {+ assert.Contains(t, w.Header().Get("Content-Disposition"), tt.wantDispContains)+ }+ if tt.wantZipEntries != nil {+ zr, err := zip.NewReader(bytes.NewReader(w.Body.Bytes()), int64(w.Body.Len()))+ require.NoError(t, err)+ got := map[string]string{}+ for _, f := range zr.File {+ rc, err := f.Open()+ require.NoError(t, err)+ data, err := io.ReadAll(rc)+ rc.Close()+ require.NoError(t, err)+ got[f.Name] = string(data)+ }+ assert.Equal(t, tt.wantZipEntries, got)+ } else if tt.wantBody != "" {+ assert.Equal(t, tt.wantBody, w.Body.String())+ }+ })+ }+}++// ─────────────────────────────────────────────────────────────────────────────+// PullFlowFiles handler tests.+// ─────────────────────────────────────────────────────────────────────────────++func TestFlowFileService_PullFlowFilesScenarios(t *testing.T) {+ tests := []struct {+ name string+ flowOwner uint64+ uid uint64+ flowID uint64+ privs []string+ body any // marshaled via json+ rawBody string+ seedExisting bool // seeds container/etc/nginx.conf+ seedExistingContainerFiles []string // additional relative paths to seed under container cache+ dockerSetup func(*fakeDockerClient)+ dockerNil bool+ wantStatus int+ wantResponsePath string // for single-file response+ wantResponsePaths []string // for multi-file response (ordered)+ wantEventChannel string // "added" | "updated" (checked when set, single-event tests)+ wantEventCount int // > 0: assert total event count+ wantCopyFromCount int // > 0: assert exact CopyFromContainer call count+ }{+ // ── single-path: existing behaviour (backward compatibility) ──────────+ {+ name: "pull new file",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{Path: "/etc/nginx.conf"},+ dockerSetup: func(d *fakeDockerClient) {d.running = trued.copyFromBody = buildContainerTar([]tarTestEntry{{name: "nginx.conf", typeflag: tar.TypeReg, content: "nginx-config"},@@ -2112,6 +2674,231 @@ func TestFlowFileService_PullFlowFilesScenarios(t *testing.T) {},wantStatus: http.StatusInternalServerError,},++ {+ // /etc covers /etc/nginx.conf; DeduplicatePaths reduces the list to just /etc.+ // Only one CopyFromContainer call is made for /etc/, not a separate one for nginx.conf.+ // Docker returns a directory TAR (entries under "etc/"), so the response includes+ // both the directory entry and all nested files.+ name: "parent path covers child path - single docker call, directory contents listed",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{+ Paths: []string{"/etc", "/etc/nginx.conf"},+ },+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.copyFromBodyMap = map[string][]byte{+ // Docker returns a directory TAR with entries under "etc/".+ "/etc": buildContainerTar([]tarTestEntry{+ {name: "etc/", typeflag: tar.TypeDir},+ {name: "etc/nginx.conf", typeflag: tar.TypeReg, content: "nginx"},+ }),+ }+ },+ wantStatus: http.StatusOK,+ // Response: the directory itself + all nested files, sorted by path.+ wantResponsePaths: []string{+ "container/etc",+ "container/etc/nginx.conf",+ },+ wantCopyFromCount: 1, // /etc/nginx.conf is covered → no separate pull+ },++ {+ // Two files supplied via the paths array; both are pulled and returned.+ name: "two files via paths array pulled and returned",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{+ Paths: []string{"/etc/nginx.conf", "/etc/hosts"},+ },+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.copyFromBodyMap = map[string][]byte{+ "/etc/nginx.conf": buildContainerTar([]tarTestEntry{+ {name: "nginx.conf", typeflag: tar.TypeReg, content: "nginx"},+ }),+ "/etc/hosts": buildContainerTar([]tarTestEntry{+ {name: "hosts", typeflag: tar.TypeReg, content: "hosts"},+ }),+ }+ },+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"container/etc/hosts", "container/etc/nginx.conf"},+ wantEventCount: 2,+ wantCopyFromCount: 2,+ },+ {+ // path and paths combined; both files are pulled.+ name: "path and paths combined pull both files",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{+ Path: "/etc/nginx.conf",+ Paths: []string{"/etc/hosts"},+ },+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.copyFromBodyMap = map[string][]byte{+ "/etc/nginx.conf": buildContainerTar([]tarTestEntry{+ {name: "nginx.conf", typeflag: tar.TypeReg, content: "nginx"},+ }),+ "/etc/hosts": buildContainerTar([]tarTestEntry{+ {name: "hosts", typeflag: tar.TypeReg, content: "hosts"},+ }),+ }+ },+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"container/etc/hosts", "container/etc/nginx.conf"},+ wantEventCount: 2,+ },+ {+ // Same path in both path and paths[0]: deduplicated to a single pull.+ name: "duplicate path in path and paths deduplicated to single operation",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{+ Path: "/etc/nginx.conf",+ Paths: []string{"/etc/nginx.conf"},+ },+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.copyFromBody = buildContainerTar([]tarTestEntry{+ {name: "nginx.conf", typeflag: tar.TypeReg, content: "nginx"},+ })+ },+ wantStatus: http.StatusOK,+ wantResponsePath: "container/etc/nginx.conf",+ wantCopyFromCount: 1,+ },+ {+ // All paths are whitespace-only: combined list is empty after dedup → 400.+ name: "whitespace-only paths returns bad request",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{+ Path: " ",+ Paths: []string{" ", "\t"},+ },+ dockerSetup: func(d *fakeDockerClient) { d.running = true },+ wantStatus: http.StatusBadRequest,+ },+ {+ // Second path exists in cache without force=true.+ // Phase 1 detects the conflict before any docker operation; neither file is pulled.+ name: "second path already exists without force fails fast in phase 1",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{+ Paths: []string{"/etc/nginx.conf", "/etc/hosts"},+ },+ seedExistingContainerFiles: []string{"etc/hosts"},+ dockerSetup: func(d *fakeDockerClient) { d.running = true },+ wantStatus: http.StatusConflict,+ wantCopyFromCount: 0, // no docker calls; validation failed in phase 1+ },+ {+ // force=true overwrites all existing cache entries in the batch.+ name: "force overwrites multiple existing cache entries",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{+ Paths: []string{"/etc/nginx.conf", "/etc/hosts"},+ Force: true,+ },+ seedExisting: true, // seeds etc/nginx.conf+ seedExistingContainerFiles: []string{"etc/hosts"},+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.copyFromBodyMap = map[string][]byte{+ "/etc/nginx.conf": buildContainerTar([]tarTestEntry{+ {name: "nginx.conf", typeflag: tar.TypeReg, content: "new-nginx"},+ }),+ "/etc/hosts": buildContainerTar([]tarTestEntry{+ {name: "hosts", typeflag: tar.TypeReg, content: "new-hosts"},+ }),+ }+ },+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"container/etc/hosts", "container/etc/nginx.conf"},+ wantEventCount: 2,+ },+ {+ // First copy succeeds; second copy fails.+ // The first file is committed to cache (partial success is expected when+ // docker errors occur in phase 2).+ name: "second container copy fails returns internal",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{+ Paths: []string{"/etc/nginx.conf", "/etc/hosts"},+ },+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.copyFromBodyMap = map[string][]byte{+ "/etc/nginx.conf": buildContainerTar([]tarTestEntry{+ {name: "nginx.conf", typeflag: tar.TypeReg, content: "nginx"},+ }),+ }+ d.copyFromErrMap = map[string]error{+ "/etc/hosts": fmt.Errorf("path not found in container"),+ }+ },+ wantStatus: http.StatusInternalServerError,+ },+ {+ // /var/log/app.log and /etc/nginx.conf are given in that order.+ // Sorted by cache path, /etc comes before /var alphabetically.+ name: "response sorted by cache path regardless of input order",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{+ Paths: []string{"/var/log/app.log", "/etc/nginx.conf"},+ },+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.copyFromBodyMap = map[string][]byte{+ "/var/log/app.log": buildContainerTar([]tarTestEntry{+ {name: "app.log", typeflag: tar.TypeReg, content: "log"},+ }),+ "/etc/nginx.conf": buildContainerTar([]tarTestEntry{+ {name: "nginx.conf", typeflag: tar.TypeReg, content: "nginx"},+ }),+ }+ },+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{+ "container/etc/nginx.conf",+ "container/var/log/app.log",+ },+ },+ {+ // One path is new (added event), one path exists with force (updated event).+ // Verify both event types are published.+ name: "added and updated events both published in batch",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.upload", "containers.view"},+ body: models.PullFlowFilesRequest{+ Paths: []string{"/etc/nginx.conf", "/etc/hosts"},+ Force: true,+ },+ seedExistingContainerFiles: []string{"etc/hosts"}, // hosts already cached+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.copyFromBodyMap = map[string][]byte{+ "/etc/nginx.conf": buildContainerTar([]tarTestEntry{+ {name: "nginx.conf", typeflag: tar.TypeReg, content: "nginx"},+ }),+ "/etc/hosts": buildContainerTar([]tarTestEntry{+ {name: "hosts", typeflag: tar.TypeReg, content: "new-hosts"},+ }),+ }+ },+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"container/etc/hosts", "container/etc/nginx.conf"},+ wantEventCount: 2, // 1 "added" (nginx.conf) + 1 "updated" (hosts)+ },}for _, tt := range tests {@@ -2137,6 +2924,11 @@ func TestFlowFileService_PullFlowFilesScenarios(t *testing.T) {require.NoError(t, os.MkdirAll(dir, 0755))require.NoError(t, os.WriteFile(filepath.Join(dir, "nginx.conf"), []byte("old"), 0644))}+ for _, relPath := range tt.seedExistingContainerFiles {+ abs := filepath.Join(dataDir, fmt.Sprintf("flow-%d-data", tt.flowID), "container", filepath.FromSlash(relPath))+ require.NoError(t, os.MkdirAll(filepath.Dir(abs), 0755))+ require.NoError(t, os.WriteFile(abs, []byte("old"), 0644))+ }var bodyReader io.Readerif tt.rawBody != "" {@@ -2153,17 +2945,47 @@ func TestFlowFileService_PullFlowFilesScenarios(t *testing.T) {require.Equal(t, tt.wantStatus, w.Code)if tt.wantStatus != http.StatusOK {+ // Even on error, verify docker call count if specified.+ if tt.wantCopyFromCount >= 0 && tt.wantCopyFromCount != fakeDocker.copyFromCount {+ // Only assert when explicitly set (non-zero).+ if tt.wantCopyFromCount > 0 {+ assert.Equal(t, tt.wantCopyFromCount, fakeDocker.copyFromCount, "unexpected CopyFromContainer call count")+ }+ }return}+resp := decodeFlowFilesResponse(t, w)- require.Len(t, resp.Files, 1)- assert.Equal(t, tt.wantResponsePath, resp.Files[0].Path)++ // Path assertions.+ if len(tt.wantResponsePaths) > 0 {+ paths := make([]string, len(resp.Files))+ for i, f := range resp.Files {+ paths[i] = f.Path+ }+ assert.Equal(t, tt.wantResponsePaths, paths)+ } else if tt.wantResponsePath != "" {+ require.Len(t, resp.Files, 1)+ assert.Equal(t, tt.wantResponsePath, resp.Files[0].Path)+ }++ // Event assertions.+ events := ss.snapshot()+ if tt.wantEventCount > 0 {+ assert.Len(t, events, tt.wantEventCount, "unexpected subscription event count")+ }if tt.wantEventChannel != "" {- events := ss.snapshot()require.Len(t, events, 1)assert.Equal(t, "flow", events[0].channel)assert.Equal(t, tt.wantEventChannel, events[0].action)- assert.Equal(t, tt.wantResponsePath, events[0].path)+ if tt.wantResponsePath != "" {+ assert.Equal(t, tt.wantResponsePath, events[0].path)+ }+ }++ // Docker call count assertion.+ if tt.wantCopyFromCount > 0 {+ assert.Equal(t, tt.wantCopyFromCount, fakeDocker.copyFromCount, "unexpected CopyFromContainer call count")}})}@@ -2180,15 +3002,18 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {uid uint64flowID uint64privs []string- queryPath string+ queryPath string // builds ?path=<value>+ rawQuery string // when set, used verbatim as query string (overrides queryPath)dockerSetup func(*fakeDockerClient)dockerNil boolwantStatus intwantPathInResp string- wantFileNames []string+ wantFileNames []string // expected file names in sorted order (nil = don't check)+ wantTotal uint64 // > 0: verify response Total}{+ // ── single-path: existing behaviour (backward compatibility) ──────────{- name: "default path lists work directory",+ name: "default path lists work directory when no param given",flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view", "containers.view"},dockerSetup: func(d *fakeDockerClient) {@@ -2204,7 +3029,7 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {wantFileNames: []string{"report.txt", "uploads"},},{- name: "custom path is honoured",+ name: "custom single path= is honoured",flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view", "containers.view"},queryPath: "/etc",@@ -2232,20 +3057,44 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {wantPathInResp: "/etc/passwd",wantFileNames: []string{"passwd"},},++ // ── access control ────────────────────────────────────────────────────{- name: "missing flow_files privilege",+ name: "missing flow_files privilege returns forbidden",flowOwner: 1, uid: 1, flowID: 1,privs: []string{"containers.view"},wantStatus: http.StatusForbidden,},{- name: "missing containers privilege",+ name: "missing containers privilege returns forbidden",flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view"},wantStatus: http.StatusForbidden,},{- name: "docker client not configured returns internal",+ name: "containers.admin is sufficient for container listing",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.admin"},+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.statPath = container.PathStat{Mode: os.ModeDir | 0755}+ d.listDir = []container.PathStat{{Name: "a.txt", Mode: 0644}}+ },+ wantStatus: http.StatusOK,+ wantPathInResp: "/work",+ wantFileNames: []string{"a.txt"},+ },+ {+ name: "missing flow returns not found",+ uid: 1,+ flowID: 99,+ privs: []string{"flow_files.view", "containers.view"},+ wantStatus: http.StatusNotFound,+ },++ // ── infrastructure errors ─────────────────────────────────────────────+ {+ name: "docker client not configured returns internal error",flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view", "containers.view"},dockerNil: true,@@ -2261,7 +3110,7 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {wantStatus: http.StatusBadRequest,},{- name: "stat path error returns internal",+ name: "stat path error returns internal error",flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view", "containers.view"},dockerSetup: func(d *fakeDockerClient) {@@ -2271,7 +3120,7 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {wantStatus: http.StatusInternalServerError,},{- name: "list dir error returns internal",+ name: "list dir error returns internal error",flowOwner: 1, uid: 1, flowID: 1,privs: []string{"flow_files.view", "containers.view"},dockerSetup: func(d *fakeDockerClient) {@@ -2281,12 +3130,190 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {},wantStatus: http.StatusInternalServerError,},++ // ── paths[] parameter ─────────────────────────────────────────────────+{- name: "missing flow returns not found",- uid: 1,- flowID: 99,- privs: []string{"flow_files.view", "containers.view"},- wantStatus: http.StatusNotFound,+ // Single path delivered via paths[] instead of path= must behave+ // identically, including the Path field in the response.+ name: "single paths[] behaves like single path=",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.view"},+ rawQuery: "paths[]=/etc",+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.statPath = container.PathStat{Mode: os.ModeDir | 0755}+ d.listDir = []container.PathStat{+ {Name: "passwd", Size: 1, Mode: 0644},+ }+ },+ wantStatus: http.StatusOK,+ wantPathInResp: "/etc",+ wantFileNames: []string{"passwd"},+ },+ {+ // Two directories are queried; results are merged and sorted by name.+ // The response Path must be empty because there is no single "current dir".+ name: "two directories via paths[] returns combined sorted listing",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.view"},+ rawQuery: "paths[]=/etc&paths[]=/var",+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.statPathMap = map[string]container.PathStat{+ "/etc": {Mode: os.ModeDir | 0755},+ "/var": {Mode: os.ModeDir | 0755},+ }+ d.listDirMap = map[string][]container.PathStat{+ "/etc": {+ {Name: "nginx.conf", Size: 10, Mode: 0644},+ {Name: "passwd", Size: 1, Mode: 0644},+ },+ "/var": {+ {Name: "log", Mode: os.ModeDir | 0755},+ },+ }+ },+ wantStatus: http.StatusOK,+ wantPathInResp: "",+ wantFileNames: []string{"nginx.conf", "passwd", "log"},+ wantTotal: 3,+ },+ {+ // path= and paths[]= are combined; merged listing is sorted.+ name: "path= and paths[] combined returns merged sorted listing",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.view"},+ rawQuery: "path=/etc&paths[]=/var",+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.statPathMap = map[string]container.PathStat{+ "/etc": {Mode: os.ModeDir | 0755},+ "/var": {Mode: os.ModeDir | 0755},+ }+ d.listDirMap = map[string][]container.PathStat{+ "/etc": {{Name: "hosts", Size: 5, Mode: 0644}},+ "/var": {{Name: "log", Mode: os.ModeDir | 0755}},+ }+ },+ wantStatus: http.StatusOK,+ wantPathInResp: "",+ wantFileNames: []string{"hosts", "log"},+ },+ {+ // Sending the same path twice must result in a single stat + list call.+ // The response contains each file only once.+ name: "duplicate paths in paths[] deduplicated",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.view"},+ rawQuery: "paths[]=/etc&paths[]=/etc",+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.statPath = container.PathStat{Mode: os.ModeDir | 0755}+ d.listDir = []container.PathStat{+ {Name: "passwd", Size: 1, Mode: 0644},+ }+ },+ wantStatus: http.StatusOK,+ wantPathInResp: "/etc",+ wantFileNames: []string{"passwd"},+ wantTotal: 1,+ },+ {+ // All paths[] values are whitespace only: the combined list is empty+ // after trimming even though params were explicitly provided → 400.+ name: "whitespace-only paths[] values return bad request",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.view"},+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ },+ rawQuery: "paths[]=%20%20&paths[]=%09",+ wantStatus: http.StatusBadRequest,+ },+ {+ // A regular file and a directory are combined in a single request.+ // The file entry and the directory contents appear together, sorted.+ name: "mix of file and directory in paths[] combined in response",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.view"},+ rawQuery: "paths[]=/etc/passwd&paths[]=/var",+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.statPathMap = map[string]container.PathStat{+ "/etc/passwd": {Name: "passwd", Size: 5, Mode: 0644},+ "/var": {Mode: os.ModeDir | 0755},+ }+ d.listDirMap = map[string][]container.PathStat{+ "/var": {{Name: "log", Mode: os.ModeDir | 0755}},+ }+ },+ wantStatus: http.StatusOK,+ wantPathInResp: "",+ wantFileNames: []string{"passwd", "log"},+ },+ {+ // Docker API returns the same entry twice from a single ListContainerDir+ // call (unexpected but possible). The response must deduplicate by path.+ name: "output deduplicated when Docker API returns duplicate entries",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.view"},+ rawQuery: "paths[]=/work",+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.statPath = container.PathStat{Mode: os.ModeDir | 0755}+ d.listDir = []container.PathStat{+ {Name: "file.txt", Size: 5, Mode: 0644},+ {Name: "file.txt", Size: 5, Mode: 0644}, // duplicate+ }+ },+ wantStatus: http.StatusOK,+ wantPathInResp: "/work",+ wantFileNames: []string{"file.txt"},+ wantTotal: 1,+ },+ {+ // First path succeeds; second path's stat call fails.+ // The handler must return 500 (fail-fast).+ name: "second path stat error in batch returns internal error",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.view"},+ rawQuery: "paths[]=/work&paths[]=/etc",+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.statPathMap = map[string]container.PathStat{+ "/work": {Mode: os.ModeDir | 0755},+ }+ d.statPathErrMap = map[string]error{+ "/etc": fmt.Errorf("path not found"),+ }+ d.listDirMap = map[string][]container.PathStat{+ "/work": {{Name: "uploads", Mode: os.ModeDir | 0755}},+ }+ },+ wantStatus: http.StatusInternalServerError,+ },+ {+ // First path directory listing succeeds; second path's listing fails.+ // The handler must return 500 (fail-fast).+ name: "second path list dir error in batch returns internal error",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.view"},+ rawQuery: "paths[]=/work&paths[]=/etc",+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.statPathMap = map[string]container.PathStat{+ "/work": {Mode: os.ModeDir | 0755},+ "/etc": {Mode: os.ModeDir | 0755},+ }+ d.listDirMap = map[string][]container.PathStat{+ "/work": {{Name: "uploads", Mode: os.ModeDir | 0755}},+ }+ d.listDirErrMap = map[string]error{+ "/etc": fmt.Errorf("permission denied"),+ }+ },+ wantStatus: http.StatusInternalServerError,},}@@ -2310,7 +3337,10 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {}target := "/flows/1/files/container"- if tt.queryPath != "" {+ switch {+ case tt.rawQuery != "":+ target += "?" + tt.rawQuery+ case tt.queryPath != "":target += "?path=" + tt.queryPath}c, w := newFlowFileTestContext(http.MethodGet, target, nil, tt.privs, tt.uid, tt.flowID)@@ -2323,11 +3353,18 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {}resp := decodeContainerFilesResponse(t, w)assert.Equal(t, tt.wantPathInResp, resp.Path)- names := make([]string, len(resp.Files))- for i, f := range resp.Files {- names[i] = f.Name++ if tt.wantFileNames != nil {+ names := make([]string, len(resp.Files))+ for i, f := range resp.Files {+ names[i] = f.Name+ }+ assert.Equal(t, tt.wantFileNames, names)+ }+ if tt.wantTotal > 0 {+ assert.Equal(t, tt.wantTotal, resp.Total, "response Total mismatch")+ assert.Len(t, resp.Files, int(tt.wantTotal), "response Files length mismatch")}- assert.Equal(t, tt.wantFileNames, names)})}}diff --git a/backend/pkg/server/services/resources.go b/backend/pkg/server/services/resources.goindex 04be8f1f..c4daee16 100644--- a/backend/pkg/server/services/resources.go+++ b/backend/pkg/server/services/resources.go@@ -1,6 +1,7 @@package servicesimport (+ "bytes""context""errors""fmt"@@ -9,6 +10,7 @@ import ("os""path""slices"+ "sort""strings""time"@@ -65,8 +67,9 @@ func NewResourceService(// @Tags Resources// @Produce json// @Security BearerAuth-// @Param path query string false "virtual directory path; empty for root"-// @Param recursive query bool false "list recursively (default false)"+// @Param path query string false "virtual directory path; empty for root (may be combined with paths[])"+// @Param paths[] query []string false "additional virtual directory paths (repeatable)"+// @Param recursive query bool false "list recursively (default false)"// @Success 200 {object} response.successResp{data=models.ResourceList}// @Failure 400 {object} response.errorResp// @Failure 403 {object} response.errorResp@@ -82,28 +85,136 @@ func (s *ResourceService) ListResources(c *gin.Context) {return}- reqPath := strings.TrimSpace(c.Query("path"))recursive := c.Query("recursive") == "true" || c.Query("recursive") == "1"- var dirPath string- if reqPath != "" {- var err error- dirPath, err = resources.SanitizeResourcePath(reqPath)+ // Collect paths from both "path" and "paths[]" query params.+ rawPaths := c.QueryArray("paths[]")+ if singlePath := strings.TrimSpace(c.Query("path")); singlePath != "" {+ rawPaths = append(rawPaths, singlePath)+ }++ // When no paths are provided, list the root (backward-compat behaviour).+ if len(rawPaths) == 0 {+ items, err := s.queryResources(uid, isAdmin, "", recursive)if err != nil {- logger.FromContext(c).WithError(err).Error("invalid path for list resources")- response.Error(c, response.ErrResourcesInvalidRequest, err)+ logger.FromContext(c).WithError(err).Error("error listing resources")+ response.Error(c, response.ErrInternal, err)return}+ response.Success(c, http.StatusOK, models.ResourceList{Items: items, Total: uint64(len(items))})+ return}- items, err := s.queryResources(uid, isAdmin, dirPath, recursive)+ dirPaths, err := collectAndSanitizeResourcePaths(rawPaths)if err != nil {- logger.FromContext(c).WithError(err).Error("error listing resources")- response.Error(c, response.ErrInternal, err)+ logger.FromContext(c).WithError(err).Error("invalid path for list resources")+ response.Error(c, response.ErrResourcesInvalidRequest, err)return}- response.Success(c, http.StatusOK, models.ResourceList{Items: items, Total: uint64(len(items))})+ // If all provided paths were whitespace-only, fall back to root listing.+ if len(dirPaths) == 0 {+ items, err := s.queryResources(uid, isAdmin, "", recursive)+ if err != nil {+ logger.FromContext(c).WithError(err).Error("error listing resources")+ response.Error(c, response.ErrInternal, err)+ return+ }+ response.Success(c, http.StatusOK, models.ResourceList{Items: items, Total: uint64(len(items))})+ return+ }++ // Query each path and merge results, deduplicating by virtual path.+ seenPaths := make(map[string]struct{})+ allItems := make([]models.ResourceEntry, 0)+ for _, dirPath := range dirPaths {+ items, err := s.queryResources(uid, isAdmin, dirPath, recursive)+ if err != nil {+ logger.FromContext(c).WithError(err).Error("error listing resources")+ response.Error(c, response.ErrInternal, err)+ return+ }+ for _, item := range items {+ if _, seen := seenPaths[item.Path]; !seen {+ seenPaths[item.Path] = struct{}{}+ allItems = append(allItems, item)+ }+ }+ }++ // Ensure all ancestor directories of queried paths are present so that+ // clients can construct a complete tree without dangling nodes.+ // For example, querying "temp2/temp" must also return "temp2".+ ancestorCandidates := make(map[string]struct{})+ for _, dirPath := range dirPaths {+ parts := strings.Split(dirPath, "/")+ for i := 1; i < len(parts); i++ {+ ancestor := strings.Join(parts[:i], "/")+ if _, already := seenPaths[ancestor]; !already {+ ancestorCandidates[ancestor] = struct{}{}+ }+ }+ }+ if len(ancestorCandidates) > 0 {+ neededAncestors := make([]string, 0, len(ancestorCandidates))+ for p := range ancestorCandidates {+ neededAncestors = append(neededAncestors, p)+ }+ q := s.db.Model(&models.UserResource{}).Where("path IN (?) AND is_dir = true", neededAncestors)+ if !isAdmin {+ q = q.Where("user_id = ?", uid)+ }+ var ancestorRecs []models.UserResource+ if err := q.Find(&ancestorRecs).Error; err != nil {+ logger.FromContext(c).WithError(err).Error("error fetching ancestor directories for resources listing")+ response.Error(c, response.ErrInternal, err)+ return+ }+ for _, rec := range ancestorRecs {+ if _, seen := seenPaths[rec.Path]; !seen {+ seenPaths[rec.Path] = struct{}{}+ allItems = append(allItems, convertResource(rec))+ }+ }+ }++ sort.Slice(allItems, func(i, j int) bool {+ if allItems[i].Path < allItems[j].Path {+ return true+ } else if allItems[i].Path > allItems[j].Path {+ return false+ } else if allItems[i].Name < allItems[j].Name {+ return true+ } else if allItems[i].Name > allItems[j].Name {+ return false+ }+ return allItems[i].CreatedAt.Before(allItems[j].CreatedAt)+ })+ response.Success(c, http.StatusOK, models.ResourceList{Items: allItems, Total: uint64(len(allItems))})+}++// collectAndSanitizeResourcePaths sanitizes and deduplicates a slice of raw+// virtual resource paths. Whitespace-only entries are skipped; invalid paths+// return an error. Returns nil when all entries reduce to empty (caller decides+// the fallback behaviour).+func collectAndSanitizeResourcePaths(rawPaths []string) ([]string, error) {+ seen := make(map[string]struct{}, len(rawPaths))+ result := make([]string, 0, len(rawPaths))+ for _, p := range rawPaths {+ trimmed := strings.TrimSpace(p)+ if trimmed == "" {+ continue+ }+ sanitized, err := resources.SanitizeResourcePath(trimmed)+ if err != nil {+ return nil, err+ }+ if _, dup := seen[sanitized]; !dup {+ seen[sanitized] = struct{}{}+ result = append(result, sanitized)+ }+ }+ return result, nil}// ---- POST /resources/ ------------------------------------------------------@@ -111,11 +222,11 @@ func (s *ResourceService) ListResources(c *gin.Context) {// UploadResources uploads one or more files into the user's resource storage.// @Summary Upload files to resource storage// @Tags Resources-// @Accept mpfd+// @Accept mpfd// @Produce json// @Security BearerAuth-// @Param dir query string false "target virtual directory path; empty or omitted means root"-// @Param files formData file true "files to upload (field name: files or file)"+// @Param dir query string false "target virtual directory path; empty or omitted means root"+// @Param files formData file true "files to upload (field name: files or file)"// @Success 200 {object} response.successResp{data=models.ResourceList}// @Failure 400 {object} response.errorResp// @Failure 403 {object} response.errorResp@@ -345,7 +456,7 @@ func (s *ResourceService) UploadResources(c *gin.Context) {// MkdirResource creates a virtual directory entry (idempotent).// @Summary Create a virtual directory// @Tags Resources-// @Accept json+// @Accept json// @Produce json// @Security BearerAuth// @Param request body models.MkdirResourceRequest true "mkdir request"@@ -424,7 +535,7 @@ func (s *ResourceService) MkdirResource(c *gin.Context) {// MoveResource renames or moves a file or directory.// @Summary Move or rename a resource (file or directory)// @Tags Resources-// @Accept json+// @Accept json// @Produce json// @Security BearerAuth// @Param request body models.MoveResourceRequest true "move request"@@ -876,7 +987,7 @@ func updateMovedResource(tx *gorm.DB, rec models.UserResource, newPath string, n// CopyResource copies a file or directory to a new path.// @Summary Copy a resource (file or directory)// @Tags Resources-// @Accept json+// @Accept json// @Produce json// @Security BearerAuth// @Param request body models.CopyResourceRequest true "copy request"@@ -1191,12 +1302,13 @@ func (s *ResourceService) copyDirResource(// ---- DELETE /resources/ -----------------------------------------------------// DeleteResource deletes a file or directory (recursively) by virtual path.+// DeleteResource deletes one or more files or directories (recursively) by virtual path.// @Summary Delete a resource (file or directory)// @Tags Resources// @Produce json// @Security BearerAuth-// @Param path query string true "virtual path to delete"+// @Param path query string false "virtual path to delete (may be combined with paths[])"+// @Param paths[] query []string false "additional virtual paths to delete (repeatable)"// @Success 200 {object} response.successResp{data=models.ResourceList}// @Failure 400 {object} response.errorResp// @Failure 403 {object} response.errorResp@@ -1212,55 +1324,78 @@ func (s *ResourceService) DeleteResource(c *gin.Context) {return}- reqPath := strings.TrimSpace(c.Query("path"))- if reqPath == "" {- response.Error(c, response.ErrResourcesInvalidRequest, errors.New("path query parameter is required"))+ // Collect paths from both "path" and "paths[]" query params.+ rawPaths := c.QueryArray("paths[]")+ if singlePath := strings.TrimSpace(c.Query("path")); singlePath != "" {+ rawPaths = append(rawPaths, singlePath)+ }+ if len(rawPaths) == 0 {+ response.Error(c, response.ErrResourcesInvalidRequest,+ errors.New("at least one path is required (use 'path' or 'paths[]' query parameters)"))return}- targetPath, err := resources.SanitizeResourcePath(reqPath)++ targetPaths, err := collectAndSanitizeResourcePaths(rawPaths)if err != nil {response.Error(c, response.ErrResourcesInvalidRequest, err)return}+ if len(targetPaths) == 0 {+ response.Error(c, response.ErrResourcesInvalidRequest,+ errors.New("at least one valid path is required"))+ return+ }- // Verify target exists and belongs to user.- var root models.UserResource- if err := s.db.Where("user_id = ? AND path = ?", uid, targetPath).First(&root).Error; err != nil {- if gorm.IsRecordNotFoundError(err) {- response.Error(c, response.ErrResourcesNotFound, fmt.Errorf("resource %q not found", targetPath))+ // Phase 1: validate every path and collect all records to delete.+ // Validation is fail-fast so that no rows are removed if any path is missing.+ hashSet := make(map[string]struct{})+ idSet := make(map[uint64]struct{})+ var toDelete []models.UserResource++ for _, targetPath := range targetPaths {+ var root models.UserResource+ if err := s.db.Where("user_id = ? AND path = ?", uid, targetPath).First(&root).Error; err != nil {+ if gorm.IsRecordNotFoundError(err) {+ response.Error(c, response.ErrResourcesNotFound, fmt.Errorf("resource %q not found", targetPath))+ return+ }+ logger.FromContext(c).WithError(err).Error("error finding resource for delete")+ response.Error(c, response.ErrInternal, err)return}- logger.FromContext(c).WithError(err).Error("error finding resource for delete")- response.Error(c, response.ErrInternal, err)- return- }- escapedTarget := resources.EscapeLike(targetPath)+ escapedTarget := resources.EscapeLike(targetPath)+ var descendants []models.UserResource+ if err := s.db.Where(+ "user_id = ? AND (path = ? OR path LIKE ?)",+ uid, targetPath, escapedTarget+"/%",+ ).Find(&descendants).Error; err != nil {+ logger.FromContext(c).WithError(err).Error("error listing resources for delete")+ response.Error(c, response.ErrInternal, err)+ return+ }- var toDelete []models.UserResource- if err := s.db.Where(- "user_id = ? AND (path = ? OR path LIKE ?)",- uid, targetPath, escapedTarget+"/%",- ).Find(&toDelete).Error; err != nil {- logger.FromContext(c).WithError(err).Error("error listing resources for delete")- response.Error(c, response.ErrInternal, err)+ for _, rec := range descendants {+ if _, dup := idSet[rec.ID]; !dup {+ idSet[rec.ID] = struct{}{}+ toDelete = append(toDelete, rec)+ if !rec.IsDir && rec.Hash != "" {+ hashSet[rec.Hash] = struct{}{}+ }+ }+ }+ }++ if len(toDelete) == 0 {+ response.Success(c, http.StatusOK, models.ResourceList{})return}- hashSet := make(map[string]struct{})ids := make([]uint64, 0, len(toDelete))deleted := make([]models.ResourceEntry, 0, len(toDelete))for _, rec := range toDelete {ids = append(ids, rec.ID)deleted = append(deleted, convertResource(rec))- if !rec.IsDir && rec.Hash != "" {- hashSet[rec.Hash] = struct{}{}- }- }-- if len(ids) == 0 {- response.Success(c, http.StatusOK, models.ResourceList{})- return}if err := s.db.Where("id IN (?)", ids).Delete(&models.UserResource{}).Error; err != nil {@@ -1277,19 +1412,36 @@ func (s *ResourceService) DeleteResource(c *gin.Context) {s.cleanupOrphanBlobs(c.Request.Context(), hashes)}+ sort.Slice(deleted, func(i, j int) bool {+ if deleted[i].Path < deleted[j].Path {+ return true+ } else if deleted[i].Path > deleted[j].Path {+ return false+ } else if deleted[i].Name < deleted[j].Name {+ return true+ } else if deleted[i].Name > deleted[j].Name {+ return false+ }+ return deleted[i].CreatedAt.Before(deleted[j].CreatedAt)+ })+s.publishResourcesDeleted(c.Request.Context(), uid, deleted)response.Success(c, http.StatusOK, models.ResourceList{Items: deleted, Total: uint64(len(deleted))})}// ---- GET /resources/download ------------------------------------------------// DownloadResource downloads a single file or a directory as a ZIP archive.-// @Summary Download a resource+// DownloadResource downloads one or more resources.+// Single regular file: served as a direct attachment with an explicit+// Content-Length header so that Swagger UI and browsers offer a download link.+// Single directory or multiple paths (any mix): packaged into a ZIP archive.+// @Summary Download a resource or resources// @Tags Resources-// @Produce application/octet-stream+// @Produce application/octet-stream,application/zip,json// @Security BearerAuth-// @Param path query string true "virtual path to download"-// @Success 200 {file} binary "file content, or ZIP archive for directories"+// @Param path query string false "virtual path to download (may be combined with paths[])"+// @Param paths[] query []string false "additional virtual paths to download (repeatable)"+// @Success 200 {file} binary "file content, or ZIP archive for directories / multiple paths"// @Failure 400 {object} response.errorResp "invalid resource request data"// @Failure 403 {object} response.errorResp "downloading resource not permitted"// @Failure 404 {object} response.errorResp "resource not found"@@ -1305,80 +1457,181 @@ func (s *ResourceService) DownloadResource(c *gin.Context) {return}- reqPath := strings.TrimSpace(c.Query("path"))- if reqPath == "" {- response.Error(c, response.ErrResourcesInvalidRequest, errors.New("path query parameter is required"))+ // Collect paths from both "path" and "paths[]" query params, then deduplicate.+ rawPaths := c.QueryArray("paths[]")+ if singlePath := strings.TrimSpace(c.Query("path")); singlePath != "" {+ rawPaths = append(rawPaths, singlePath)+ }+ if len(rawPaths) == 0 {+ response.Error(c, response.ErrResourcesInvalidRequest,+ errors.New("at least one path is required (use 'path' or 'paths[]' query parameters)"))return}- targetPath, err := resources.SanitizeResourcePath(reqPath)++ targetPaths, err := collectAndSanitizeResourcePaths(rawPaths)if err != nil {response.Error(c, response.ErrResourcesInvalidRequest, err)return}+ if len(targetPaths) == 0 {+ response.Error(c, response.ErrResourcesInvalidRequest,+ errors.New("at least one valid path is required"))+ return+ }- q := s.db.Where("path = ?", targetPath)- if !isAdmin {- q = q.Where("user_id = ?", uid)+ // Load each requested resource from the DB; fail-fast on missing.+ type resolvedEntry struct {+ rec models.UserResource}- var rec models.UserResource- if err := q.First(&rec).Error; err != nil {- if gorm.IsRecordNotFoundError(err) {- response.Error(c, response.ErrResourcesNotFound, fmt.Errorf("resource %q not found", targetPath))+ entries := make([]resolvedEntry, 0, len(targetPaths))+ seenTargets := make(map[string]struct{}, len(targetPaths))+ for _, targetPath := range targetPaths {+ if _, dup := seenTargets[targetPath]; dup {+ continue+ }+ seenTargets[targetPath] = struct{}{}++ q := s.db.Where("path = ?", targetPath)+ if !isAdmin {+ q = q.Where("user_id = ?", uid)+ }+ var rec models.UserResource+ if err := q.First(&rec).Error; err != nil {+ if gorm.IsRecordNotFoundError(err) {+ response.Error(c, response.ErrResourcesNotFound, fmt.Errorf("resource %q not found", targetPath))+ return+ }+ logger.FromContext(c).WithError(err).Error("error finding resource for download")+ response.Error(c, response.ErrInternal, err)return}- logger.FromContext(c).WithError(err).Error("error finding resource for download")- response.Error(c, response.ErrInternal, err)- return+ entries = append(entries, resolvedEntry{rec: rec})}- if !rec.IsDir {- blobPath := resources.BlobPath(s.dataDir, rec.Hash)- if _, statErr := os.Lstat(blobPath); statErr != nil {- if os.IsNotExist(statErr) {+ // Single regular file → serve as a direct attachment with explicit Content-Length.+ if len(entries) == 1 && !entries[0].rec.IsDir {+ e := entries[0]+ blobPath := resources.BlobPath(s.dataDir, e.rec.Hash)+ f, err := os.Open(blobPath)+ if err != nil {+ if os.IsNotExist(err) {response.Error(c, response.ErrResourcesNotFound,- fmt.Errorf("blob for resource %q not found on disk", targetPath))+ fmt.Errorf("blob for resource %q not found on disk", e.rec.Path))return}- logger.FromContext(c).WithError(statErr).Error("error checking blob for download")- response.Error(c, response.ErrInternal, statErr)+ logger.FromContext(c).WithError(err).Error("error opening resource blob for download")+ response.Error(c, response.ErrInternal, err)+ return+ }+ defer f.Close()++ info, err := f.Stat()+ if err != nil {+ logger.FromContext(c).WithError(err).Error("error stating resource blob for download")+ response.Error(c, response.ErrInternal, err)return}- c.FileAttachment(blobPath, rec.Name)+ c.DataFromReader(http.StatusOK, info.Size(), "application/octet-stream", f,+ map[string]string{+ "Content-Disposition": mime.FormatMediaType("attachment", map[string]string{+ "filename": e.rec.Name,+ }),+ })return}- // Directory: collect all non-directory entries recursively.- escapedTarget := resources.EscapeLike(targetPath)- var fileRecs []models.UserResource- if err := s.db.Where(- "user_id = ? AND path LIKE ? AND is_dir = false",- rec.UserID, escapedTarget+"/%",- ).Find(&fileRecs).Error; err != nil {- logger.FromContext(c).WithError(err).Error("error listing resources for zip download")- response.Error(c, response.ErrInternal, err)+ // Single directory → ZIP with paths relative to that directory (backward-compat).+ if len(entries) == 1 && entries[0].rec.IsDir {+ e := entries[0]+ escapedTarget := resources.EscapeLike(e.rec.Path)+ var fileRecs []models.UserResource+ if err := s.db.Where(+ "user_id = ? AND path LIKE ? AND is_dir = false",+ e.rec.UserID, escapedTarget+"/%",+ ).Find(&fileRecs).Error; err != nil {+ logger.FromContext(c).WithError(err).Error("error listing resources for zip download")+ response.Error(c, response.ErrInternal, err)+ return+ }++ zipEntries := make([]resources.ZipEntry, 0, len(fileRecs))+ for _, fr := range fileRecs {+ relPath := strings.TrimPrefix(fr.Path, e.rec.Path+"/")+ if relPath == "" {+ relPath = fr.Name+ }+ zipEntries = append(zipEntries, resources.ZipEntry{+ BlobPath: resources.BlobPath(s.dataDir, fr.Hash),+ ZipPath: relPath,+ })+ }++ dirName := path.Base(e.rec.Path)+ var buf bytes.Buffer+ if err := resources.ZipResources(&buf, zipEntries); err != nil {+ logger.FromContext(c).WithError(err).Error("error creating zip archive for download")+ response.Error(c, response.ErrInternal, err)+ return+ }+ c.DataFromReader(http.StatusOK, int64(buf.Len()), "application/zip", &buf,+ map[string]string{+ "Content-Disposition": mime.FormatMediaType("attachment", map[string]string{+ "filename": dirName + ".zip",+ }),+ })return}- entries := make([]resources.ZipEntry, 0, len(fileRecs))- for _, fr := range fileRecs {- relPath := strings.TrimPrefix(fr.Path, targetPath+"/")- if relPath == "" {- relPath = fr.Name+ // Multiple paths (any mix of files and directories) → ZIP using the full+ // virtual path as each entry name so the caller sees the complete path context.+ seenZipPaths := make(map[string]struct{})+ zipEntries := make([]resources.ZipEntry, 0)+ for _, e := range entries {+ if !e.rec.IsDir {+ if _, dup := seenZipPaths[e.rec.Path]; !dup {+ seenZipPaths[e.rec.Path] = struct{}{}+ zipEntries = append(zipEntries, resources.ZipEntry{+ BlobPath: resources.BlobPath(s.dataDir, e.rec.Hash),+ ZipPath: e.rec.Path,+ })+ }+ continue+ }++ // Directory: collect all file descendants using their full virtual paths.+ escapedTarget := resources.EscapeLike(e.rec.Path)+ var fileRecs []models.UserResource+ if err := s.db.Where(+ "user_id = ? AND path LIKE ? AND is_dir = false",+ e.rec.UserID, escapedTarget+"/%",+ ).Find(&fileRecs).Error; err != nil {+ logger.FromContext(c).WithError(err).Error("error listing resources for zip download")+ response.Error(c, response.ErrInternal, err)+ return+ }+ for _, fr := range fileRecs {+ if _, dup := seenZipPaths[fr.Path]; !dup {+ seenZipPaths[fr.Path] = struct{}{}+ zipEntries = append(zipEntries, resources.ZipEntry{+ BlobPath: resources.BlobPath(s.dataDir, fr.Hash),+ ZipPath: fr.Path,+ })+ }}- entries = append(entries, resources.ZipEntry{- BlobPath: resources.BlobPath(s.dataDir, fr.Hash),- ZipPath: relPath,- })}- dirName := path.Base(targetPath)- c.Header("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{- "filename": dirName + ".zip",- }))- c.Header("Content-Type", "application/zip")- if err := resources.ZipResources(c.Writer, entries); err != nil {+ var buf bytes.Buffer+ if err := resources.ZipResources(&buf, zipEntries); err != nil {logger.FromContext(c).WithError(err).Error("error creating zip archive for download")+ response.Error(c, response.ErrInternal, err)+ return}+ c.DataFromReader(http.StatusOK, int64(buf.Len()), "application/zip", &buf,+ map[string]string{+ "Content-Disposition": mime.FormatMediaType("attachment", map[string]string{+ "filename": "download.zip",+ }),+ })}// ---- helper methods --------------------------------------------------------diff --git a/backend/pkg/server/services/resources_test.go b/backend/pkg/server/services/resources_test.goindex 04a55e13..eee81b63 100644--- a/backend/pkg/server/services/resources_test.go+++ b/backend/pkg/server/services/resources_test.go@@ -240,6 +240,8 @@ func TestResourceService_ListResourcesScenarios(t *testing.T) {name stringseeds []seedpath string+ paths []string // additional paths for paths[] param+ rawQuery string // overrides path/paths/recursive URL building when setrecursive boolprivs []stringuid uint64@@ -358,6 +360,151 @@ func TestResourceService_ListResourcesScenarios(t *testing.T) {wantStatus: http.StatusOK,wantResponsePaths: []string{},},++ // ── paths[] parameter ────────────────────────────────────────────────+ {+ // Two sibling directories listed via paths[]; results are merged and sorted.+ name: "two directories via paths[] returns combined deduplicated results",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a"},+ {path: "other", isDir: true},+ {path: "other/b.txt", content: "b"},+ },+ paths: []string{"docs", "other"},+ privs: []string{"resources.view"},+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"docs", "docs/a.txt", "other", "other/b.txt"},+ },+ {+ // path= and paths[]= are combined; both directories are listed.+ name: "path= and paths[] combined return merged results",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a"},+ {path: "extra", isDir: true},+ {path: "extra/c.txt", content: "c"},+ },+ path: "docs",+ paths: []string{"extra"},+ privs: []string{"resources.view"},+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"docs", "docs/a.txt", "extra", "extra/c.txt"},+ },+ {+ // Same path sent twice in paths[]; items appear only once in the response.+ name: "duplicate paths in paths[] deduplicated",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a"},+ },+ paths: []string{"docs", "docs"},+ privs: []string{"resources.view"},+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"docs", "docs/a.txt"},+ },+ {+ // path and paths[] query the same path; results deduplicated.+ name: "path= and paths[] with same value deduplicated",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a"},+ },+ path: "docs",+ paths: []string{"docs"},+ privs: []string{"resources.view"},+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"docs", "docs/a.txt"},+ },+ {+ // Whitespace-only paths[] entries are ignored; falls back to root listing.+ name: "whitespace-only paths[] falls back to root listing",+ seeds: []seed{+ {path: "root.txt", content: "r"},+ },+ rawQuery: "paths[]=%20%20&paths[]=%09",+ privs: []string{"resources.view"},+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"root.txt"},+ },+ {+ // An invalid path in paths[] returns 400.+ name: "invalid path in paths[] returns bad request",+ rawQuery: "paths[]=docs&paths[]=../escape",+ privs: []string{"resources.view"},+ wantStatus: http.StatusBadRequest,+ },+ {+ // Results from multiple paths are returned sorted by virtual path.+ name: "output sorted by path across multiple queried paths",+ seeds: []seed{+ {path: "z", isDir: true},+ {path: "z/c.txt", content: "c"},+ {path: "a", isDir: true},+ {path: "a/b.txt", content: "b"},+ },+ paths: []string{"z", "a"},+ privs: []string{"resources.view"},+ wantStatus: http.StatusOK,+ // a < a/b.txt < z < z/c.txt+ wantResponsePaths: []string{"a", "a/b.txt", "z", "z/c.txt"},+ },+ {+ // Querying a nested path must also return its parent directory so that+ // a client can construct a complete tree without dangling nodes.+ name: "listing nested path includes parent directory as ancestor",+ seeds: []seed{+ {path: "base", isDir: true},+ {path: "base/sub", isDir: true},+ {path: "base/sub/file.txt", content: "x"},+ },+ paths: []string{"base/sub"},+ privs: []string{"resources.view"},+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"base", "base/sub", "base/sub/file.txt"},+ },+ {+ // A deeply nested path must include every ancestor directory.+ name: "listing deeply nested path includes all ancestor directories",+ seeds: []seed{+ {path: "a", isDir: true},+ {path: "a/b", isDir: true},+ {path: "a/b/c", isDir: true},+ {path: "a/b/c/file.txt", content: "y"},+ },+ paths: []string{"a/b/c"},+ privs: []string{"resources.view"},+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"a", "a/b", "a/b/c", "a/b/c/file.txt"},+ },+ {+ // If an ancestor directory does not exist in the DB it is simply omitted.+ name: "missing ancestor directory not added to response",+ seeds: []seed{+ // "base" parent is intentionally not seeded+ {path: "base/sub", isDir: true},+ {path: "base/sub/file.txt", content: "x"},+ },+ paths: []string{"base/sub"},+ privs: []string{"resources.view"},+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"base/sub", "base/sub/file.txt"},+ },+ {+ // Ancestors are scoped to the requesting user; another user's ancestor+ // directory must not appear in the response.+ name: "ancestor directory belonging to another user is not included",+ seeds: []seed{+ {userID: 2, path: "shared", isDir: true},+ {userID: 1, path: "shared/sub", isDir: true},+ {userID: 1, path: "shared/sub/file.txt", content: "x"},+ },+ paths: []string{"shared/sub"},+ privs: []string{"resources.view"},+ wantStatus: http.StatusOK,+ // "shared" belongs to user 2 → not returned for user 1+ wantResponsePaths: []string{"shared/sub", "shared/sub/file.txt"},+ },}for _, tt := range tests {@@ -382,16 +529,24 @@ func TestResourceService_ListResourcesScenarios(t *testing.T) {seedResource(t, db, seeded)}- target := "/resources/"- query := []string{}- if tt.path != "" {- query = append(query, "path="+tt.path)- }- if tt.recursive {- query = append(query, "recursive=true")- }- if len(query) > 0 {- target += "?" + strings.Join(query, "&")+ var target string+ if tt.rawQuery != "" {+ target = "/resources/?" + tt.rawQuery+ } else {+ target = "/resources/"+ query := []string{}+ if tt.path != "" {+ query = append(query, "path="+tt.path)+ }+ for _, p := range tt.paths {+ query = append(query, "paths[]="+p)+ }+ if tt.recursive {+ query = append(query, "recursive=true")+ }+ if len(query) > 0 {+ target += "?" + strings.Join(query, "&")+ }}uid := tt.uid@@ -573,7 +728,7 @@ func TestResourceService_MkdirResourceScenarios(t *testing.T) {assert.Equal(t, tt.wantEvents, ss.events)if tt.wantStatus == http.StatusOK {var resp struct {- Status string `json:"status"`+ Status string `json:"status"`Data models.ResourceEntry `json:"data"`}require.NoError(t, json.Unmarshal(w.Body.Bytes(), &resp))@@ -888,7 +1043,9 @@ func TestResourceService_DownloadResourceScenarios(t *testing.T) {tests := []struct {name stringseeds []seed- path string+ path string // builds ?path=<value>+ paths []string // builds ?paths[]=<value> for each+ rawQuery string // when set, used verbatim (overrides path/paths)privs []stringuid uint64wantStatus int@@ -897,6 +1054,7 @@ func TestResourceService_DownloadResourceScenarios(t *testing.T) {wantDispContains stringwantZipEntries map[string]string}{+ // ── single-path: existing behaviour (backward compatibility) ──────────{name: "download single file with download privilege",seeds: []seed{{path: "report.txt", content: "payload"}},@@ -935,6 +1093,7 @@ func TestResourceService_DownloadResourceScenarios(t *testing.T) {wantStatus: http.StatusOK,wantContentType: "application/zip",wantDispContains: "docs.zip",+ // Single dir → paths relative to dir root.wantZipEntries: map[string]string{"a.txt": "a-data","sub/b.txt": "b-data",@@ -963,6 +1122,8 @@ func TestResourceService_DownloadResourceScenarios(t *testing.T) {wantDispContains: "docs.zip",wantZipEntries: map[string]string{},},++ // ── access control ────────────────────────────────────────────────────{name: "missing privilege returns forbidden",seeds: []seed{{path: "report.txt", content: "payload"}},@@ -970,10 +1131,11 @@ func TestResourceService_DownloadResourceScenarios(t *testing.T) {privs: []string{"resources.view"},wantStatus: http.StatusForbidden,},++ // ── single-path: invalid input ────────────────────────────────────────{name: "empty path returns bad request",seeds: []seed{{path: "report.txt", content: "payload"}},- path: "",privs: []string{"resources.download"},wantStatus: http.StatusBadRequest,},@@ -997,6 +1159,128 @@ func TestResourceService_DownloadResourceScenarios(t *testing.T) {privs: []string{"resources.download"},wantStatus: http.StatusNotFound,},++ // ── paths[] parameter ─────────────────────────────────────────────────++ {+ // Single file via paths[] behaves identically to path=.+ name: "single file via paths[] downloaded directly",+ seeds: []seed{{path: "report.txt", content: "payload"}},+ paths: []string{"report.txt"},+ privs: []string{"resources.download"},+ wantStatus: http.StatusOK,+ wantBody: "payload",+ wantDispContains: "report.txt",+ },+ {+ // Single directory via paths[] uses dir-relative ZIP paths (backward-compat).+ name: "single directory via paths[] uses dir-relative zip paths",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a-data"},+ {path: "docs/sub", isDir: true},+ {path: "docs/sub/b.txt", content: "b-data"},+ },+ paths: []string{"docs"},+ privs: []string{"resources.download"},+ wantStatus: http.StatusOK,+ wantContentType: "application/zip",+ wantDispContains: "docs.zip",+ wantZipEntries: map[string]string{+ "a.txt": "a-data",+ "sub/b.txt": "b-data",+ },+ },+ {+ // Two files → ZIP where each entry uses its full virtual path.+ name: "two files via paths[] packaged into zip with full virtual paths",+ seeds: []seed{+ {path: "docs/a.txt", content: "a-data"},+ {path: "other/b.txt", content: "b-data"},+ },+ paths: []string{"docs/a.txt", "other/b.txt"},+ privs: []string{"resources.download"},+ wantStatus: http.StatusOK,+ wantContentType: "application/zip",+ wantDispContains: "download.zip",+ wantZipEntries: map[string]string{+ "docs/a.txt": "a-data",+ "other/b.txt": "b-data",+ },+ },+ {+ // path= and paths[]= are combined; result is a multi-entry ZIP.+ name: "path= and paths[] combined produce multi-entry zip",+ seeds: []seed{+ {path: "a.txt", content: "a-data"},+ {path: "b.txt", content: "b-data"},+ },+ path: "a.txt",+ paths: []string{"b.txt"},+ privs: []string{"resources.download"},+ wantStatus: http.StatusOK,+ wantContentType: "application/zip",+ wantDispContains: "download.zip",+ wantZipEntries: map[string]string{+ "a.txt": "a-data",+ "b.txt": "b-data",+ },+ },+ {+ // File and directory combined: directory contents use full virtual paths.+ name: "file and directory via paths[] combined in zip with full virtual paths",+ seeds: []seed{+ {path: "report.txt", content: "report-data"},+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a-data"},+ {path: "docs/sub", isDir: true},+ {path: "docs/sub/b.txt", content: "b-data"},+ },+ paths: []string{"report.txt", "docs"},+ privs: []string{"resources.download"},+ wantStatus: http.StatusOK,+ wantContentType: "application/zip",+ wantDispContains: "download.zip",+ wantZipEntries: map[string]string{+ "report.txt": "report-data",+ "docs/a.txt": "a-data",+ "docs/sub/b.txt": "b-data",+ },+ },+ {+ // Same path sent twice: downloaded exactly once.+ name: "duplicate paths in paths[] deduplicated",+ seeds: []seed{{path: "a.txt", content: "alpha"}},+ paths: []string{"a.txt", "a.txt"},+ privs: []string{"resources.download"},+ wantStatus: http.StatusOK,+ wantBody: "alpha",+ wantDispContains: "a.txt",+ },+ {+ // Whitespace-only paths → 400.+ name: "whitespace-only paths[] returns bad request",+ rawQuery: "paths[]=%20%20&paths[]=%09",+ privs: []string{"resources.download"},+ wantStatus: http.StatusBadRequest,+ },+ {+ // Invalid path → 400.+ name: "invalid path in paths[] returns bad request",+ rawQuery: "paths[]=docs&paths[]=../escape",+ privs: []string{"resources.download"},+ wantStatus: http.StatusBadRequest,+ },+ {+ // First resource valid, second missing → 404, fail-fast.+ name: "missing resource in batch returns not found",+ seeds: []seed{+ {path: "a.txt", content: "alpha"},+ },+ paths: []string{"a.txt", "missing.txt"},+ privs: []string{"resources.download"},+ wantStatus: http.StatusNotFound,+ },}for _, tt := range tests {@@ -1025,10 +1309,23 @@ func TestResourceService_DownloadResourceScenarios(t *testing.T) {seedResource(t, db, seeded)}- target := "/resources/download"- if tt.path != "" {- target += "?path=" + tt.path+ var target string+ if tt.rawQuery != "" {+ target = "/resources/download?" + tt.rawQuery+ } else {+ query := []string{}+ if tt.path != "" {+ query = append(query, "path="+tt.path)+ }+ for _, p := range tt.paths {+ query = append(query, "paths[]="+p)+ }+ target = "/resources/download"+ if len(query) > 0 {+ target += "?" + strings.Join(query, "&")+ }}+uid := tt.uidif uid == 0 {uid = 1@@ -1079,7 +1376,9 @@ func TestResourceService_DeleteResourceScenarios(t *testing.T) {tests := []struct {name stringseeds []seed- targetPath string+ targetPath string // builds ?path=<value>+ targetPaths []string // builds ?paths[]=<value> for each+ rawQuery string // overrides targetPath/targetPaths when setprivs []stringwantStatus intwantPaths []string@@ -1211,6 +1510,119 @@ func TestResourceService_DeleteResourceScenarios(t *testing.T) {wantPaths: []string{"report.txt"},wantPresentBlobs: []string{"payload"},},++ // ── paths[] parameter ────────────────────────────────────────────────+ {+ // Two sibling files deleted in one request.+ name: "delete two files via paths[] in batch",+ seeds: []seed{+ {path: "a.txt", content: "a"},+ {path: "b.txt", content: "b"},+ {path: "keep.txt", content: "keep"},+ },+ targetPaths: []string{"a.txt", "b.txt"},+ privs: []string{"resources.delete"},+ wantStatus: http.StatusOK,+ wantPaths: []string{"keep.txt"},+ wantResponsePaths: []string{"a.txt", "b.txt"},+ wantEvents: []resourceEvent{+ {action: "deleted", path: "a.txt"},+ {action: "deleted", path: "b.txt"},+ },+ wantMissingBlobs: []string{"a", "b"},+ wantPresentBlobs: []string{"keep"},+ },+ {+ // path= and paths[]= are combined.+ name: "path= and paths[] combined delete both targets",+ seeds: []seed{+ {path: "a.txt", content: "a"},+ {path: "b.txt", content: "b"},+ },+ targetPath: "a.txt",+ targetPaths: []string{"b.txt"},+ privs: []string{"resources.delete"},+ wantStatus: http.StatusOK,+ wantPaths: []string{},+ wantResponsePaths: []string{"a.txt", "b.txt"},+ wantEvents: []resourceEvent{+ {action: "deleted", path: "a.txt"},+ {action: "deleted", path: "b.txt"},+ },+ },+ {+ // Same path sent twice: each record is deleted exactly once.+ name: "duplicate paths in paths[] deduplicated",+ seeds: []seed{+ {path: "a.txt", content: "a"},+ },+ targetPaths: []string{"a.txt", "a.txt"},+ privs: []string{"resources.delete"},+ wantStatus: http.StatusOK,+ wantPaths: []string{},+ wantResponsePaths: []string{"a.txt"},+ wantEvents: []resourceEvent{{action: "deleted", path: "a.txt"}},+ wantMissingBlobs: []string{"a"},+ },+ {+ // Whitespace-only paths[] → 400 (no valid paths provided).+ name: "whitespace-only paths[] returns bad request",+ rawQuery: "paths[]=%20%20&paths[]=%09",+ privs: []string{"resources.delete"},+ wantStatus: http.StatusBadRequest,+ },+ {+ // First path valid, second path missing → 404, nothing deleted (fail-fast).+ name: "missing second path in batch returns 404 without deleting first",+ seeds: []seed{+ {path: "a.txt", content: "a"},+ },+ targetPaths: []string{"a.txt", "missing.txt"},+ privs: []string{"resources.delete"},+ wantStatus: http.StatusNotFound,+ wantPaths: []string{"a.txt"}, // not deleted due to fail-fast+ },+ {+ // Parent and child both in delete list: all descendants collected once+ // via ID deduplication; no double-deletion or errors.+ name: "overlapping paths parent and child both processed correctly",+ seeds: []seed{+ {path: "docs", isDir: true},+ {path: "docs/a.txt", content: "a"},+ {path: "docs/sub", isDir: true},+ {path: "docs/sub/b.txt", content: "b"},+ },+ targetPath: "docs",+ targetPaths: []string{"docs/a.txt"},+ privs: []string{"resources.delete"},+ wantStatus: http.StatusOK,+ wantPaths: []string{},+ wantResponsePaths: []string{"docs", "docs/a.txt", "docs/sub", "docs/sub/b.txt"},+ wantEvents: []resourceEvent{+ {action: "deleted", path: "docs"},+ {action: "deleted", path: "docs/a.txt"},+ {action: "deleted", path: "docs/sub"},+ {action: "deleted", path: "docs/sub/b.txt"},+ },+ },+ {+ // Deleted entries are returned sorted by virtual path.+ name: "response sorted by path across multiple deleted targets",+ seeds: []seed{+ {path: "z.txt", content: "z"},+ {path: "a.txt", content: "a"},+ {path: "m.txt", content: "m"},+ },+ targetPaths: []string{"z.txt", "a.txt", "m.txt"},+ privs: []string{"resources.delete"},+ wantStatus: http.StatusOK,+ wantResponsePaths: []string{"a.txt", "m.txt", "z.txt"},+ wantEvents: []resourceEvent{+ {action: "deleted", path: "a.txt"},+ {action: "deleted", path: "m.txt"},+ {action: "deleted", path: "z.txt"},+ },+ },}for _, tt := range tests {@@ -1244,7 +1656,20 @@ func TestResourceService_DeleteResourceScenarios(t *testing.T) {seedResource(t, db, seeded)}- c, w := newResourceTestContext(http.MethodDelete, "/resources/?path="+tt.targetPath, nil, tt.privs)+ var target string+ if tt.rawQuery != "" {+ target = "/resources/?" + tt.rawQuery+ } else {+ query := []string{}+ if tt.targetPath != "" {+ query = append(query, "path="+tt.targetPath)+ }+ for _, p := range tt.targetPaths {+ query = append(query, "paths[]="+p)+ }+ target = "/resources/?" + strings.Join(query, "&")+ }+ c, w := newResourceTestContext(http.MethodDelete, target, nil, tt.privs)svc.DeleteResource(c)require.Equal(t, tt.wantStatus, w.Code)