Skip to content

Commit 27c1c39

Browse files
authored
OPFS site creation: Use the same "is this directory a site?" check as the site list (#65)
Site list and site creation use different criteria for checking if an OPFS directory represents a site. * The site list displays OPFS directories with `wp-runtime.json` file inside * New site creation assumes every OPFS directory represents a site and refuses to create a site with a given sluf if a corresponding directory exists – even if there's no `wp-runtime.json` inside. This means a user may not see the site in the list and still be unable to save it under the requested slug. This PR adjusts the check during new site creation to test for the presence of `wp-runtime.json`. CC @brandonpayton – what do you think?
1 parent 0f66399 commit 27c1c39

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/playground/website/src/lib/state/opfs/opfs-site-storage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ class OpfsSiteStorage {
5252
async create(slug: string, metadata: SiteMetadata): Promise<void> {
5353
const newSiteDirName = getDirectoryNameForSlug(slug);
5454
if (await opfsChildExists(this.root, newSiteDirName)) {
55-
throw new Error(`Site with slug '${slug}' already exists.`);
55+
const dir = await this.root.getDirectoryHandle(newSiteDirName);
56+
if (await opfsChildExists(dir, SITE_METADATA_FILENAME)) {
57+
throw new Error(`Site with slug '${slug}' already exists.`);
58+
}
5659
}
5760

5861
await this.root.getDirectoryHandle(newSiteDirName, {

0 commit comments

Comments
 (0)