@whyour/qinglong 2.18.2-1 → 2.18.2-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whyour/qinglong",
3
- "version": "2.18.2-1",
3
+ "version": "2.18.2-2",
4
4
  "description": "Timed task management platform supporting Python3, JavaScript, Shell, Typescript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,26 +1,39 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.writeFileWithLock = void 0;
4
7
  const proper_lockfile_1 = require("proper-lockfile");
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
5
10
  const promises_1 = require("fs/promises");
6
11
  const util_1 = require("../config/util");
7
- async function writeFileWithLock(path, content, options = {}) {
12
+ function getUniqueLockPath(filePath) {
13
+ const sanitizedPath = filePath
14
+ .replace(/[<>:"/\\|?*]/g, '_')
15
+ .replace(/^_/, '');
16
+ return path_1.default.join(os_1.default.tmpdir(), `${sanitizedPath}.ql_lock`);
17
+ }
18
+ async function writeFileWithLock(filePath, content, options = {}) {
8
19
  if (typeof options === 'string') {
9
20
  options = { encoding: options };
10
21
  }
11
- if (!(await (0, util_1.fileExist)(path))) {
12
- const fileHandle = await (0, promises_1.open)(path, 'w');
22
+ if (!(await (0, util_1.fileExist)(filePath))) {
23
+ const fileHandle = await (0, promises_1.open)(filePath, 'w');
13
24
  fileHandle.close();
14
25
  }
15
- const release = await (0, proper_lockfile_1.lock)(path, {
26
+ const lockfilePath = getUniqueLockPath(filePath);
27
+ const release = await (0, proper_lockfile_1.lock)(filePath, {
16
28
  retries: {
17
29
  retries: 10,
18
30
  factor: 2,
19
31
  minTimeout: 100,
20
32
  maxTimeout: 3000,
21
33
  },
34
+ lockfilePath,
22
35
  });
23
- await (0, promises_1.writeFile)(path, content, Object.assign({ encoding: 'utf8' }, options));
36
+ await (0, promises_1.writeFile)(filePath, content, Object.assign({ encoding: 'utf8' }, options));
24
37
  await release();
25
38
  }
26
39
  exports.writeFileWithLock = writeFileWithLock;