@actions/io
Advanced tools
Comparing version 1.1.2 to 1.1.3
/// <reference types="node" /> | ||
import * as fs from 'fs'; | ||
export declare const chmod: typeof fs.promises.chmod, copyFile: typeof fs.promises.copyFile, lstat: typeof fs.promises.lstat, mkdir: typeof fs.promises.mkdir, readdir: typeof fs.promises.readdir, readlink: typeof fs.promises.readlink, rename: typeof fs.promises.rename, rmdir: typeof fs.promises.rmdir, stat: typeof fs.promises.stat, symlink: typeof fs.promises.symlink, unlink: typeof fs.promises.unlink; | ||
export declare const chmod: typeof fs.promises.chmod, copyFile: typeof fs.promises.copyFile, lstat: typeof fs.promises.lstat, mkdir: typeof fs.promises.mkdir, open: typeof fs.promises.open, readdir: typeof fs.promises.readdir, readlink: typeof fs.promises.readlink, rename: typeof fs.promises.rename, rm: typeof fs.promises.rm, rmdir: typeof fs.promises.rmdir, stat: typeof fs.promises.stat, symlink: typeof fs.promises.symlink, unlink: typeof fs.promises.unlink; | ||
export declare const IS_WINDOWS: boolean; | ||
export declare const UV_FS_O_EXLOCK = 268435456; | ||
export declare const READONLY: number; | ||
export declare function exists(fsPath: string): Promise<boolean>; | ||
@@ -6,0 +8,0 @@ export declare function isDirectory(fsPath: string, useStat?: boolean): Promise<boolean>; |
@@ -32,7 +32,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCmdPath = exports.tryGetExecutablePath = exports.isRooted = exports.isDirectory = exports.exists = exports.IS_WINDOWS = exports.unlink = exports.symlink = exports.stat = exports.rmdir = exports.rename = exports.readlink = exports.readdir = exports.mkdir = exports.lstat = exports.copyFile = exports.chmod = void 0; | ||
exports.getCmdPath = exports.tryGetExecutablePath = exports.isRooted = exports.isDirectory = exports.exists = exports.READONLY = exports.UV_FS_O_EXLOCK = exports.IS_WINDOWS = exports.unlink = exports.symlink = exports.stat = exports.rmdir = exports.rm = exports.rename = exports.readlink = exports.readdir = exports.open = exports.mkdir = exports.lstat = exports.copyFile = exports.chmod = void 0; | ||
const fs = __importStar(require("fs")); | ||
const path = __importStar(require("path")); | ||
_a = fs.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; | ||
_a = fs.promises | ||
// export const {open} = 'fs' | ||
, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.open = _a.open, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rm = _a.rm, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; | ||
// export const {open} = 'fs' | ||
exports.IS_WINDOWS = process.platform === 'win32'; | ||
// See https://github.com/nodejs/node/blob/d0153aee367422d0858105abec186da4dff0a0c5/deps/uv/include/uv/win.h#L691 | ||
exports.UV_FS_O_EXLOCK = 0x10000000; | ||
exports.READONLY = fs.constants.O_RDONLY; | ||
function exists(fsPath) { | ||
@@ -39,0 +45,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -33,8 +33,4 @@ "use strict"; | ||
const assert_1 = require("assert"); | ||
const childProcess = __importStar(require("child_process")); | ||
const path = __importStar(require("path")); | ||
const util_1 = require("util"); | ||
const ioUtil = __importStar(require("./io-util")); | ||
const exec = util_1.promisify(childProcess.exec); | ||
const execFile = util_1.promisify(childProcess.execFile); | ||
/** | ||
@@ -120,4 +116,2 @@ * Copies a file or folder. | ||
if (ioUtil.IS_WINDOWS) { | ||
// Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another | ||
// program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del. | ||
// Check for invalid characters | ||
@@ -128,51 +122,15 @@ // https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file | ||
} | ||
try { | ||
const cmdPath = ioUtil.getCmdPath(); | ||
if (yield ioUtil.isDirectory(inputPath, true)) { | ||
yield exec(`${cmdPath} /s /c "rd /s /q "%inputPath%""`, { | ||
env: { inputPath } | ||
}); | ||
} | ||
else { | ||
yield exec(`${cmdPath} /s /c "del /f /a "%inputPath%""`, { | ||
env: { inputPath } | ||
}); | ||
} | ||
} | ||
catch (err) { | ||
// if you try to delete a file that doesn't exist, desired result is achieved | ||
// other errors are valid | ||
if (err.code !== 'ENOENT') | ||
throw err; | ||
} | ||
// Shelling out fails to remove a symlink folder with missing source, this unlink catches that | ||
try { | ||
yield ioUtil.unlink(inputPath); | ||
} | ||
catch (err) { | ||
// if you try to delete a file that doesn't exist, desired result is achieved | ||
// other errors are valid | ||
if (err.code !== 'ENOENT') | ||
throw err; | ||
} | ||
} | ||
else { | ||
let isDir = false; | ||
try { | ||
isDir = yield ioUtil.isDirectory(inputPath); | ||
} | ||
catch (err) { | ||
// if you try to delete a file that doesn't exist, desired result is achieved | ||
// other errors are valid | ||
if (err.code !== 'ENOENT') | ||
throw err; | ||
return; | ||
} | ||
if (isDir) { | ||
yield execFile(`rm`, [`-rf`, `${inputPath}`]); | ||
} | ||
else { | ||
yield ioUtil.unlink(inputPath); | ||
} | ||
try { | ||
// note if path does not exist, error is silent | ||
yield ioUtil.rm(inputPath, { | ||
force: true, | ||
maxRetries: 3, | ||
recursive: true, | ||
retryDelay: 300 | ||
}); | ||
} | ||
catch (err) { | ||
throw new Error(`File was unable to be removed ${err}`); | ||
} | ||
}); | ||
@@ -179,0 +137,0 @@ } |
{ | ||
"name": "@actions/io", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Actions io lib", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
0
37117
568