From 3ec43ef0e5109481fbd15cd3be8b9f36877737cc Mon Sep 17 00:00:00 2001 From: Ryan Ratcliff Date: Tue, 9 Dec 2025 07:51:58 -0500 Subject: [PATCH] feat: provides protection against overwritting on download --- lib/api.js | 7 +++++++ lib/cmds/files_cmds/download.js | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/lib/api.js b/lib/api.js index 75373c2..1beebc0 100644 --- a/lib/api.js +++ b/lib/api.js @@ -103,6 +103,13 @@ module.exports.list = async function (options, path) { module.exports.download = async function (options, path, fileName) { mkdirp(dirname(fileName)); + // Check if file exists and skip if overwrite is not enabled + // eslint-disable-next-line security/detect-non-literal-fs-filename + if (fs.existsSync(fileName) && !options.overwrite) { + console.log(chalk.yellow(`Skipped (already exists): ${fileName}`)); + return; + } + const response = await request(options).get(path); const bar = progress(fileName); diff --git a/lib/cmds/files_cmds/download.js b/lib/cmds/files_cmds/download.js index a0a6589..b49c713 100644 --- a/lib/cmds/files_cmds/download.js +++ b/lib/cmds/files_cmds/download.js @@ -24,6 +24,11 @@ exports.builder = yargs => { alias: 'l', type: 'number', default: 1000 + }).option('overwrite', { + describe: 'Overwrite existing files. By default, existing files are skipped.', + alias: 'f', + type: 'boolean', + default: false }); };