Skip to content

fix: handle deploy-scoped stores on Windows #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import semver from 'semver'
import tmp from 'tmp-promise'
import { test, expect, beforeAll, afterEach } from 'vitest'

import { getStore } from './main.js'
import { getDeployStore, getStore } from './main.js'
import { BlobsServer } from './server.js'

beforeAll(async () => {
Expand Down Expand Up @@ -286,3 +286,28 @@ test('Lists entries', async () => {

expect(parachutesSongs2.directories).toEqual([])
})

test('Works with a deploy-scoped store', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have committed this test first and you can see it failing: d746898

const deployID = '655f77a1b48f470008e5879a'
const directory = await tmp.dir()
const server = new BlobsServer({
directory: directory.path,
token,
})
const { port } = await server.start()

const store = getDeployStore({
deployID,
edgeURL: `http://localhost:${port}`,
token,
siteID,
})
const key = 'my-key'

await store.set(key, 'value 1 for store 1')

expect(await store.get(key)).toBe('value 1 for store 1')

await server.stop()
await fs.rm(directory.path, { force: true, recursive: true })
})
8 changes: 6 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createReadStream, createWriteStream, promises as fs } from 'node:fs'
import http from 'node:http'
import { tmpdir } from 'node:os'
import { dirname, join, relative, resolve, sep } from 'node:path'
import { platform } from 'node:process'

import { ListResponse } from './backend/list.ts'
import { decodeMetadata, encodeMetadata, METADATA_HEADER_INTERNAL } from './metadata.ts'
Expand Down Expand Up @@ -301,12 +302,15 @@ export class BlobsServer {
return {}
}

const [, siteID, storeName, ...key] = url.pathname.split('/')
const [, siteID, rawStoreName, ...key] = url.pathname.split('/')

if (!siteID || !storeName) {
if (!siteID || !rawStoreName) {
return {}
}

// On Windows, file paths can't include the `:` character, which is used in
// deploy-scoped stores.
const storeName = platform === 'win32' ? encodeURIComponent(rawStoreName) : rawStoreName
const rootPath = resolve(this.directory, 'entries', siteID, storeName)
const dataPath = resolve(rootPath, ...key)
const metadataPath = resolve(this.directory, 'metadata', siteID, storeName, ...key)
Expand Down