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
Debugging Code
introduced
by
![]() |
|||
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
|
|||
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 | } |