Skip to content

Commit 7ec4253

Browse files
committed
Remove tmp-promise
1 parent c131168 commit 7ec4253

File tree

3 files changed

+42
-63
lines changed

3 files changed

+42
-63
lines changed

package-lock.json

Lines changed: 35 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"rfc4648": "^1.3.0",
6767
"stream-buffers": "^3.0.2",
6868
"tar": "^6.1.11",
69-
"tmp-promise": "^3.0.2",
7069
"tslib": "^2.4.1",
7170
"ws": "^8.11.0"
7271
},

src/cp.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as fs from 'fs';
22
import { WritableStreamBuffer } from 'stream-buffers';
33
import * as tar from 'tar';
4-
import * as tmp from 'tmp-promise';
5-
4+
import { tmpdir } from 'os';
5+
import { randomUUID } from 'crypto';
66
import { KubeConfig } from './config';
77
import { Exec } from './exec';
88

@@ -18,7 +18,7 @@ export class Cp {
1818
* @param {string} containerName - The name of the container in the pod to exec the command inside.
1919
* @param {string} srcPath - The source path in the pod
2020
* @param {string} tgtPath - The target path in local
21-
* @param {string} cwd - The directory that is used as the parent in the pod when downloading
21+
* @param {string} [cwd] - The directory that is used as the parent in the pod when downloading
2222
*/
2323
public async cpFromPod(
2424
namespace: string,
@@ -28,8 +28,7 @@ export class Cp {
2828
tgtPath: string,
2929
cwd?: string,
3030
): Promise<void> {
31-
const tmpFile = tmp.fileSync();
32-
const tmpFileName = tmpFile.name;
31+
const tmpFileName = `${tmpdir()}/${randomUUID()}`;
3332
const command = ['tar', 'zcf', '-'];
3433
if (cwd) {
3534
command.push('-C', cwd);
@@ -65,7 +64,7 @@ export class Cp {
6564
* @param {string} containerName - The name of the container in the pod to exec the command inside.
6665
* @param {string} srcPath - The source path in local
6766
* @param {string} tgtPath - The target path in the pod
68-
* @param {string} cwd - The directory that is used as the parent in the host when uploading
67+
* @param {string} [cwd] - The directory that is used as the parent in the host when uploading
6968
*/
7069
public async cpToPod(
7170
namespace: string,
@@ -75,16 +74,9 @@ export class Cp {
7574
tgtPath: string,
7675
cwd?: string,
7776
): Promise<void> {
78-
const tmpFile = tmp.fileSync();
79-
const tmpFileName = tmpFile.name;
77+
const tmpFileName = `${tmpdir()}/${randomUUID()}`;
8078
const command = ['tar', 'xf', '-', '-C', tgtPath];
81-
await tar.c(
82-
{
83-
file: tmpFile.name,
84-
cwd,
85-
},
86-
[srcPath],
87-
);
79+
await tar.c({ file: tmpFileName, cwd }, [srcPath]);
8880
const readStream = fs.createReadStream(tmpFileName);
8981
const errStream = new WritableStreamBuffer();
9082
this.execInstance.exec(

0 commit comments

Comments
 (0)