mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-11 04:48:44 +03:00
Merge branch 'stable' into beta
This commit is contained in:
commit
c4adc38273
@ -1,4 +1,6 @@
|
||||
temp = require 'temp'
|
||||
path = require 'path'
|
||||
fs = require 'fs-plus'
|
||||
FileSystemBlobStore = require '../src/file-system-blob-store'
|
||||
|
||||
describe "FileSystemBlobStore", ->
|
||||
@ -77,3 +79,27 @@ describe "FileSystemBlobStore", ->
|
||||
expect(blobStore.get("b", "invalidation-key-2")).toBeUndefined()
|
||||
expect(blobStore.get("b", "invalidation-key-3")).toBeUndefined()
|
||||
expect(blobStore.get("c", "invalidation-key-4")).toBeUndefined()
|
||||
|
||||
it "ignores errors when loading an invalid blob store", ->
|
||||
blobStore.set("a", "invalidation-key-1", new Buffer("a"))
|
||||
blobStore.set("b", "invalidation-key-2", new Buffer("b"))
|
||||
blobStore.save()
|
||||
|
||||
# Simulate corruption
|
||||
fs.writeFileSync(path.join(storageDirectory, "MAP"), new Buffer([0]))
|
||||
fs.writeFileSync(path.join(storageDirectory, "INVKEYS"), new Buffer([0]))
|
||||
fs.writeFileSync(path.join(storageDirectory, "BLOB"), new Buffer([0]))
|
||||
|
||||
blobStore = FileSystemBlobStore.load(storageDirectory)
|
||||
|
||||
expect(blobStore.get("a", "invalidation-key-1")).toBeUndefined()
|
||||
expect(blobStore.get("b", "invalidation-key-2")).toBeUndefined()
|
||||
|
||||
blobStore.set("a", "invalidation-key-1", new Buffer("x"))
|
||||
blobStore.set("b", "invalidation-key-2", new Buffer("y"))
|
||||
blobStore.save()
|
||||
|
||||
blobStore = FileSystemBlobStore.load(storageDirectory)
|
||||
|
||||
expect(blobStore.get("a", "invalidation-key-1")).toEqual(new Buffer("x"))
|
||||
expect(blobStore.get("b", "invalidation-key-2")).toEqual(new Buffer("y"))
|
||||
|
@ -12,12 +12,16 @@ class FileSystemBlobStore {
|
||||
}
|
||||
|
||||
constructor (directory) {
|
||||
this.inMemoryBlobs = new Map()
|
||||
this.invalidationKeys = {}
|
||||
this.blobFilename = path.join(directory, 'BLOB')
|
||||
this.blobMapFilename = path.join(directory, 'MAP')
|
||||
this.invalidationKeysFilename = path.join(directory, 'INVKEYS')
|
||||
this.lockFilename = path.join(directory, 'LOCK')
|
||||
this.reset()
|
||||
}
|
||||
|
||||
reset () {
|
||||
this.inMemoryBlobs = new Map()
|
||||
this.invalidationKeys = {}
|
||||
this.storedBlob = new Buffer(0)
|
||||
this.storedBlobMap = {}
|
||||
}
|
||||
@ -32,9 +36,14 @@ class FileSystemBlobStore {
|
||||
if (!fs.existsSync(this.invalidationKeysFilename)) {
|
||||
return
|
||||
}
|
||||
this.storedBlob = fs.readFileSync(this.blobFilename)
|
||||
this.storedBlobMap = JSON.parse(fs.readFileSync(this.blobMapFilename))
|
||||
this.invalidationKeys = JSON.parse(fs.readFileSync(this.invalidationKeysFilename))
|
||||
|
||||
try {
|
||||
this.storedBlob = fs.readFileSync(this.blobFilename)
|
||||
this.storedBlobMap = JSON.parse(fs.readFileSync(this.blobMapFilename))
|
||||
this.invalidationKeys = JSON.parse(fs.readFileSync(this.invalidationKeysFilename))
|
||||
} catch (e) {
|
||||
this.reset()
|
||||
}
|
||||
}
|
||||
|
||||
save () {
|
||||
|
Loading…
Reference in New Issue
Block a user