Skip to content

Commit e67be93

Browse files
authored
Merge pull request #248 from lifeomic/add-overwrite-optional
feat: provides protection against overwritting on download
2 parents 5cfd9dd + 3ec43ef commit e67be93

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/api.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ module.exports.list = async function (options, path) {
103103
module.exports.download = async function (options, path, fileName) {
104104
mkdirp(dirname(fileName));
105105

106+
// Check if file exists and skip if overwrite is not enabled
107+
// eslint-disable-next-line security/detect-non-literal-fs-filename
108+
if (fs.existsSync(fileName) && !options.overwrite) {
109+
console.log(chalk.yellow(`Skipped (already exists): ${fileName}`));
110+
return;
111+
}
112+
106113
const response = await request(options).get(path);
107114

108115
const bar = progress(fileName);

lib/cmds/files_cmds/download.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ exports.builder = yargs => {
2424
alias: 'l',
2525
type: 'number',
2626
default: 1000
27+
}).option('overwrite', {
28+
describe: 'Overwrite existing files. By default, existing files are skipped.',
29+
alias: 'f',
30+
type: 'boolean',
31+
default: false
2732
});
2833
};
2934

0 commit comments

Comments
 (0)