Artifact dc986378a1cfb16646d1d2567d6ed83d92ede4a5c3e02f2561b89e4837e23a5c:
- File
fossil_create_parent_test.go
— part of check-in
[2449bcd313]
at
2026-10-26 12:30:29
on branch main
— fix: let Create proceed when the filesystem cannot stat the parent
Create's parent-directory check, added in #457, refused a path whenever os.Stat of its parent failed. Under TinyGo wasm a repository lives in a SQLite VFS and os.Stat is unsupported, so every create failed with "parent directory does not exist: /"; standard Go's js/wasm build hung on the same check. It now refuses only a parent the filesystem confirms is missing or is not a directory, and otherwise lets SQLite's own open report a real failure (tracked in #509). (user: [email protected], size: 1288) [annotate] [blame] [check-ins using] [more...]
package libfossil import ( "errors" "io/fs" "os" "path/filepath" "strings" "testing" ) // Create refuses a path whose parent the filesystem confirms is missing or // is not a directory, and proceeds when the filesystem cannot say, as under // TinyGo wasm, where a repository lives in a SQLite VFS and os.Stat is // unsupported (#509). func TestCreateParentDirectory(t *testing.T) { dir := t.TempDir() file := filepath.Join(dir, "plain-file") if err := os.WriteFile(file, []byte("x"), 0o644); err != nil { t.Fatal(err) } for path, want := range map[string]string{ filepath.Join(dir, "no-such-dir", "r.fossil"): "parent directory does not exist", filepath.Join(file, "r.fossil"): "parent is not a directory", } { _, err := Create(path, CreateOpts{User: "test"}) if err == nil || !strings.Contains(err.Error(), want) { t.Errorf("Create(%s) = %v, want %q", path, err, want) } } statUnsupported := func(string) (fs.FileInfo, error) { return nil, errors.ErrUnsupported } saved := statParent statParent = statUnsupported t.Cleanup(func() { statParent = saved }) r, err := Create(filepath.Join(dir, "r.fossil"), CreateOpts{User: "test"}) if err != nil { t.Fatalf("Create with an unsupported stat: %v, want it to proceed", err) } r.Close() }