Improve getFileType

- Change parameter name
- Add more documentation
This commit is contained in:
Michael B. Gale 2023-10-04 19:50:02 +01:00
parent 8ac187720c
commit 9a5a628613
No known key found for this signature in database
GPG key ID: FF5E2765BD00628F
3 changed files with 17 additions and 7 deletions

10
lib/actions-util.js generated
View file

@ -382,12 +382,16 @@ function getWorkflowRunAttempt() {
exports.getWorkflowRunAttempt = getWorkflowRunAttempt;
/**
* Tries to obtain the output of the `file` command for the file at the specified path.
* The output will vary depending on the type of `file`, which operating system we are running on, etc.
*/
const getFileType = async (fp) => {
const getFileType = async (filePath) => {
let stderr = "";
let stdout = "";
try {
await new toolrunner.ToolRunner(await safeWhich.safeWhich("file"), ["-L", fp], {
// The `file` command will output information about the type of file pointed at by `filePath`.
// For binary files, this may include e.g. whether they are static of dynamic binaries.
// The `-L` switch instructs the command to follow symbolic links.
await new toolrunner.ToolRunner(await safeWhich.safeWhich("file"), ["-L", filePath], {
silent: true,
listeners: {
stdout: (data) => {
@ -401,7 +405,7 @@ const getFileType = async (fp) => {
return stdout;
}
catch (e) {
core.info(`Could not determine type of ${fp} from ${stdout}. ${stderr}`);
core.info(`Could not determine type of ${filePath} from ${stdout}. ${stderr}`);
throw e;
}
};