Skip to content

Commit

Permalink
Create workdir if not exist. (wechaty/wechaty-puppet-padplus#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Feb 8, 2020
1 parent 5bfdb5b commit 98d3963
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/flash-store-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ export class FlashStoreSync<K = any, V = any> implements Map<K, V> {

if (!this.workdir) {
this.workdir = path.join(appRoot, '.flash-store-sync')
if (!fs.existsSync(this.workdir)) {
fs.mkdirSync(this.workdir)
}
}

this.asyncBusyDict = {}
Expand All @@ -49,7 +46,6 @@ export class FlashStoreSync<K = any, V = any> implements Map<K, V> {
this.flashStore = new FlashStore<K, V>(this.workdir)

this.asyncBusyAdd(this.loadStoreToCache())

}

private async loadStoreToCache (): Promise<void> {
Expand Down
17 changes: 14 additions & 3 deletions src/flash-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,24 @@ export class FlashStore<K = string, V = any> implements AsyncMap<K, V> {

if (!this.workdir) {
this.workdir = path.join(appRoot, '.flash-store')
if (!fs.existsSync(this.workdir)) {
}

if (fs.existsSync(this.workdir)) {
log.verbose('FlashStore', 'constructor(%s)', workdir)
} else {
/**
* Mkdir for the database directory. (only for the last path, no recursive)
*/
log.silly('FlashStore', 'constructor(%s) not exist, creating...', this.workdir)
try {
fs.mkdirSync(this.workdir)
} catch (e) {
log.error('FlashStore', 'constructor(%s) exception: %s', this.workdir, e && e.message)
throw e
}
log.silly('FlashStore', 'constructor(%s) workdir created.', this.workdir)
}

log.verbose('FlashStore', 'constructor(%s)', workdir)

// we use seperate workdir for snapdb, leveldb, and rocksdb etc.
const medeaWorkdir = path.join(this.workdir, 'medea')

Expand Down

0 comments on commit 98d3963

Please sign in to comment.