| Total Complexity | 10 |
| Complexity/F | 2.5 |
| Lines of Code | 46 |
| Function Count | 4 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | import process from 'child_process' |
||
| 2 | import path from 'path' |
||
| 3 | import fs from 'fs' |
||
| 4 | |||
| 5 | import { |
||
| 6 | config |
||
| 7 | ,abeExtend |
||
|
|
|||
| 8 | } from '../' |
||
| 9 | |||
| 10 | export function create(name) { |
||
| 11 | let lockFile = path.join(config.root, `abe-process-${name}.lock`) |
||
| 12 | try { |
||
| 13 | var stats = fs.statSync(lockFile) |
||
| 14 | if (stats.isFile()) { |
||
| 15 | console.log(`cannot lock process ${name} already running`) |
||
| 16 | return false |
||
| 17 | } |
||
| 18 | }catch(err) { |
||
| 19 | fs.writeFileSync(lockFile, '', {encoding: 'utf8'}) |
||
| 20 | } |
||
| 21 | |||
| 22 | return true |
||
| 23 | } |
||
| 24 | |||
| 25 | export function remove(name) { |
||
| 26 | let lockFile = path.join(config.root, `abe-process-${name}.lock`) |
||
| 27 | try { |
||
| 28 | var stats = fs.statSync(lockFile) |
||
| 29 | if (stats.isFile()) { |
||
| 30 | fs.unlinkSync(lockFile) |
||
| 31 | return true |
||
| 32 | } |
||
| 33 | }catch(err) { |
||
| 34 | |||
| 35 | } |
||
| 36 | return false |
||
| 37 | } |
||
| 38 | |||
| 39 | export function deleteAll() { |
||
| 40 | var files = fs.readdirSync(config.root) |
||
| 41 | Array.prototype.forEach.call(files, (file) => { |
||
| 42 | if (file.indexOf('abe-process') > -1 && file.indexOf('.lock') > -1) { |
||
| 43 | fs.unlinkSync(path.join(config.root, file)) |
||
| 44 | } |
||
| 45 | }) |
||
| 46 | } |