Issues (791)

src/cli/extend/lock.js (2 issues)

1
import path from 'path'
2
import fs from 'fs'
3
4
import {config} from '../'
5
6
export function create(name) {
7
  let lockFile = path.join(config.root, `abe-process-${name}.lock`)
8
  try {
9
    var stats = fs.statSync(lockFile)
10
    if (stats.isFile()) {
11
      console.log(`cannot lock process ${name} already running`)
0 ignored issues
show
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
12
      return false
13
    }
14
  }catch(err) {
15
    fs.writeFileSync(lockFile, '', {encoding: 'utf8'})
16
  }
17
18
  return true
19
}
20
21
export function remove(name) {
22
  let lockFile = path.join(config.root, `abe-process-${name}.lock`)
23
  try {
24
    var stats = fs.statSync(lockFile)
25
    if (stats.isFile()) {
26
      fs.unlinkSync(lockFile)
27
      return true
28
    }
29
  }catch(err) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
30
    
31
  }
32
  return false
33
}
34
35
export function deleteAll() {
36
  var files = fs.readdirSync(config.root)
37
  Array.prototype.forEach.call(files, (file) => {
38
    if (file.indexOf('abe-process') > -1 && file.indexOf('.lock') > -1) {
39
      fs.unlinkSync(path.join(config.root, file))
40
    }
41
  })
42
}