-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fetch/list endpoints for remote access to the registry.
This supports read access for applications outside of the shared FS.
- Loading branch information
Showing
4 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"path/filepath" | ||
"fmt" | ||
"io/fs" | ||
) | ||
|
||
func listFiles(dir string, recursive bool) ([]string, error) { | ||
to_report := []string{} | ||
|
||
err := filepath.WalkDir(dir, func(path string, info fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
is_dir := info.IsDir() | ||
if is_dir { | ||
if recursive || dir == path { | ||
return nil | ||
} | ||
} | ||
|
||
rel, err := filepath.Rel(dir, path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !recursive && is_dir { | ||
to_report = append(to_report, rel + "/") | ||
return fs.SkipDir | ||
} else { | ||
to_report = append(to_report, rel) | ||
return nil | ||
} | ||
}) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("failed to obtain a directory listing; %w", err) | ||
} | ||
|
||
return to_report, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
) | ||
|
||
func TestListFiles(t *testing.T) { | ||
dir, err := os.MkdirTemp("", "") | ||
if (err != nil) { | ||
t.Fatalf("failed to create a temporary directory; %v", err) | ||
} | ||
|
||
path := filepath.Join(dir, "A") | ||
err = os.WriteFile(path, []byte(""), 0644) | ||
if err != nil { | ||
t.Fatalf("failed to create a mock file; %v", err) | ||
} | ||
|
||
subdir := filepath.Join(dir, "sub") | ||
err = os.Mkdir(subdir, 0755) | ||
if err != nil { | ||
t.Fatalf("failed to create a temporary subdirectory; %v", err) | ||
} | ||
|
||
subpath := filepath.Join(subdir, "B") | ||
err = os.WriteFile(subpath, []byte(""), 0644) | ||
if err != nil { | ||
t.Fatalf("failed to create a mock file; %v", err) | ||
} | ||
|
||
// Checking that we pull out all the files. | ||
all, err := listFiles(dir, true) | ||
if (err != nil) { | ||
t.Fatal(err) | ||
} | ||
|
||
sort.Strings(all) | ||
if len(all) != 2 || all[0] != "A" || all[1] != "sub/B" { | ||
t.Errorf("unexpected results from the listing (%q)", all) | ||
} | ||
|
||
// Checking that the directories are properly listed. | ||
all, err = listFiles(dir, false) | ||
if (err != nil) { | ||
t.Fatal(err) | ||
} | ||
|
||
sort.Strings(all) | ||
if len(all) != 2 || all[0] != "A" || all[1] != "sub/" { | ||
t.Errorf("unexpected results from the listing (%q)", all) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters