@agoric/swing-store-simple
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.2.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/swing-store-simple@0.1.2...@agoric/swing-store-simple@0.2.0) (2020-05-04) | ||
### Features | ||
* swing-store-simple: add isSwingStore() query ([c450459](https://github.com/Agoric/agoric-sdk/commit/c450459a92d3ecba4a106820d980683babdf8c29)), closes [#953](https://github.com/Agoric/agoric-sdk/issues/953) | ||
## [0.1.2](https://github.com/Agoric/agoric-sdk/compare/@agoric/swing-store-simple@0.1.2-alpha.0...@agoric/swing-store-simple@0.1.2) (2020-04-13) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@agoric/swing-store-simple", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "Persistent storage for SwingSet, based on a Map, optionally backed by a simple JSON file", | ||
@@ -27,3 +27,3 @@ "main": "simpleSwingStore.js", | ||
}, | ||
"gitHead": "a5fe2624fedcf3b8adf46ed6c157c29fd459b2ed" | ||
"gitHead": "534d1a65d79f9dd176cc670f374c9de2cd081a7e" | ||
} |
@@ -299,1 +299,25 @@ import fs from 'fs'; | ||
} | ||
/** | ||
* Is this directory a compatible swing store? | ||
* | ||
* @param dirPath Path to a directory in which database files might be present. | ||
* This directory need not actually exist | ||
* | ||
* @return boolean | ||
* If the directory is present and contains the files created by initSwingStore | ||
* or openSwingStore, returns true. Else returns false. | ||
* | ||
*/ | ||
export function isSwingStore(dirPath) { | ||
if (`${dirPath}` !== dirPath) { | ||
throw new Error('dirPath must be a string'); | ||
} | ||
if (fs.existsSync(dirPath)) { | ||
const storeFile = path.resolve(dirPath, 'swingset-kernel-state.jsonlines'); | ||
if (fs.existsSync(storeFile)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
import fs from 'fs'; | ||
import path from 'path'; | ||
@@ -8,2 +9,3 @@ import { test } from 'tape-promise/tape'; | ||
getAllState, | ||
isSwingStore, | ||
} from '../simpleSwingStore'; | ||
@@ -49,2 +51,4 @@ | ||
test('storageInFile', t => { | ||
fs.rmdirSync('testdb', { recursive: true }); | ||
t.equal(isSwingStore('testdb'), false); | ||
const { storage, commit, close } = initSwingStore('testdb'); | ||
@@ -55,8 +59,20 @@ testStorage(t, storage); | ||
close(); | ||
t.equal(isSwingStore('testdb'), true); | ||
const { storage: after } = openSwingStore('testdb'); | ||
t.deepEqual(getAllState(after), before, 'check state after reread'); | ||
t.equal(isSwingStore('testdb'), true); | ||
t.end(); | ||
}); | ||
test('rejectLMDB', t => { | ||
const notSimpleDir = 'testdb-lmdb'; | ||
fs.mkdirSync(notSimpleDir, { recursive: true }); | ||
fs.writeFileSync(path.resolve(notSimpleDir, 'data.mdb'), 'some data\n'); | ||
fs.writeFileSync(path.resolve(notSimpleDir, 'lock.mdb'), 'lock stuff\n'); | ||
t.equal(isSwingStore(notSimpleDir), false); | ||
t.end(); | ||
}); | ||
test.onFinish(() => fs.rmdirSync('testdb', { recursive: true })); | ||
test.onFinish(() => fs.rmdirSync('testdb-lmdb', { recursive: true })); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25841
391