package librarysnapshot import ( "errors" "os" "testing" ) func TestArchiveOpenPersistsDirectoryEntriesAndPropagatesSyncFailure(t *testing.T) { root := t.TempDir() if err := os.Chmod(root, 0700); err != nil { t.Fatal(err) } calls := 0 archive, err := openArchive(root, 1024*1024, func(r *os.Root) error { calls++; return syncRoot(r) }) if err != nil { t.Fatal(err) } archive.Close() if calls != 2 { t.Fatalf("root and root-parent durability missing: sync calls=%d", calls) } for _, failAt := range []int{1, 2} { injected := errors.New("directory fsync failed") n := 0 archive, err = openArchive(root, 1024*1024, func(r *os.Root) error { n++ if n == failAt { return injected } return syncRoot(r) }) if !errors.Is(err, injected) || archive != nil { if archive != nil { archive.Close() } t.Fatal("directory fsync failure did not block archive publication", err) } } }